google-apigoogle-ads-script

Account Summary Report Google Ads Script not sending emails after I added new metrics


I added conversion and revenue columns to the script which can be found here.

This is the error I'm getting in the logs (the spreadsheet is updating fine with no issues):

TypeError: newValue.indexOf is not a function
    at formatChangeString (Code:366:33)
    at emailRow (Code:314:11)
    at Code:285:15
    at Array.forEach (<anonymous>)
    at sendEmail (Code:284:17)
    at main (Code:106:7)

Solution

  • formatChangeString(newValue,oldValue) expects newValue to be a string (so that newValue.indexOf('%') can be called.

    It seems that one of the metrics you added is returned by the AdsApp.report call as a different type (most likely Number).

    If you want a quick workaround, just change the line

    const isPercentage = newValue.indexOf('%') >= 0;
    

    to

    const isPercentage = String(newValue).indexOf('%') >= 0;