Skip to content

Instantly share code, notes, and snippets.

@PureLandFlying
Last active June 28, 2019 19:45
Show Gist options
  • Save PureLandFlying/f8cca4a9c2f0b3936abc72c64cef35b1 to your computer and use it in GitHub Desktop.
Save PureLandFlying/f8cca4a9c2f0b3936abc72c64cef35b1 to your computer and use it in GitHub Desktop.
function main() {
var adGroupIterator = AdsApp.adGroups().withCondition("CampaignStatus = ENABLED").withCondition("AdGroupType IN [SEARCH_STANDARD, SEARCH_DYNAMIC_ADS]").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});
adGroup.urls().setTrackingTemplate("{lpurl}?utm_medium=Search&utm_source=GoogleSearch&utm_campaign={_campaign}&utm_content={_adgroup}&utm_term={keyword}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment