Blog

How to Dynamically Insert Campaign Names in Google Ads URL Parameters

02.04.19 // John O'Toole
Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Email this to someone

Obility builds custom data integrations to optimize ad campaigns based on sales data from CRM platforms.

In most cases, we prefer to use ad platform IDs for more reliable syncing, but there are still cases where it is desirable to capture the campaign name and/or ad group name in a marketing automation or CRM platform.

Google Ads provides ValueTrack parameters that allow you to dynamically insert parameters into your final URL. However they do not provide a ValueTrack parameter for campaign name or ad group name.

Google provides two options for inserting campaign name and ad group name in your URL parameters:

  1. Create tracking templates at the ad group level, and manually insert the campaign and ad group names.
  2. Create custom parameters at the ad group level, and manually insert the campaign and ad group names. Then reference the custom parameters in the tracking template at the account level.

Either way this is a tedious process and susceptible to human error such as typos, or forgetting to add the custom parameter fields.

Our solution utilizes a Google Ads script to automatically create your custom parameters and insert the campaign name and ad group name, which can then be dynamically inserted into the final URL by referencing the custom parameters in the account level tracking template.

Step 1.

Enter these parameters in the tracking template at the account level settings of your Google Ads account:

utm_campaign={_campaign}

utm_adgroup={_adgroup}

Example: {lpurl}?utm_campaign={_campaign}&utm_adgroup={_adgroup}

Step 2.

Add this script to your Google Ads account using these instructions and set the frequency to run hourly:

function main() {
var adGroupIterator = AdsApp.adGroups().withCondition("CampaignStatus = ENABLED").get();
while (adGroupIterator.hasNext()) {
var adGroup = adGroupIterator.next();
var gn=adGroup.getName().replace(/\s/g,'_');
var cn=adGroup.getCampaign().getName().replace(/\s/g,'_');
adGroup.urls().setCustomParameters({adgroup: gn, campaign: cn});
}
}

Notes:

  • The script will only run on enabled campaigns.
  • The script will replace any other custom parameters set at the ad group level.
  • The script replaces spaces in the campaign and ad group names with underscores.
  • If campaign name or ad group name parameters have been entered in a lower level tracking template they will need to be removed so they don’t override the new account level parameters.

About John O'Toole

John O'Toole is a senior SEM manager specializing in paid search and display for B2B companies. He is passionate about automation, data integration and dashboard design. View all John O'Toole’s posts >

Want more opportunities?

Let’s talk about increasing your revenue.

  • This field is for validation purposes and should be left unchanged.