Script failure

78 views
Skip to first unread message

Guilherme Machado - Google Ads

unread,
Dec 11, 2023, 8:34:54 PM12/11/23
to Google Ads Scripts Forum
Hello, could you help me how to fix this error?

Screenshot_7.png
Screenshot_8.png

Screenshot_6.png

Nils Rooijmans

unread,
Dec 12, 2023, 4:10:54 AM12/12/23
to Google Ads Scripts Forum
from the looks of it (logger output), the function getPMaxCampaigns() does not return any campaign id's. 
Could it be that the account does not have any PMax campaigns running, or that the code of  getPMaxCampaigns() filters campaigns based on some condition (ie: campaign names)?
If you share the code of that function we can have a look.

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/

Guilherme Machado - Google Ads

unread,
Dec 12, 2023, 9:49:50 AM12/12/23
to Nils Rooijmans via Google Ads Scripts Forum
Good morning!

Below is the script

var fullReport = [];

function main() {

    // enter your spreadsheet url  and sheet name
    let sheetUrl = 'https://docs.google.com/spreadsheets/d/1RO8lHTsY8O0yjjIwpSKv5IZXSfH2p5uQaPB2-85029Y/edit?usp=sharing'; // enter spreadsheet URL between the quotes
    let sheetName = 'Ultimate Performance Max Insight Report - V3 - Delupo 👾🧠🤖🚀'; // enter sheet name between the quotes
   
    // don't touch code below this line
    // =================================
    let ss = SpreadsheetApp.openByUrl(sheetUrl);

    const campaignIds = getPMaxCampaigns();
    Logger.log(campaignIds)

    for (var id of campaignIds) {
        getPMaxSearchTerms(id)
    }
    let headers = Object.keys(fullReport[0]);
    console.log(headers);

    let values = fullReport.map(x => headers.map(function(y) {
        if (x[y]) { return x[y] } else { return "" }
    }));

    values.unshift(headers);

    ss.getSheetByName(sheetName).clear().getRange(1, 1, values.length, values[0].length).setValues(values);

}

function getPMaxSearchTerms(campaignId) {

    let query = AdsApp.search(
        `SELECT
           campaign.name,
           campaign_search_term_insight.category_label,
           campaign_search_term_insight.id,
           metrics.clicks,
           metrics.impressions,
           metrics.conversions,
           metrics.conversions_value
          FROM campaign_search_term_insight
          WHERE segments.date DURING LAST_30_DAYS
           AND campaign_search_term_insight.campaign_id = '${campaignId}'`);

    Logger.log(query.totalNumEntities())
    while (query.hasNext()) {
        let r = query.next()
        let row = Object.assign(r.campaign, r.campaignSearchTermInsight, r.metrics);
        delete row.resourceName
        fullReport.push(row)
    }
}

function getPMaxCampaigns() {
    let retVal = []
    let query = `SELECT campaign.id
               FROM campaign WHERE campaign.advertising_channel_type = 'PERFORMANCE_MAX'
                AND campaign.serving_status = 'SERVING'
                AND campaign.status = 'ENABLED'`

    let report = AdsApp.search(query);

    while (report.hasNext()) {

        let r = report.next()
        let id = r.campaign.id
        if (retVal.indexOf(id) == -1) {
            retVal.push(id)
        }
    }
    return retVal;
}

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/oUCrlj-gX98/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/5a93675b-39df-4a85-9959-350534f11b15n%40googlegroups.com.

Google Ads Scripts Forum Advisor

unread,
Dec 12, 2023, 12:07:30 PM12/12/23
to adwords...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads Scripts support team.

After reviewing your concern, I understand you are getting undefined error messages. I would like to inform you that your error messages indicate that you are fetching a variable value without initialization. I would like to suggest that you initialize the fullReport array before fetching the value from the 0 index of the fullReport[0] array.

If you still face any issue while running your script please revert back with following details : 
  • Google Ads account ID / CID
  • Name of the script in the account.
  • The uncropped screen shot of the error you encountered.
You can send the details via Reply privately to the author option, or direct private reply to this email.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02r1JDG:ref"

Thanks,
 
Google Logo Google Ads Scripts Team

 

Reply all
Reply to author
Forward
0 new messages