Script to increase the bid in relation to impressions share lost by ranking

57 views
Skip to first unread message

Andrea Fiore

unread,
Mar 27, 2023, 9:09:18 AM3/27/23
to Google Ads Scripts Forum
Hello! I'm trying to run this script to increase the bid in relation to the share of impressions lost by ranking

function main() {
  // seleziona la campagna tramite nome
  var campaignName = "Insert Campaign Name Here"; // Sostituisci con il nome della tua campagna
  var campaignIterator = AdsApp.campaigns().withCondition("Name = '" + campaignName + "'").get();

  if (!campaignIterator.hasNext()) {
    Logger.log("Nessuna campagna trovata con il nome: " + campaignName);
    return;
  }

  var campaign = campaignIterator.next();

  // calcola la quota impressioni persa per ranking degli ultimi 7 giorni
  var stats = campaign.getStatsFor("LAST_7_DAYS");
  var impressionsLostToRank = stats.getImpressionsLostDueToRank();

  Logger.log("La quota impressioni persa per ranking degli ultimi 7 giorni per la campagna " + campaignName + " è: " + impressionsLostToRank);

  // aumenta il CPC di tutte le parole chiave della campagna del 10% se la quota impressioni persa per ranking è superiore al 10%
  if (impressionsLostToRank / stats.getImpressions() > 0.1) {
    var keywordsIterator = campaign.keywords().get();
    while (keywordsIterator.hasNext()) {
      var keyword = keywordsIterator.next();
      var currentCpc = keyword.bidding().getCpc();
      keyword.bidding().setCpc(currentCpc * 1.1);
    }

    Logger.log("Il CPC di tutte le parole chiave della campagna " + campaignName + " è stato aumentato del 10%");
    // Invia la notifica via email
    var emailSubject = "Aumento CPC - Campagna " + campaignName;
    var emailBody = "Il CPC di tutte le parole chiave della campagna " + campaignName + " è stato aumentato del 10% a causa di una quota impressioni persa per ranking superiore al 10% negli ultimi 7 giorni.";
    MailApp.sendEmail("tuaindir...@dominio.com", emailSubject, emailBody);
  }
}

The log returns this error:  

TypeError: stats.getImpressionsLostDueToRank is not a function at main (Code:15:37) at Object.<anonymous> (adsapp_compiled:19677:54)

How can I solve it?

Thanks!

Nils Rooijmans

unread,
Mar 28, 2023, 2:55:58 AM3/28/23
to Google Ads Scripts Forum
the method getImpressionsLostDueToRank() does not exits.

To get the estimated percentage of impressions on the Search Network that your ads didn't receive due to poor Ad Rank your need to create a GAQL query .
You can use the query to get the keywords that you would like to increase the bids for.

Hope this helps,

Nils Rooijmans
https://nilsrooijmans.com
See my Google Ads Scripts FAQ to avoid the same mistakes I made: https://nilsrooijmans.com/google-ads-scripts-faq/

Google Ads Scripts Forum Advisor

unread,
Mar 28, 2023, 4:18:10 AM3/28/23
to adwords...@googlegroups.com

Hi All,

 

@Nils - Thank you for your insights on this.

 

@Andrea - I would agree that there isn't a method such as 'getImpressionsLostDueToRank()' which you may use in Google Ads Scripts. You may refer to Nils' previous response on how you may be able to retrieve an estimated percentage of impressions on the Search Network which can be done via Reporting. For an example on how to create a report, you may check this link.

 

Upon checking your script, it appears that you would like to check this field for a campaign seeing as you've implemented it within it's iterator. You may use the field metrics.search_rank_lost_impression_share using the campaign report type. In order to help you build the query you'd use, you can check the campaign report's query builder. If you would instead like to check for this field in keywords, then you may use the same field but using the keyword_view report type. You can check this link for the report type's query builder.

 

Let us know if you have any further clarifications.

 

Best regards,

 

Google Logo Google Ads Scripts Team


ref:_00D1U1174p._5004Q2kCJVo:ref
Reply all
Reply to author
Forward
0 new messages