Blog

How to Dynamically Insert Campaign Names in Google Ads URL Parameters

02.04.19 // John O'Toole

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:

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

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.
  • The script will not work with video, discovery, or performance max campaign types due to api limitations, but you can still set them manually.

About John O'Toole

John O'Toole is a senior PPC manager focused on paid search and display campaigns for B2B companies. He also develops automated reporting and dashboard solutions that combine search, social, SEO, CRM and MAP data for all of our clients. View all John O'Toole’s posts >