AdWords
4.9K members online now
4.9K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

MCC Script account iterator returns an account it shouldn't

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi all,

 

This is my first time posting so I apologize if I'm not doing it right (or in the right place). I have an MCC script that queries accounts with a filter applied. This filter only lets in accounts with zero impressions on the day the script is run. The purpose is to give warning of a potential credit card payment failure (there is no way to get billing data through the API, so this is a proxy measure) as a backup since I sometimes don't get email alerts when a payment fails. The script is scheduled to run at 4pm daily. It mostly works fine, but I get an account returned that should not be in there because it has more than zero impressions. The script is as follows:

 

var zeroAccounts = [];
var dateRange = 'TODAY';
var To = ["email@address.com"];

function main () {

var accountIterator = MccApp.accounts()
.withCondition('Impressions = 0')
.withCondition("LabelNames DOES_NOT_CONTAIN 'Paused'")
.forDateRange(dateRange)
.get();

while (accountIterator.hasNext()) {
var account = accountIterator.next();
var stats = account.getStatsFor(dateRange);
var accountName = account.getName()
zeroAccounts.push(accountName);
}

if (zeroAccounts.length > 0) {
for (var i in To) {
MailApp.sendEmail(To[i],"Comptes Sans Impressions", "Les comptes suivant ont eu zero impressions aujourd'hui, indicant possiblement un problème de paiement: "+ zeroAccounts.toString());
}
}
}

 

The .withCondition methods under the accountIterator are what filter out anything that don't meet those conditions. I've tested it, it works fine, but one account keeps popping in which shouldn't be there. When I look at the account, it has impressions. I thought at first that it has something to do with my requesting the dateRange 'TODAY', like the account in question is on a different time, but I just don't know. Does anyone have any experience with this kind of issue? Thanks,

1 Expert replyverified_user
Marked as Best Answer.
Solution
Accepted by topic author Ian T
September 2015

Re: MCC Script account iterator returns an account it shouldn't

Top Contributor
# 2
Top Contributor

Hi @Ian T I think you're probably on the right lines that it's the time zone that's the problem.  Time Zones can be something of a nightmare in AdWords, especially when working with scripts.  As you probably know, each Account respects the Time Zone set in that Account so if you're iterating over Accounts in multiple Time Zones, "TODAY" is going to mean different things to different Accounts.  Unless I'm mistaken, the script as it is will use the Time Zone set in your MCC Account.

 

One option is to use the formatDate utility to specify a date range that's based upon the Time Zone of the Account:

 

var accountDate = new Date(Utilities.formatDate(date, AdWordsApp.currentAccount().getTimeZone(), "MMM dd,yyyy HH:mm:ss"));

 

where date in the above is a date object representing the date/time you're after.  I'd write a simple sandbox script to test this feature until you're certain you're seeing the same data for impressions you see when you look at the individual Accounts.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: MCC Script account iterator returns an account it shouldn't

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Thanks, Jon!

I actually did something simpler. I set the date range to 'YESTERDAY' and had the script run in the morning instead of the evening. One night doesn't make a difference for my type of client right now (in fact, many of them don't run in the evenings). However, I am not going to go with your solution as it is closer to the behavior I want. Thanks!