Enable ad by label on certain days

15 views
Skip to first unread message

Guillaume Aubert

unread,
Jun 23, 2019, 8:50:53 AM6/23/19
to Google Ads Scripts Forum
Hi,

I started creating an easy script to enable an ad with a certain label on a certain day.
Here is my script. When I'm running it, the campaign isn't enabled. 

function main() {
    var adSelector = AdsApp
        .ads()
        .withCondition("LabelNames CONTAINS_ANY ['Monday 1']")
    var today = new Date().getDay();
    var adIterator = adSelector.get();
    while (adIterator.hasNext()) {
        var ad = adIterator.next();
        // Sunday
        if (today == 0) {
            ad.enable();
        }
    }
}


Google Ads Scripts Forum Advisor Prod

unread,
Jun 24, 2019, 3:27:20 AM6/24/19
to adwords...@googlegroups.com
Hi Guillaume,

Thanks for posting your concern.

Upon checking the provided script, I can see that you did fine on implementing it. You just need to implement the Default timezone in date object methods in your code. I am suggesting this because when you just use the getDay() method (where you've used it in a condition), default timezone that will be used is America/Los_Angeles (Pacific time) so the returned value for the said method will be varied with the expected date.

Please refer to the modified script below as the suggestion was applied to it.
function main() {
    var adSelector = AdsApp
        .ads()
        .withCondition("LabelNames CONTAINS_ANY ['Monday 1']")
    var now = new Date();
    var timeZone = AdsApp.currentAccount().getTimeZone();
    var formatDate = Utilities.formatDate(now, timeZone, 'MMMM dd, yyyy');
    var today = new Date(formatDate).getDay();


    var adIterator = adSelector.get();
    while (adIterator.hasNext()) {
        var ad = adIterator.next();
        // Sunday
        if (today == 0) {
            ad.enable();
        }
    }
}


Please let me know if you have further questions/clarifications.

Regards,
Ejay
Google Ads Scripts Team

ref:_00D1U1174p._5001UCZ2fH:ref

Guillaume Aubert

unread,
Jun 24, 2019, 4:22:59 AM6/24/19
to Google Ads Scripts Forum
Thanks for your quick answer.
Tried your script, and I'm still facing the same issue.

Ad, that has the status paused, remains paused when I'm running the script.
It has the label applied to it. 

Google Ads Scripts Forum Advisor Prod

unread,
Jun 25, 2019, 1:46:58 AM6/25/19
to adwords...@googlegroups.com
Hi Guillaume,

Thank you for your reply.

To further investigate the issue, would you mind providing the customer ID and the name of the script where you encountered the issue via Reply privately to author? Also, could you provide the sample ad ID(s) that was not paused when the script executed?
Reply all
Reply to author
Forward
0 new messages