A script to change the campaigns' tracking templates every 2 weeks?

66 views
Skip to first unread message

Sonny Rupaire

unread,
Nov 13, 2019, 11:15:16 AM11/13/19
to Google Ads Scripts Forum
I need to a script to automatically change my campaigns tracking templates every two weeks.
I explain myself: 

Selected campaigns would have 2 different tracking templates, let's call them A and B. 
Tracking template A would run during week 1 and 2, and the tracking template B would run during week 3 and 4, and so on...

Anyone can help me with that?
Thanks :D

Google Ads Scripts Forum Advisor

unread,
Nov 13, 2019, 4:11:37 PM11/13/19
to adwords-scripts+apn2wqdhslorhs5-...@googlegroups.com, adwords-scripts+apn2wqdhslorhs5-...@googlegroups.co, adwords...@googlegroups.com
Hi Sonny,

Here is a basic outline for a script you might run to accomplish this:

function main() {

  var trackingTemplateOne = "TEMPLATE_ONE";
  var trackingTemplateTwo = "TEMPLATE_TWO";
  
  var campaignSelector = AdsApp.campaigns().withCondition("YOUR_CONDITION").get();
  
  while(campaignSelector.hasNext()) {    
    var campaign = campaignSelector.next();
    
    if(/* condition for one set of weeks */) 
      campaign.urls().setTrackingTemplate(trackingTemplateOne);
    else /* condition for other set of weeks */
      campaign.urls().setTrackingTemplate(trackingTemplateTwo);
  }  
}

You will need to figure out the date math so that the conditions (if-else statement) assign the correct tracking template, depending on the pair of weeks. Here are a few useful resources for this:
  1. Working with dates and times
  2. formatDate method reference (mentioned in the above resource)
  3. Various date and time patterns that the formatDate method accepts
Regards,
Matt
Google Ads Scripts Team

ref:_00D1U1174p._5001UJaYpr:ref

Sonny Rupaire

unread,
Nov 14, 2019, 5:55:02 AM11/14/19
to Google Ads Scripts Forum
Thank you so much! 
Reply all
Reply to author
Forward
0 new messages