Script for Ad Countdown Linked to Sale Calendar

17 views
Skip to first unread message

Tammy Miles

unread,
Sep 27, 2019, 12:39:09 PM9/27/19
to Google Ads Scripts Forum
Hello!

I'm looking at ways to automate ads using the ad countdown feature in Google ads with the Google Calendar.    I came across a possible solution for a script that calls the calendar.   The only issue I've found that I don't know how to fix is that the script only allows one campaign to be attributed to the event in Google calendar.

Is there a way for a Google calendar event to allow a number of campaigns to be assigned to the one sale date in the script / calendar description?

Here's the script details:


My developer looked into it and it says to look for 1 instance of "campaign=" in the description.   

Thanks!

Google Ads Scripts Forum Advisor

unread,
Sep 27, 2019, 3:18:51 PM9/27/19
to adwords-scripts+apn2wqd-rpxdks_w...@googlegroups.com, adwords-scripts+apn2wqd-rpxdks_w...@googlegroups.co, adwords...@googlegroups.com
 Hi Tammy, 

The script is meant for a single campaign. However, I would recommend making changes to the listAllEvents and getCampaignName functions. Here are a few ideas to get you started, however, there may be other necessary changes. Please see comments and changes in bold:

//Change this function so that it returns an array of campaign names, rather than just one campaign name
//This would require editing the event description so each new line has campaing=campaign_name

function getCampaignName(eventDescription) {
  var retval = [];
  var parts = eventDescription.split('\n');
  for (var i = 0; i < parts.length; i++) {
    var subparts = parts[i].split('=');
    if (subparts.length == 2 && subparts[0].toLowerCase() == 'campaign') {
      retval.push(subparts[1]);
    }
    return retval;
  }
  return null;
}

and:

function listAllEvents() {
  var calendarEvents = Calendar.Events.list(CALENDAR_ID, {
    singleEvents: true,
    orderBy: 'startTime'
  });

  var retval = [];

  for (var i = 0; i < calendarEvents.items.length; i++) {
    var event = calendarEvents.items[i];
    if (event.start.date || event.end.date) {
      throw ('All day events are not supported. Set a start and end time.');
    }
    var startDate = parseDate(event.start.dateTime);
    var endDate = parseDate(event.end.dateTime);

    var listOfCampaigns = getCampaignName(event.description); //array of campaign names
    
    for(var j = 0; j < listOfCampaigns.length; j++) {
      retval.push({
        'Name': event.summary,
        'Campaign': listOfCampaigns[j],
        'StartDate': startDate,
        'EndDate': endDate
      });
    }
  }
  return retval;
}

Regards,
Matt
Google Ads Scripts Team

 

ref:_00D1U1174p._5001UKL7Pl:ref

Tammy Miles

unread,
Sep 27, 2019, 5:05:03 PM9/27/19
to Google Ads Scripts Forum
Thank you Matt!

With the code adjustments you noted, would I need to list the campaign names in the Event description separated by a comma?  eg:

campaing=test1,campaign=test2,campaign=teste

Or separated by [enter]

campaign=test1
campaign=test2
campaign=test3

Thanks for the speedy response!

Google Ads Scripts Forum Advisor

unread,
Sep 30, 2019, 3:00:35 PM9/30/19
to adwords-scripts+apn2wqd-rpxdks_w...@googlegroups.com, adwords-scripts+apn2wqd-rpxdks_w...@googlegroups.co, adwords...@googlegroups.com
HI Tammy,

The getCampaignName function splits the description up with new lines, so please break up the description as you suggested:

campaign=test1
campaign=test2
campaign=test3

Tammy Miles

unread,
Oct 3, 2019, 1:11:05 PM10/3/19
to Google Ads Scripts Forum
Thanks again.  I'll give this a try.

One last question - when the ads have reached an end date and the next start date isn't for a few weeks, do the countdown ads stop serving?   I ask because I have seen some ads past the date still get impressions and clicks when manually using the countdown function.

Google Ads Scripts Forum Advisor

unread,
Oct 3, 2019, 4:44:04 PM10/3/19
to adwords-scripts+apn2wqd-rpxdks_w...@googlegroups.com, adwords-scripts+apn2wqd-rpxdks_w...@googlegroups.co, adwords...@googlegroups.com
Hi Tammy,

The ads should no longer run after the end date, specified in the calendar event, passes. Can you please send me the ad group and ad IDs of ads that are not obeying the end date?

Thanks,
Matt Yashinsky

Tammy Miles

unread,
Oct 4, 2019, 1:48:27 PM10/4/19
to Google Ads Scripts Forum
I'll take a look to see if I can find an example.  One of our team members suggested in her research that if the countdown timer passes, they may drop the headline and serve the ad without the headline (if there are 3 headlines).

The team came back with a great question - instead of Campaign=  Can we do this for multiple Ad Groups Instead?    Some accounts have multiple products under a campaign instead of them being broken out by campaign.

Thanks!
Tamy

Google Ads Scripts Forum Advisor

unread,
Oct 4, 2019, 3:21:58 PM10/4/19
to adwords-scripts+apn2wqd-rpxdks_w...@googlegroups.com, adwords-scripts+apn2wqd-rpxdks_w...@googlegroups.co, adwords...@googlegroups.com
Hi Tammy,

This is possible, but you'll have to make the necessary adjustments to the script. For instance, the function, setCustomizerItem, uses the method, setTargetCampaign, but you'll have to switch it out for setTargetAdGroup, which takes both ad group name and campaign name as parameters, not just campaign name. Additionally, you will have to alter the getCampaignName function so that it retrieves both campaign names and ad group names. In the previous customization of that function that I posted, the function returned an array of campaign names. If you are now using ad groups too, then that function should probably return a two dimensional array of the form:
 
[ [campaignName1, adGroupName1] , [campaignName2, adGroupName2], ... , [campaignNameN, adGroupNameN] ]
 
This is assuming the ad groups are dispersed throughout more than just one campaign.

There may be other necessary changes as well, where the ad group would need to be specified 

Regards,
Matt
Google Ads Scripts Team

 


ref:_00D1U1174p._5001UKL7Pl:ref

Tammy Miles

unread,
Oct 4, 2019, 3:42:43 PM10/4/19
to Google Ads Scripts Forum
Okay, let's assume the ad group name is the same in all campaigns.   With the array you noted below, this is what I put into the calendar description with the campaign and ad group name for each item to check?

Let's say the campaigns are Boston MBC and Las Vegas Search, California Health and the ad group is MBC online.   The array in the calendar description would look like this?  The prior set up for the campaign level had this separated as a line item for the calendar event.

[Boston MBC, MBC online], [Las Vegas Search, MBC online], [Calfifornia Health, MBC online]

Are spaces okay or no?

Google Ads Scripts Forum Advisor

unread,
Oct 4, 2019, 5:16:56 PM10/4/19
to adwords-scripts+apn2wqd-rpxdks_w...@googlegroups.com, adwords-scripts+apn2wqd-rpxdks_w...@googlegroups.co, adwords...@googlegroups.com
Hi Tammy,

If the ad group name is constant (i.e. always 'MBC online'), then there wouldn't be a need to parse the 'getCampaignName' function into two-element sub-arrays. You can define the ad group globally, at the top of your script, e.g.:

  var AD_GROUP_NAME = 'MBC online' ; 

And then leave the getCampaignName function as we edited it previously. 

Then you can have:

setTargetAdGroup( campaignName, AD_GROUP_NAME ); // Where campaignName is retrieved from your array of campaign names
Reply all
Reply to author
Forward
0 new messages