Platforms that are funded by digital advertising could be required to be more transparent about the services they provide and how they are using consumers' data.
They will be expected to give consumers a choice over whether to receive personalised advertising, and prevented from placing restrictions on their customers that make it hard for them to use rival platforms.
The code will be enforced by a new dedicated unit within the CMA.
The Digital Markets Unit could be given powers to suspend, block and reverse decisions made by technology firms and to impose financial penalties for non-compliance.
Google and Facebook have previously said they are committed to working with the British government and regulator on digital advertising.
The new code could also affect the media industry, which has lost much of its advertising revenues to Facebook and Google.
The new code will attempt to govern commercial arrangements between publishers and platforms to help keep publishers in business.
It will try to stop online platforms from imposing unfair terms on news publishers that limit their ability to monetise their content.