0 Conversions in past hour Alert Script

281 views
Skip to first unread message

SB

unread,
Feb 1, 2024, 11:29:54 AM2/1/24
to Google Ads Scripts Forum
Hello all, unfortunately we sometimes run into technical issues and conversions don't fire back (3rd party tracking). It has happened twice so far that we didnt notice until a couple hours later so we want to put an alert script into place where we get an alert if there were no conversions in the past hour.

The script we have now is:

function main() {
  // Set your email address
  var emailAddress = "mye...@email.com";

  // Get the conversion stats for today
  var stats = AdsApp.currentAccount().getStatsFor("TODAY");

  // Filter the statistics to include only data for the last hour
  var conversionsLastHour = filterConversionsLastHour(stats);

  // Check if there are no conversions in the last hour
  if (conversionsLastHour === 0) {
    // Send an email alert
    sendEmailAlert(emailAddress, "No conversions recorded in the past hour.");
  }
}

// Function to filter conversions for the last hour
function filterConversionsLastHour(stats) {
  var now = new Date();
  var oneHourAgo = new Date(now.getTime() - (1 * 3600 * 1000)); // 1 hour ago

  var iterator = stats.conversions().forDateRange(oneHourAgo, now).get();
  var count = 0;
  while (iterator.hasNext()) {
    var conversion = iterator.next();
    count++;
  }
  return count;
}

// Function to send email alert
function sendEmailAlert(email, message) {
  // Send email
  MailApp.sendEmail({
    to: email,
    subject: "Google Ads Alert: No Conversions",
    body: message
  });
}

So the reason why it is a bit convoluted is because initially we got this error: Ga: Invalid input: LAST_HOUR. Expected one of ["TODAY","YESTERDAY","LAST_7_DAYS","LAST_14_DAYS","LAST_30_DAYS","LAST_BUSINESS_WEEK","LAST_WEEK_SUN_SAT","LAST_WEEK_MON_SUN","THIS_WEEK_SUN_TODAY","THIS_WEEK_MON_TODAY","THIS_MONTH","LAST_MONTH","ALL_TIME"] at main (Code:6:39) So we added this workaround to still have it check hourly. Unfortunately now we get this error: Ba: Could not read from Google Ads at main (Code:6:51)

My question is twofold: 1. Does the script look oke, or does anyone have an simpler solution for receiving alerts when there are no conversions in the past hour? 2. If so, how can we solve the error? Your help is much appreciated!

Kind regards,

SB

Google Ads Scripts Forum

unread,
Feb 13, 2024, 7:19:43 AM2/13/24
to Google Ads Scripts Forum
Hi ,

Thank you for reaching out to the Google Ads Scripts team. 

It appears that something is broken with this post. I would request you to reach out to the Google Ads Scripts support team directly to this email googleadsscr...@google.com

Thanks,
Google Ads Scripts

Google Ads Scripts Forum Advisor

unread,
Feb 13, 2024, 10:04:59 AM2/13/24
to adwords...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads Scripts Team. 

By reviewing your query, I understand that you are facing an error while executing the script. Provide us with the below details to further investigate the issue:

  • Google Ads account ID / CID.
  • Name of the new script.
  • Error details or the screenshot of the issue (if any).

You can send the details via Reply privately to the author option, or direct private reply to this email.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02rz3m3:ref"

Thanks,
 
Google Logo Google Ads Scripts Team


Reply all
Reply to author
Forward
0 new messages