Account Anomaly Detector

183 views
Skip to first unread message

J van de Ven

unread,
Dec 22, 2020, 4:03:16 AM12/22/20
to Google Ads Scripts Forum
I've been setting up the account anomaly detector for one of my accounts and run into an issue.

The script runs once a day (late night), aiming to have it reporting on the full data of that day so far, but it only considers data of one hour. Is there any way to change this?


Thanks in advance for your help!

Cheers,
Jorin

Google Ads Scripts Forum Advisor

unread,
Dec 22, 2020, 5:13:33 AM12/22/20
to adwords...@googlegroups.com

Hi Jorin,

Thanks for raising this to us.

So we could further check on our end, could you share with us your customer ID as well as the access to the template spreadsheet via Reply privately to author or Reply to author option? If you encounter an error when using the said options, you may send those requested details on this email (googleadsscr...@google.com) instead.

Regards,

Google Logo
Mark Kevin Albios
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q29U0iE:ref

J van de Ven

unread,
Dec 22, 2020, 3:25:38 PM12/22/20
to Google Ads Scripts Forum
Thanks, Mark.
I cannot use the said options indeed - I will email you directly.

Jorin

Google Ads Scripts Forum Advisor

unread,
Dec 27, 2020, 9:03:43 PM12/27/20
to adwords...@googlegroups.com

Hi Jorin,

Thanks for getting back to us.

I'm afraid that we still don't have any access on the link you've shared. However, no worries on that since you've already provided a screenshot of the spreadsheet file.

Please note that the Account Anomaly Detector script gets all available statistics but may be up to 3 hours delayed due to data's freshness. With regard to the alert you've received, the script was able to detect an anomaly when it run at 8:00 PM. However, if it will detect the same anomaly on the next runtime, it won't be reflected on the sheet file. As per the script's documentation (How it works), no subsequent alerts of the same type will be triggered for the day. If you'd like to reset the alert, delete the Alerting cell value.

Hope this helps.

Regards,

Jorin van de Ven

unread,
Dec 29, 2020, 6:07:16 AM12/29/20
to Google Ads Scripts Forum on behalf of adsscriptsforumadvisor
Many thanks, Mark!

The documentation says: Suppose the script runs at 7pm on a Tuesday. Since Google Ads statistics may be up to 3 hours delayed, the script will only consider stats up to 4pm.

I interpreted ''up to 4pm'' as if the script would look at the full day data until 4pm (12am --> 4pm), but that is not the case, it solely looks at one hour of data. I've scheduled the script to run once a day at 11pm, aiming to have the full day data until 8pm compared to the avg of the last 26 weeks.
Is there any way to make this happen in the script? Or is there a script available that would compare yesterday's data with avg last 26 weeks?


Met vriendelijke groet / Kind regards,

Jorin van de Ven



Mercatorplein 82
1056 CL Amsterdam
the Netherlands
M. +31 6 55 47 77 12



--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/8IUSPe34spk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/HQ-M5000000000000000000000000000000000000000000000QM11Q000cWWu4PYSTf-cklwIWaW3hA%40sfdc.net.

Google Ads Scripts Forum Advisor

unread,
Jan 3, 2021, 11:37:23 PM1/3/21
to adwords...@googlegroups.com
Hi Jorin,

I work along with Mark. Allow me to assist you in this.

With regard to your use case inquiry, you need to update the solution script base on your requirement by doing the following.
  • setting the dateRangeToCheck to get the yesterday's date
  • setting the dateRangeToEnd to get the date before yesterday's date
With this, kindly update the following line 88-99 to:
var dateRangeToCheck = getDateStringInPast(1, upTo);
var dateRangeToEnd = getDateStringInPast(2, upTo);
then let me know how it goes.

Regards,
Google Logo
Teejay Wennie Pimentel
Google Ads Scripts Team
 

 

ref:_00D1U1174p._5004Q29U0iE:ref

Jorin van de Ven

unread,
Jan 13, 2021, 1:20:36 PM1/13/21
to Google Ads Scripts Forum on behalf of adsscriptsforumadvisor
Hi Teejay,
Many thanks for your response.
Unfortunately, the script continues to output only 1 hour of data, instead of the full-day data of yesterday.

Screenshot 2021-01-13 at 19.10.24.png

Should we probably also change ''var todayStats = getReportStats(todayQuery, upToHour, 1)''?
Hereby a copy of line 88-101.

  var dateRangeToCheck = getDateStringInPast(1, upTo);
  var dateRangeToEnd = getDateStringInPast(2, upTo);
  var dateRangeToStart = getDateStringInPast(1 + weeks * 7, upTo);
  var fields = 'HourOfDay,DayOfWeek,Clicks,Impressions,Conversions,Cost';
  var todayQuery = 'SELECT ' + fields +
      ' FROM ACCOUNT_PERFORMANCE_REPORT DURING ' + dateRangeToCheck + ',' +
      dateRangeToCheck;
  var pastQuery = 'SELECT ' + fields +
      ' FROM ACCOUNT_PERFORMANCE_REPORT WHERE DayOfWeek=' +
      DAYS[getDateStringInTimeZone('u', now)].toUpperCase() +
      ' DURING ' + dateRangeToStart + ',' + dateRangeToEnd;
  var todayStats = getReportStats(todayQuery, upToHour, 1);
  var pastStats = getReportStats(pastQuery, upToHour, weeks);


Met vriendelijke groet / Kind regards,

Jorin van de Ven



Mercatorplein 82
1056 CL Amsterdam
the Netherlands
M. +31 6 55 47 77 12


--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/8IUSPe34spk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.

Google Ads Scripts Forum Advisor

unread,
Jan 14, 2021, 2:48:47 AM1/14/21
to adwords...@googlegroups.com
Hi there,

Thank you for getting back to us.

Could you kindly update the var todayStats = getReportStats(todayQuery, upToHour, 1); to var todayStats = getReportStats(todayQuery, 24, 1), then let me know how it goes?

Jorin van de Ven

unread,
Jan 22, 2021, 5:07:27 AM1/22/21
to Google Ads Scripts Forum on behalf of adsscriptsforumadvisor
Many thanks, Teejay.
Next to the change you suggested, I also changed the line ''var pastStats = getReportStats(pastQuery, upToHour, weeks);'' into ''var pastStats = getReportStats(pastQuery, 24, weeks);''

It seems to work fine now, apart from the script not clearing out existing alerts anymore; at least, I have the impression it does not.
Could it be that we also have to change something in this piece of code?

  // Basic reporting statistics are usually available with no more than a 3-hour
  // delay.
  var upTo = new Date(now.getTime() - 3 * 3600 * 1000);
  var upToHour = parseInt(getDateStringInTimeZone('h', upTo));
  if (upToHour == 1) {
    // first run for the day, kill existing alerts
    spreadsheet.getRangeByName('clicks_alert').clearContent();
    spreadsheet.getRangeByName('impressions_alert').clearContent();
    spreadsheet.getRangeByName('conversions_alert').clearContent();
    spreadsheet.getRangeByName('cost_alert').clearContent();
  }

Lastly, would you know if it's possible to send alerts to 2 or more email addresses? 
Can I simply list additional email addresses in the dashboard (spreadsheet), separated by a comma?

Looking forward to hearing back from you!


Met vriendelijke groet / Kind regards,

Jorin van de Ven



Mercatorplein 82
1056 CL Amsterdam
the Netherlands
M. +31 6 55 47 77 12


--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/8IUSPe34spk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.

Google Ads Scripts Forum Advisor

unread,
Jan 25, 2021, 1:45:08 AM1/25/21
to adwords...@googlegroups.com
Hi Jorin,

I wasn't able to follow your last email. Could you please elaborate, so I could provide a precise guidance? As per adding more email address for email alerts, you may add it on the email cell separated by a comma.

Jorin van de Ven

unread,
Feb 4, 2021, 3:38:55 PM2/4/21
to Google Ads Scripts Forum on behalf of adsscriptsforumadvisor
Hi Teejay,
Apologies for my late response.

The script is not clearing out existing alerts in the spreadsheet with the first run of the day.
I was thinking, should we change line #80 maybe?
if (upToHour == 1) { --->  if (upToHour == 24) {

Last time I also changed line # 101 to ensure we have full day datapoints for past stats as well (next to having this for today's stats):
var pastStats = getReportStats(pastQuery, upToHour, weeks); ---> var pastStats = getReportStats(pastQuery, 24, weeks);
I have not been able to verify that the past stats are accurately reflecting the avg of the past 26 weeks though, do you believe this change is correct?

Looking forward to hearing back from you.


Met vriendelijke groet / Kind regards,

Jorin van de Ven



Mercatorplein 82
1056 CL Amsterdam
the Netherlands
M. +31 6 55 47 77 12

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/8IUSPe34spk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.

Google Ads Scripts Forum Advisor

unread,
Feb 5, 2021, 12:30:36 AM2/5/21
to adwords...@googlegroups.com

Hi Jorin,

 

Harry here, teammate of Teejay on the Google Ads Scripts Team. Allow me to assist you this time. If you want to configure the Account Anomaly Detector to check data / stats in the last 24 hours instead of the previous hour, then you should change line 80 to compare the upToHour variable with 24 and other block of codes related to this change. Kindly try this on your end and let me know how it goes, then we'll go from there.

 

Thanks,

Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q29U0iE:ref

Jorin van de Ven

unread,
Feb 5, 2021, 11:26:25 AM2/5/21
to Google Ads Scripts Forum on behalf of adsscriptsforumadvisor
Thank you, Harry.
What exactly do you mean by ''..and other block of codes related to this change''.
As an example, should I also replace upToHour by the value 24 in the piece of code illustrates below; in all four instances?

Screenshot 2021-02-05 at 17.19.31.png

Met vriendelijke groet / Kind regards,

Jorin van de Ven



Mercatorplein 82
1056 CL Amsterdam
the Netherlands
M. +31 6 55 47 77 12


--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/8IUSPe34spk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.

Google Ads Scripts Forum Advisor

unread,
Feb 8, 2021, 2:41:49 AM2/8/21
to adwords...@googlegroups.com

Hi Jorin,

 

Thanks for coming back. Upon checking with the team, the if condition "if (upToHour == 1)" should stay as is. It checks for the first run of the day (first hour) then it clears the alerts / contents in the spreadsheet but since you have scheduled your script to Daily at 6am, you should change the condition on line 80 to check if its 6 am (upToHour == 6).

 

If the script does not still clears the spreadsheet the next day of execution and considering that you've confirmed that the script now checks the data in past 24 hours, then I would suggest that you first recreate the script, re-authorize then reschedule to see if it would have the same behavior. It would also be best to create a new spreadsheet template for this one to refresh configuration and its execution. Let me know how it goes.

Jorin van de Ven

unread,
Feb 20, 2021, 11:44:34 AM2/20/21
to Google Ads Scripts Forum on behalf of adsscriptsforumadvisor
Hi Harry,
Changing the condition on line 80 to check if it's 6 am (upToHour == 6) did not work out, unfortunately.
I also identified that the past stats were not accurately reflecting the avg of the last 26 weeks.

This let me decide to move back to the original version of this script - not ideal, but probably the best option for now.
Do you believe there is any script out there that detects anomalies in yesterday's stats to send an alert by email (I am especially after alerts for a steep increase in cost)?


Met vriendelijke groet / Kind regards,

Jorin van de Ven



Mercatorplein 82
1056 CL Amsterdam
the Netherlands
M. +31 6 55 47 77 12


--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/8IUSPe34spk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.

Google Ads Scripts Forum Advisor

unread,
Feb 21, 2021, 11:30:30 PM2/21/21
to adwords...@googlegroups.com

Hi Jorin,

 

It's unfortunate that our changes didn't work this time around. I would suggest that you consider using the Account Summary Report script in this regard. The script fetches yesterday's statistics and updates the spreadsheet. The graphs are pre-configured to display the stats. If the email address is specified, the script sends out an HTML-formatted email.

 

Let me know if you have other questions/concerns.

Jorin van de Ven

unread,
Mar 21, 2021, 12:06:34 PM3/21/21
to Google Ads Scripts Forum on behalf of adsscriptsforumadvisor
Hi Harry,
I'm using the original account anomaly detector script now, but somehow still stumbling upon some ''error''.

In case of an alert for a given hour, I receive the alert twice a day.
Below the exact same alert I just received for the second time today; I guess this has to do with the script not distinguishing between a.m. and p.m.?
Could that be? And would you know how to solve for this?

Your account 708-138-7322 is not performing as expected today:
     Cost is too high: 11.28 EUR by 1:00, expecting at most 8.32
Log into Google Ads and take a look.

Thanks!


Met vriendelijke groet / Kind regards,

Jorin van de Ven



Mercatorplein 82
1056 CL Amsterdam
the Netherlands
M. +31 6 55 47 77 12


--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/8IUSPe34spk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.

Google Ads Scripts Forum Advisor

unread,
Mar 22, 2021, 3:13:07 AM3/22/21
to adwords...@googlegroups.com
Hi Jorin,

I work along with Harry. Allow me to assist you in this. 

As mentioned on our document, if the alert were somewhat noisy, scheduling it Daily around mid-day might also make sense.

Regards,
Google Logo
Teejay Wennie Pimentel
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q29U0iE:ref

Jorin van de Ven

unread,
Mar 23, 2021, 10:44:05 AM3/23/21
to Google Ads Scripts Forum on behalf of adsscriptsforumadvisor
Thanks for your suggestion, Teejay - I'll try that out.

Met vriendelijke groet / Kind regards,

Jorin van de Ven



Mercatorplein 82
1056 CL Amsterdam
the Netherlands
M. +31 6 55 47 77 12


--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/8IUSPe34spk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages