Tuesday, March 21, 2023

Experiment changes in Google Ads scripts

Starting in April, we will be rolling out a change to the way you create experiments in Google Ads scripts to bring the process more in line with the Google Ads API. Previously, you would create a draft, modify the draft, and then create an experiment from the modified draft. Now, you will create the experiment directly, which will automatically create the underlying drafts and allow you to modify them before scheduling the experiment.

You can read more about this feature in our Drafts and Experiments guide.

To summarize the new changes in a simple example, if you had code such as:
const draft = campaign.newDraftBuilder()
  .withName(newDraftName)
  .build()
  .getResult();
// Modify the draft campaign before beginning the experiment.
const draftCampaign = draft.getDraftCampaign();
const experiment = draft.newExperimentBuilder()
  .withName(newExperimentName)
  .withTrafficSplitPercent(50)
  .startBuilding();
The new equivalent code would be:
const experiment = AdsApp.newExperimentBuilder()
  .withCampaign(campaign)
  .withTrafficSplitPercent(50)
  // Some new fields are required.
  .withStartDate("20230501")
  .withEndDate("20230601")
  .withType("SEARCH_CUSTOM")
  // The suffix will automatically be added to the end of the name for
  // each experiment campaign.
  .withSuffix("experiment")
  // Goals have no effect on the serving of the experiment, but instead
  // just help you keep track of your intentions.
  .withGoals([{metric: 'CLICKS', direction: 'INCREASE'}])
  .build();
// The experiment campaign is the new equivalent of the draft campaign
// in the example above.
const experimentCampaign = experiment.getExperimentCampaign();
This change will allow us to bring further improvements to this feature as they are added in the Google Ads API.

If you have any questions or feedback, please leave a post on our forum or send a message to our support alias googleadsscripts-support@google.com.