Google Ads Script: Conversion Action Alert

Foto van Matinique Roelse
Matinique Roelse

Inhoudsopgave

Below, you’ll find a Google Ads script that alerts you when a specific conversion action in Google Ads stopped generating revenue

What The Script Does

👉 Monitors a specific conversion action
👉 Sends instant email alerts when tracking breaks
👉 Takes less than 2 minutes to set up

Installing The Script

  1. Put the script in Google Ads.
  2. Add your email in the script
  3. Add the number of days to count
  4. Add the name of your conversion action
  5. Preview the script.
  6. Schedule the script if you’re happy with it (I prefer daily)

Script Introduction

Want to never miss broken conversions again?

Me neither.

Last week, one of our clients’ conversion tracking broke down.

Nobody wants that to happen.

Our regular ‘no conversions’ monitoring missed it, because it was only a specific conversion that stopped working.

And that was (of course) the most important conversion action.

Because sometimes, you optimize for different conversions in one Google Ads campaign or account.

We HAD to automate this to prevent it in the future.

Script Code

// Script to check conversion actions and their revenue
// Scripted by Adcrease > www.adcrease.nl
// First add the requirements (Email, Num_days and Conversion_Action_Name, then 'Preview' and 'schedule'

const YOUR_EMAIL = 'your@email.com';   // enter your email address here between the single quotes
const NUM_DAYS = 3; // number of days to check
const CONVERSION_ACTION_NAME = 'Name_of_your_conversion_action'; // enter the name of your conversion action here

function main() {
  try {
    // Get conversion action data using GAQL
    const query = AdsApp.report(
      `SELECT 
        conversion_action.name, 
        metrics.all_conversions,
        metrics.all_conversions_value,
        metrics.conversion_last_conversion_date, 
        conversion_action.include_in_conversions_metric, 
        conversion_action.type,
        customer.descriptive_name
      FROM conversion_action 
      WHERE conversion_action.include_in_conversions_metric = TRUE
      AND conversion_action.name = '${CONVERSION_ACTION_NAME}'
 `
    );
    
    const rows = query.rows();
    const problemConversions = [];
    
    while (rows.hasNext()) {
      const row = rows.next();
      const lastDate = row['metrics.conversion_last_conversion_date'];
      const conversions = Number(row['metrics.all_conversions']) || 0;
      const revenue = Number(row['metrics.all_conversions_value']) || 0;
      
      if (lastDate) {
        const lastConversionDate = new Date(lastDate);
        const daysSinceLastConversion = Math.floor((new Date() - lastConversionDate) / (1000 * 60 * 60 * 24));
        
        if (daysSinceLastConversion >= NUM_DAYS) {
          problemConversions.push({
            name: row['conversion_action.name'],
            lastDate: lastConversionDate.toISOString().split('T')[0],
            daysSince: daysSinceLastConversion,
            totalConversions: conversions,
            totalRevenue: revenue,
            type: row['conversion_action.type'],
            included: row['conversion_action.include_in_conversions_metric'],
            accountName: row['customer.descriptive_name']
          });
        }
      }
    }
    
    if (problemConversions.length === 0) {
      Logger.log(`No issues found for conversion action: ${CONVERSION_ACTION_NAME}`);
      return;
    }
    
    const subject = `Alert: No Recent Revenue for ${CONVERSION_ACTION_NAME}`;
    const body = `Account: ${problemConversions[0].accountName}\n\n` +
      `The conversion action "${CONVERSION_ACTION_NAME}" has had no revenue in the last ${NUM_DAYS} days.\n\n` +
      `Last conversion: ${problemConversions[0].lastDate} (${problemConversions[0].daysSince} days ago)\n` +
      `Type: ${problemConversions[0].type}\n` +
      `Primary conversion: ${problemConversions[0].included}\n\n` +
      `This is an automated alert sent by a google ads script.`;
    
    MailApp.sendEmail({
      to: YOUR_EMAIL,
      subject: subject,
      body: body
    });
    
    Logger.log(`Alert sent for ${CONVERSION_ACTION_NAME}`);
  } catch (error) {
    const errorMsg = `Error in conversion monitoring script: ${error.message}`;
    Logger.log(errorMsg);
    MailApp.sendEmail({
      to: YOUR_EMAIL,
      subject: 'Error in Google Ads Conversion Monitoring Script',
      body: errorMsg
    });
  }
} 

That’s it! 

Any comments or add-ons?

Happy to hear!

Facebook
Twitter
LinkedIn

Lees meer van Adcrease

Direct een gratis Google Ads Check aanvragen!

Gratis advies over je Google Ads

Naam(Vereist)