cov19 icon
COVID-19 COMPANY UPDATE
We are 100% available for you and provide strategic advice on how your business can cope with uncertainty these days.

Microsoft Advertising Budget Eater Script

Script to evaluate your long tail and identify non-converters for Microsoft text ads

Microsoft Advertising Budget Eater Script illustration

Ready to learn more about your Microsoft Advertising long tail and non-converters?

The “Budget Eater” script evaluates the long tail and non-converters of the last 30 days. It will analyse your Search campaigns and provide you with insights about the correlations between costs, conversions and the long tail. Furthermore, you will get impressions regarding the contribution of your long tail to your revenue, and statistics about your non-converters and top converters. Just add the script to your Microsoft Advertising (formerly known as Bing Ads) account and get your results. The code won’t change anything in your Microsoft Advertising campaigns, it just analyses your existing data and provides you with an automatic evaluation.

Download script and start optimizing

No commitments & no hidden costs — Just a great script

Access and read our privacy policy.

Success image

Thank you!

You can get the script code below

Arrow down icon
/**
 * Microsoft Advertising Budget Eater Script         . * ・ 。゚☆━੧[ ✪ ᗜ ✪ ]⊃
 *
 * Overview: You can use this script to evaluate your long tail and your
 * non-converting keywords from the last 30 days (campaign type Search). The script will give you an impression
 * of the correlations between costs, conversions, and the Long Tail within
 * your Microsoft Advertising account.
 *
 * Author: smec Team [smarter-ecommerce.com]
 *
 * Version: 1.0
 * Changelog:
 * - version 1.0
 *  - Released initial version.
 * Updated: 19-02-2020
 *
 * Twitter: @smec
 * Email: [email protected]
 * (c) Smarter Ecommerce GmbH. All rights reserved.
 * License: MIT
 */

/* ============================== Preferences =============================== */

// Sets the number of conversions threshold for evaluating the Long Tail.
var LONG_TAIL_CONVERSIONS_THRESHOLD = 1;

var REPORTING_DATE_RANGE = "LAST_30_DAYS";

/* =============================== Execution ================================ */

function main() {
    var totalCost = 0;

    var result = {
        nonConverters: { count: 0, cost: 0 },
        longtail: { count: 0, cost: 0, conversions: 0, revenue: 0 },
        converters: { count: 0, cost: 0, conversions: 0, revenue: 0 }
    };

    var iterator1 = AdsApp.keywords()
        .withCondition('Conversions < 1')
        .forDateRange(REPORTING_DATE_RANGE)
        .get();        
    var iterator2 = AdsApp.keywords()
        .withCondition('Conversions >= 1')
        .withCondition('Conversions <= '+LONG_TAIL_CONVERSIONS_THRESHOLD)
        .forDateRange(REPORTING_DATE_RANGE)
        .get();
    var iterator3 = AdsApp.keywords()
        .withCondition('Conversions > '+LONG_TAIL_CONVERSIONS_THRESHOLD)
        .forDateRange(REPORTING_DATE_RANGE)
        .get();

    result.nonConverters.count = iterator1.totalNumEntities();

    // Get the total costs for all search campaigns
    var iterator0 = AdsApp.campaigns()
        .withCondition("Type = SEARCH_AND_CONTENT")
        .forDateRange(REPORTING_DATE_RANGE)
        .get();

    while (iterator0.hasNext()) {
        var campaign = iterator0.next();
        var metrics = campaign.getStats();
        totalCost += metrics.getCost();
    }   

    while (iterator2.hasNext()) {
        let keyword = iterator2.next();
        let kwStats = keyword.getStats();

        let conversions = kwStats.getConversions();
        let cost = kwStats.getCost();
        let revenue = kwStats.getRevenue();

        result.longtail.count += 1;
        result.longtail.conversions += conversions;
        result.longtail.cost += cost;
        result.longtail.revenue += revenue;
    }

    while (iterator3.hasNext()) {
        let keyword = iterator3.next();
        let kwStats = keyword.getStats();

        let conversions = kwStats.getConversions();
        let cost = kwStats.getCost();
        let revenue = kwStats.getRevenue();

        result.converters.count += 1;
        result.converters.cost += cost;
        result.converters.conversions += conversions;
        result.converters.revenue += revenue;
    }    

    result.nonConverters.cost = totalCost - (result.longtail.cost + result.converters.cost);

    var totalConversions = result.longtail.conversions + result.converters.conversions;
    var totalRevenue = result.longtail.revenue + result.converters.revenue;

  // In this part, the calculated result numbers are printed:
  Logger.log("Microsoft Ads Search campaigns report ("+REPORTING_DATE_RANGE+")");
  Logger.log("===========================\n");
  Logger.log("Number of keywords without conversions (Non-Converters): " + result.nonConverters.count);
  Logger.log("Number of keywords in Long Tail with up to "+LONG_TAIL_CONVERSIONS_THRESHOLD+" conversion(s): " + result.longtail.count);
  Logger.log("Number of keywords having more than "+LONG_TAIL_CONVERSIONS_THRESHOLD+" conversion(s): " + result.converters.count + "\n");
  Logger.log("===========================\n");
  Logger.log("Total costs: " + round(totalCost));
  Logger.log("- - - - - - - - - - - - - -\n");
  Logger.log("Cost for Non-Converters: " + round(result.nonConverters.cost) +
      " (" + round(percentage(result.nonConverters.cost, totalCost)) + "% from total cost)\n");
  Logger.log("Cost for Long Tail keywords: " + round(result.longtail.cost) +
      " (" + round(percentage(result.longtail.cost, totalCost)) + "% from total cost)\n");
  Logger.log("Cost for top converters (more than "+LONG_TAIL_CONVERSIONS_THRESHOLD+" conv.): " + round(result.converters.cost) +
      " (" + round(percentage(result.converters.cost, totalCost)) + "% from total cost)\n");
  Logger.log("===========================\n");               
  Logger.log("Total conversions: " + round(totalConversions));
  Logger.log("- - - - - - - - - - - - - -\n");
  Logger.log("Conversions from Long Tail keywords: " + round(result.longtail.conversions) +
      " (" + round(percentage(result.longtail.conversions, totalConversions)) + "% from total conversions)");
  Logger.log("Conversions from top converters (more than "+LONG_TAIL_CONVERSIONS_THRESHOLD+" conv.): " + round(result.converters.conversions) +
      " (" + round(percentage(result.converters.conversions, totalConversions)) + "% from total conversions)"); 
  Logger.log("===========================\n");
  Logger.log("Total Revenue: " + round(totalRevenue));
  Logger.log("- - - - - - - - - - - - - -\n");
  Logger.log("Revenue from Long Tail: " + round(result.longtail.revenue) +
      " (" + round(percentage(result.longtail.revenue, totalRevenue)) + "% from total revenue)\n");           
}

/**
 * A helper function which rounds the given number to 2 decimals.
 */
function round(number) {
  return Math.round(number * 100) / 100;
}

/**
 * A helper function which returns the percentage of a value for the given total value.
 */
function percentage(value, total) {
  return value / total * 100;
}

The code was successfully copied to your Clipboard.

Popular Google Ads Scripts

Martin Röttgerding

“Automation can take your PPC efforts to the next level – if you’re doing it right.”

Martin Röttgerding, Head of SEA – Bloofusion Germany

Maximize your Google Shopping performance with Whoop!

Get in touch to learn more