Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Script for PMax evaluation - Deep Insights

42 views
Skip to first unread message

Selina Poms

unread,
Jan 20, 2025, 9:12:55 AMJan 20
to adwords...@googlegroups.com
Hi!

I have created a script that shows me the PMax conversions by placement channel. Unfortunately, I only ever see ‘0’ after each channel in the spreadsheet.
image.png
What is the error here?
I would also like to add the costs per channel, what is the best way to do this?
And would there be a way to go even deeper in terms of placements so that you could see the individual apps, websites, etc.?

This is/was my script: 

function main() {
  const SPREADSHEET_URL = 'https://docs.google.com/spreadsheets/d/1nltpU0p77RI82N12djftEVA3NOCoYWO3lbb4NXFDfR8/edit';

  const query = `
    SELECT
      segments.ad_network_type,
      metrics.conversions
    FROM
      campaign
    WHERE
      campaign.advertising_channel_type = 'PERFORMANCE_MAX'
      AND segments.date BETWEEN '2024-12-20' AND '2025-01-19'
  `;

  const report = AdsApp.report(query);
  const rows = report.rows();

  let conversionByNetwork = {
    'SEARCH': 0,
    'DISPLAY': 0,
    'YOUTUBE': 0,
    'GMAIL': 0,
    'SHOPPING': 0
  };

  Logger.log('Processing query results...');
  while (rows.hasNext()) {
    const row = rows.next();
    const network = row['segments.ad_network_type'];
    const conversions = parseFloat(row['metrics.conversions']);

    // Debugging: Log the raw data
    Logger.log(`Network: ${network}, Conversions: ${conversions}`);

    if (network in conversionByNetwork) {
      conversionByNetwork[network] += conversions;
    } else {
      Logger.log(`Unexpected network type: ${network}`);
    }
  }

  // Debugging: Log the final results
  Logger.log('Final conversion data:');
  for (const network in conversionByNetwork) {
    Logger.log(`${network}: ${conversionByNetwork[network]}`);
  }

  // Open the spreadsheet
  const spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  const sheet = spreadsheet.getActiveSheet();

  // Clear existing data in the sheet
  sheet.clear();

  // Write headers
  sheet.getRange(1, 1).setValue('Network');
  sheet.getRange(1, 2).setValue('Conversions');

  // Write data
  let rowIndex = 2;
  for (const network in conversionByNetwork) {
    sheet.getRange(rowIndex, 1).setValue(network);
    sheet.getRange(rowIndex, 2).setValue(conversionByNetwork[network]);
    rowIndex++;
  }

  Logger.log('Data written to the spreadsheet successfully.');
}



Thank you sooo much for your help!

Best wishes, 

Selina

Google Ads Scripts Forum

unread,
Jan 20, 2025, 11:18:23 AMJan 20
to Google Ads Scripts Forum
Hi,

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

In order to assist you further, could you please provide us with the following details:
  • Google Ads account ID/CID
  • Name of the script
You can share the requested details via Reply privately to the author option or a direct private reply to this email.

Thanks,
Google Ads Scripts team
Reply all
Reply to author
Forward
0 new messages