google ads trending search alert script

Google Ads Trending Search Terms Alert Script

To make the most of the Google Ads platform, its users often rely on scripts to automate tedious tasks that are error-prone and time-consuming when done manually. Introducing our free Google Ads trending alert script.

This script works by notifying you when searches for a certain term or keyword peak, enabling you to adjust your campaigns accordingly and increase overall success. 

Let’s get into it!

Google Ads Trending Search Alert Script

const config = {
    increaseThreshold: 0.9, // Any search term with a bigger % increase than this will trigger an alert
    decreaseThreshold: 0.3, // Any search term with a bigger % decrease than this will trigger an alert
    impressionThreshold: 10, // Any search term with less than this many impressions in the past 7 days will be excluded
    emails: "[email protected]", // Comma-separated list of emails the alert should be sent to
};

function main() {
    const searchTerms = {};
    const alerts = [];

    const report = getSqrReport("LAST_7_DAYS", config.impressionThreshold);
    const rows = report.rows();

    while (rows.hasNext()) {
        const row = cleanRow(rows.next());
        row.impressions_last_7d = row.impressions;
        delete row.impressions;
        searchTerms[row.search_term] = row;
    }

    const yesterdayReport = getSqrReport("YESTERDAY");
    const yesterdayRows = yesterdayReport.rows();
    while (yesterdayRows.hasNext()) {
        const row = cleanRow(yesterdayRows.next());
        if (searchTerms[row.search_term]) {
            searchTerms[row.search_term].impressions_yesterday = row.impressions;
            searchTerms[row.search_term].impr_7d_avg =
                Math.ceil((searchTerms[row.search_term].impressions_last_7d / 7) * 100) / 100;
            const impressionChange =
                (row.impressions - searchTerms[row.search_term].impr_7d_avg) / searchTerms[row.search_term].impr_7d_avg;
            searchTerms[row.search_term].impression_change = Math.ceil(impressionChange * 10000) / 100 + "%";

            if (impressionChange > config.increaseThreshold) {
                alerts.push(searchTerms[row.search_term]);
            } else if (impressionChange < 0 && impressionChange > -config.decreaseThreshold) {
                alerts.push(searchTerms[row.search_term]);
            }
        }
    }

    // Send alerts
    console.log(`Found ${alerts.length} alerts`);
    if (alerts.length > 0) {
        const subject = "";
        const body =
            `<style>font-family: Arial, Helvetica, sans-serif;font-size: 12px;</style>Hello, <br><br>` +
            `The following search terms have seen significant changes in their impressions: <br><br>${arrOfObjectsToHtmlTable(
                alerts
            )}<br><br>` +
            `Thanks,<br>The Script`;
        //MailApp.sendEmail(config.emails, subject, body);
        MailApp.sendEmail({
            to: config.emails,
            subject,
            htmlBody: body,
        });
    }

    function getSqrReport(dateRange, impressions = 0) {
        const query = `
      SELECT 
        search_term_view.search_term, 
        ad_group.name, 
        campaign.name, 
        customer.descriptive_name, 
        segments.keyword.info.text, 
        segments.keyword.info.match_type, 
        metrics.clicks, 
        metrics.cost_micros, 
        metrics.impressions 
      FROM search_term_view 
      WHERE 
        segments.date DURING ${dateRange} 
        AND metrics.impressions > ${impressions}
    `;
        const report = AdsApp.report(query);
        return report;
    }

    function cleanRow(row) {
        delete row["formatForUpload"];
        const newRow = {};
        for (attr in row) {
            let value = row[attr];

            const attrSplit = attr.split(".");
            if (attrSplit[0] === "metrics" || attrSplit[0] === "segments" || attrSplit[0].indexOf("view") !== -1) {
                attrSplit.shift();
            }
            let attribute = attrSplit.join("_");

            if (attr.indexOf("cost_micros") !== -1) {
                value = parseFloat(value) / 1000000;
                attribute = "cost";
            }
            if (attr.indexOf("metrics") !== -1) {
                value = parseFloat(value);
            }

            newRow[attribute] = value;
        }
        return newRow;
    }

    function arrOfObjectsToHtmlTable(arr) {
        const headers = `<tr>${Object.keys(arr[0])
            .map((el) => `<th>${titleCase(el.replace(/_/g, " "))}</th>`)
            .join("")}</tr>`;
        const body = arr
            .map((row) => {
                return `<tr>${Object.values(row)
                    .map((el) => `<td>${el}</td>`)
                    .join("")}</tr>`;
            })
            .join("");
        const style = `
      <style>
        #script-table {
          border-collapse: collapse;
          width: 100%;
        }

        #script-table td, #script-table th {
          border: 1px solid #ddd;
          padding: 8px;
        }

        #script-table tr:nth-child(even){background-color: #f2f2f2;}

        #script-table tr:hover {background-color: #ddd;}

        #script-table th {
          padding-top: 12px;
          padding-bottom: 12px;
          text-align: left;
          background-color: #028afc;
          color: white;
        }
      </style>
    `;

        const table = `${style}<table id=script-table>${headers}${body}</table>`;
        return table;

        function titleCase(str) {
            return str
                .toLowerCase()
                .split(" ")
                .map(function (word) {
                    return word.charAt(0).toUpperCase() + word.slice(1);
                })
                .join(" ");
        }
    }
}

How to Use Scripts in Google Ads

Using scripts in Google Ads is a relatively easy process, which can save you a lot of time and effort in the long run when managing your PPC campaigns.

First off, when you’ve signed into your account, go to “Tools & Settings” and select “Scripts” from the menu. This will give you the option to either create a new script or choose from a library of pre-made ones. Once you’ve chosen it, you can set it up by specifying its conditions. 

Aside from what our Google Ads trending search alert script has to offer, scripts can be useful in a variety of ways. Examples include generating reports, adjusting bids and budgets, pausing or enabling campaigns based on certain conditions, analyzing data, and even creating and managing ads. 

What is the Trending Search Alert Script for Google Ads?

This script works by sending you an alert when there has been a change in trending Google search terms. This notification will come in through email and might include a report in Google Sheets, listing the top trending terms.

This script is pretty handy because it helps users stay up-to-date with the latest search trends and adjust their ad campaigns accordingly. For example, if they notice a search term is getting more popular, they can increase their ad budget to take advantage of the increased interest and potentially improve their conversion rate.

On the other hand, if a search term is bringing in traffic that’s not quite relevant to their business, they can pause those ads to avoid wasting their advertising budget.

Ultimately, Google Ads trending search alert script can be a valuable tool in assisting advertisers in staying ahead of the curve and making data-driven decisions when it comes to their advertising campaigns.

How Does the Google Ads Trending Search Alert Script Work?

Our Google Ads trending search alert script works by keeping tabs on the search volume of specific keywords in Google Search. It also collects data from Google Ads and compares the impressions (number of times your ad appears on the page) for selected time periods, like the last 7 days or 30 days. 

Then, it calculates the difference in impressions between the current and previous periods to detect if there’s been a significant surge in search volume. 

If your predetermined threshold for the increase is reached, the script sends an email notification to alert you of the trending search term, enabling you to stay on top of the latest Google trends and adjust your ad campaigns to meet their optimum success rate.

Why Should You Use the Google Ads Trending Search Alert Script 

There are many benefits to using the Google Ads trending search alert script to aid your ad campaigns. 

Some of the most important ones are the following:

  • It allows agencies to make better use of their daily or monthly ad budget by focusing on high performing keywords. This can help businesses maximize their ROI and get the most out of their advertising budget.
  • The script also helps businesses avoid funneling unqualified traffic, providing the insight needed to pause ads or negative keywords effectively. This can help businesses save money on advertising and improve the overall effectiveness of their campaigns.
  • The script can also help improve ad conversion rate by targeting popular search terms that are relevant to their business and increase customer engagement

When to Use the Google Ads Trending Search Alert Script? 

Here are some situations where this script can be particularly useful:

  • When managing multiple accounts it can be tricky keeping track of all the search terms that are relevant to each. The script can help clearly and concisely identify trending search terms across all accounts, making it easier to adjust campaigns accordingly.
  • When targeting high cost per click (CPC) keywords, bidding can get expensive. Using the script to identify trending search terms will allow agencies to potentially discover new, lower-cost keywords to target that are still relevant to their product or service.
  • The script is also handy in situations when there are certain limitations to the ads budget. By identifying trending search terms and adjusting campaigns accordingly, businesses can focus on high-performing keywords that are likely to result in conversions, while avoiding wasting money on keywords that aren’t bringing in qualified traffic.
  • The script can also help during seasonal traffic influxes, such as during holiday shopping seasons, as it can help agencies stay ahead of the competition by identifying new trends in peak periods.

When to Use the Google Ads Trending Search Alert Script?

Custom Automation Scripts by Acuto

If your agency is spending valuable time on tasks that are time-consuming and error-prone, but you don’t want to overspend on different automation tools, perhaps a bespoke automation script is your solution.

Acuto can help you streamline your workflow and boost productivity with our custom script development services. Our automation services can provide scripts tailored to the unique needs of your agency, freeing up the time, costs and energy needed elsewhere so that your team can focus solely on maximising growth.

Check out more of our free scripts here, or, if you want to discuss your particular needs, make sure to get in touch.

Want to automate Google Ads with custom scripts?

If you liked this script or would like a personalized one, we’re here to help! Our team of developers with experience in PPC can create custom scripts to automate any aspect of your Google Ads accounts. Schedule a discovery call to discuss how we can assist you in implementing automation scripts effectively.

Key Takeaways

So, let’s recap what we’ve learnt here:

  • Google Ads is a powerful platform for businesses, which can be supercharged with scripts to automate tedious tasks and save time when managing PPC campaigns.
  • Our Google Ads trending search alert script is free and is designed to send alerts when there’s been a change in trending search terms on Google.
  • The script keeps tabs on the search volume of specific keywords, collects data from Google Ads, and compares impressions for selected time periods to detect significant surges in search volume.
  • The benefits of using Acuto’s tailored script include maximizing ROI, improving ad conversion rate, and staying ahead of the competition. It is very useful when managing multiple accounts, high cost per click keywords, budget limitations, and seasonal traffic influxes helping your agency reach its maximum potential!

If you encounter any issues while using the script, please contact us.

Recent Posts
google ads high CPC alert script

Google Ads High CPC Alert Script

Discover how Google Ads high CPC alert script can revolutionise the way marketing agencies optimise their campaigns.

pause google ads with low CTR script

Pause Google Ads with Low CTR Script

Use this free script to pause Google Ads with low CTR to help improve the efficiency of your campaign and avoid wasted ad spend.

Recent Posts