Keeping spaces in campaign names and ad groups

234 views
Skip to first unread message

Dan Konig

unread,
May 11, 2022, 6:40:42 PM5/11/22
to Google Ads Scripts Forum
Hi,
I am using the following script to use campaign names and ad group names in my tracking template. The tutorial I found was replacing spaces with underscores but I am wondering if I can keep the spaces. The preview of this script seems to imply that Google sends over the campaign names and ad group names with the spaces encoded.

Script
function main(){
    let adGroups = AdsApp.adGroups().withCondition("CampaignStatus = ENABLED").get();
    while (adGroups.hasNext()) {
        let adGroup = adGroups.next();
        let group=adGroup.getName().replace(/\s/g,'%20');
        let campaign=adGroup.getCampaign().getName().replace(/\s/g,'%20');
        adGroup.urls().setCustomParameters({adgroup: group, campaign: campaign});
    }
}

Preview
Ad group custom parameters changed from {_adgroup}=adgroup%20name, {_campaign}=US%20|%20Search%20|%20Desktop%20|%20Ecampaign to {_adgroup}=adgroup%20name, {_campaign}=US%20|%20Search%20|%20Desktop%20|%20campaign

Pascal van Dooren

unread,
May 13, 2022, 11:51:00 AM5/13/22
to Google Ads Scripts Forum
Hi Dan,

THe script above should work fine. Since custom parameters are appended to the final URL, they'll need to comply with URL formatting. URLs don't allow the space character but encode it as '%20' instead. The script above seems to do just this, so you should be fine.

Google Ads Scripts Forum Advisor

unread,
May 15, 2022, 10:52:28 PM5/15/22
to adwords...@googlegroups.com

Hello Dan,

I’m James from the Google Ads scripts support team. Thank you for reaching out to us.

Can you please first provide us with the following information below so that we take a closer look at your concern?

  • Google Ads account ID / CID
  • Script name

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2as4Dd:ref
Reply all
Reply to author
Forward
0 new messages