function main() {\n\tvar SuffixTemplate=\"utm_source=google&utm_medium=cpc&utm_campaign={CampaignName}&utm_content={AdGroupName}&utm_ad={creative}&utm_term={keyword}&matchtype={matchtype}&device={device}&GeoLoc={loc_physical_ms}&placement={placement}&network={network}&campaign_id={campaignid}&adset_id={adgroupid}&ad_id={creative}\";\n\n\tvar _CAMPAIGN_CONTAINS=\"\"; \/\/Filter by Campaign name \n\tvar _ADGROUP_CONTAINS=\"\"; \/\/Filter by Adgroup name \n\tvar STATUS=\"ENABLED\"; \/\/ENABLED, PAUSED\n\n\tif (SuffixTemplate.search(\/{AdGroupName}|{CampaignName}\/g)==-1) {\n\t\tLogger.log(\"Enter at least one of the {CampaignName} or {AdGroupName} parameter in the tracking template\");\n\t\treturn\n\t} \n\tif (SuffixTemplate.search(\"{CampaignName}\")>0&&SuffixTemplate.search(\"{AdGroupName}\")==-1) {\n\t\tvar campaignIterator=_CAMPAIGN_CONTAINS==\"\"?AdsApp.campaigns().withCondition(\"Status = \"+STATUS).get():AdsApp.campaigns().withCondition(\"Name contains '\"+_CAMPAIGN_CONTAINS+\"'\").withCondition(\"Status = \"+STATUS).get();\n\t\tif (!campaignIterator.hasNext()) {\n\t\t\tLogger.log(\"No Campaigns matched with this condition\");\n\t\t\treturn\n\t\t}\n\t\twhile (campaignIterator.hasNext()) { \n\t\t\tvar campaign=campaignIterator.next(); \n\t\t\tvar campaigntemplate=SuffixTemplate.replace(\/{CampaignName}\/g,campaign.getName().replace(\/\\s\/g,'%20'))\n\t\t\tcampaign.urls().setFinalUrlSuffix(campaigntemplate);\n\t\t\tLogger.log(campaign.getName()+\" => \"+campaigntemplate) \n\t\t}\n\t}\n\tif (SuffixTemplate.search(\"{AdGroupName}\")>0) {\n\t\tvar adgroupIterator = {hasNext:function(){return false}} \n\t\tif (_ADGROUP_CONTAINS==\"\"&&_CAMPAIGN_CONTAINS==\"\") {\n\t\t\tadgroupIterator=AdsApp.adGroups().withCondition(\"Status = \"+STATUS).get();\n\t\t} else if (_ADGROUP_CONTAINS==\"\"&&_CAMPAIGN_CONTAINS!==\"\") {\n\t\t\tadgroupIterator=AdsApp.adGroups().withCondition(\"CampaignName contains '\"+_CAMPAIGN_CONTAINS+\"'\").withCondition(\"Status = \"+STATUS).get();\n\t\t} else if (_ADGROUP_CONTAINS!==\"\"&&_CAMPAIGN_CONTAINS!==\"\") {\n\t\t\tadgroupIterator=AdsApp.adGroups().withCondition(\"CampaignName contains '\"+_CAMPAIGN_CONTAINS+\"'\").withCondition(\"Name contains '\"+_ADGROUP_CONTAINS+\"'\").withCondition(\"Status = \"+STATUS).get();\n\t\t} else if (_ADGROUP_CONTAINS!==\"\"&&_CAMPAIGN_CONTAINS==\"\") {\n\t\t\tadgroupIterator=AdsApp.adGroups().withCondition(\"Name contains '\"+_ADGROUP_CONTAINS+\"'\").withCondition(\"Status = \"+STATUS).get();\n\t\t}\n\n\t\tif (!adgroupIterator.hasNext()) {\n\t\t\tLogger.log(\"No Campaigns\/Adgroups matched with this condition\");return\n\t\t}\n\t\twhile (adgroupIterator.hasNext()) { \n\t\t var adgroup=adgroupIterator.next();\n\t\t\tvar adgrouptemplate=SuffixTemplate.replace(\/{AdGroupName}\/g,adgroup.getName().replace(\/\\s\/g,'%20'))\n\t\t\tif (SuffixTemplate.search(\"{CampaignName}\")>0) {\n\t\t\t\tadgrouptemplate=adgrouptemplate.replace(\/{CampaignName}\/g,adgroup.getCampaign().getName().replace(\/\\s\/g,'%20'))\n\t\t\t}\n\t\t\tadgroup.urls().setFinalUrlSuffix(adgrouptemplate);\n\t\t\tLogger.log(adgroup.getCampaign().getName()+\" => \"+adgroup.getName()+\" => \"+adgrouptemplate)\n \t\t}\n\t}\n}\n<\/code><\/pre>\n\n\n\nWhat it does<\/h2>\n\n\n\n This script adds two dynamic UTM’s to your tracking template: CampaignName and AdGroupName<\/p>\n\n\n\n
TrackingTemplate<\/h3>\n\n\n\n You can edit this variable to add\/remove data that will appear in the destination URL the users are sent to.<\/p>\n\n\n\n
CAMPAIGN_CONTAINS<\/h3>\n\n\n\n This variable can be used to filter in only specific campaigns by their name. For example, if all your brand campaigns have a standard naming convention, e.g. Brand_Jaspers_UK_Exact, you can simply adjust the variable to _CAMPAIGN_CONTAINS = “Brand”<\/em>.<\/p>\n\n\n\nTo apply the script to all campaigns in the account, simply leave this variable empty.<\/p>\n\n\n\n
ADGROUP_CONTAINS<\/h3>\n\n\n\n Similarly, this variable can be used to filter in only specific ad groups by their name. For example, if all your exact match ad groups have a standard naming convention, e.g. Brand_Jaspers_UK_Exact, you can simply adjust the variable to _ADGROUP_CONTAINS<\/em> = “Exact”<\/em>.<\/p>\n\n\n\nTo apply the script to all ad groups in the account, simply leave this variable empty.<\/p>\n\n\n\n
Important<\/strong> Make sure you remove all existing tracking templates from your account (on all levels). This script will only run on campaigns that are active.<\/p><\/blockquote>\n\n\n\nInstalling the script<\/h2>\n\n\n\n After making the relevant adjustments to the script, you can go ahead and install it on your account.<\/p>\n\n\n
\n
<\/figure><\/div>\n\n\nNavigate to Tools -> Bulk Actions -> Scripts. Create a new script by clicking the blue plus icon.<\/p>\n\n\n\n
Give the script a memorable name, e.g. Auto Campaign and Ad Group UTM’s<\/em>.<\/p>\n\n\n\n
<\/figure><\/div>\n\n\nPaste in the script’s code and hit Save.<\/p>\n\n\n\n
Google Ads will then ask for your permission to add the script (there’s no fishy code here, pinky swear!). There’s a minor chance it will show an error after confirming the installation, that’s just a bug.<\/p>\n\n\n\n
You can then click Run and then Preview.<\/p>\n\n\n
\n
<\/figure><\/div>\n\n\nThe code will now run, and its outputs will show in the bottom window. This effectively adds the tracking template to the campaigns and ad groups set in the script (if no filters were set, then to all the account).<\/p>\n\n\n\n
Back on the main Scripts page, you can set the frequency at which the script will run (as you want new campaigns\/ad groups to use it as well).<\/p>\n\n\n
\n
<\/figure><\/div>\n\n\nThe frequency can be set as you see fit. If this account has many changes happening daily, you can set it to update on an hourly basis. This will update both new and existing campaigns (if their name changes).<\/p>\n\n\n\n
Final thoughts<\/h2>\n\n\n\n This script and post were both contributed by the awesome team at Terrific Digital<\/a>, which are sailing the high seas of digital marketing with a holistic approach and a bottle of rum.<\/p>\n","protected":false},"excerpt":{"rendered":"When working with Google Ads, most advertisers usually default to using the Auto-tagging feature which automatically appends the gclid parameter to the destination URL (e.g. domain.com\/landing-page?gclid=12345abcde). This feature enables the tracking mechanisms used by Google Ads and Google Analytics that can match a specific visitor and their consecutive actions with the ad clicked. In layman’s […]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-4971","post","type-post","status-publish","format-standard","hentry","category-google-ads"],"_links":{"self":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4971","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/comments?post=4971"}],"version-history":[{"count":4,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4971\/revisions"}],"predecessor-version":[{"id":5282,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4971\/revisions\/5282"}],"wp:attachment":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/media?parent=4971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/categories?post=4971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/tags?post=4971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}