Script to change campaign names at MCC level

303 views
Skip to first unread message

Sonny

unread,
Nov 29, 2019, 9:17:53 AM11/29/19
to Google Ads Scripts Forum
Hi GAScripters!

I'm a complete noob in scripting so I need your help.
I need a script that scans the campaigns tracking template within a MCC in order to append the defined source id at the end of the campaign name.

Ex: 
IF Campaign name is: 
example campaign 1

and Campaign tracking template: 
https://www.exampletrackingtmp.com/?source_id=456158445&url={lpurl}&gclid={gclid}

THEN campaign name should be changed to:
example campaign 1 - SRC456158445

This is a script behaviour that should be done at MCC level because multiple accounts have these kind of tracking templates with a defined source id.

When a campaign doesn't have a defined, it says source_id={campaignid} instead
When this is a case, the campaign name should rename unchanged. 


The script should also log the campaign names associated with tracking templates that contains a source id which is already in used in a different tracking template, in order to avoid duplicates (I don't want to have campaigns running under the same source id).

Ex: 
IF:
source_id=456158445 is found in more than 1 campaign tracking template

THEN log: 
Duplicate source_id=456158445 found in campaigns:
example campaign 1 - SRC456158445
example campaign 2 - SRC456158445

Thanks for your help.

Sonny



Google Ads Scripts Forum Advisor

unread,
Dec 1, 2019, 11:07:00 PM12/1/19
to adwords...@googlegroups.com
Hi Sonny,

Thanks for posting your concern.

To get you started on creating the script based on the provided requirement, you may try to implement this suggestion. Please follow the instruction below.
1. Implement the account's selector and iterator to process all your accounts.
2. Use the select() method so that the script will determine which account will be processed first.
3. Implement the campaign's selector and iterator to get all the campaigns on each account.
4. Use the getTrackingTemplate() method to retrieve the tracking templates at the campaign level.
5. Create a process that will get the numeric value after the "source_id=" and before the "&url=".
6. Create a condition to check whether the source ID has value.
7. If the condition is satisfied, change the campaign name by using the setName(name) method.

To determine if there are duplicate source id, I suggest to import campaigns to the Google spreadsheet so that you can easily check if there are indeed duplicate source ID. You can use these sample codes to import data in the Google spreadsheet.

Let me know if you have further questions/clarifications.

Regards,
Ejay
Google Ads Scripts Team

ref:_00D1U1174p._5001UODV58:ref

Sonny

unread,
Dec 2, 2019, 6:44:35 AM12/2/19
to Google Ads Scripts Forum
Hi, 

Thanks for your reply. I'm gonna dive into this.

Cheers, Sonny
Reply all
Reply to author
Forward
0 new messages