PMax Data

Report on your PMax campaigns in a seperate spreadsheet

Start Now!
Report on your PMax campaigns
PMax Data Get started!

 

  1. Import script into account.
  2. Make a copy of the spreadsheet (column names and tabs are most important)
  3. Copy the new spreadsheet URL in the script
  4. Adjust N=14 (number of days) if you like.
  5. Run the script.

Note: you will see a difference between campaign level data and what the script can fetch. This is because until now it is not possible to retrieve keyword/search and other data, such as Sponsored Gmail, Discovery, etc.

The script
/****************************
 * Created By: Jermaya Leijen (https://partout.nl/)
 ****************************/

function main() {
  const count_days=14  
  const sheet_url="https://docs.google.com/spreadsheets/d/1wuWPouMr0bc7LLscEB44sCea7h5G-WBH0Yvg_awlvNQ/edit#gid=0"

  const end=new Date(Date.now() - 86400000)    
  const start=new Date(Date.now() - count_days*86400000)  
  
  let sh
  let searchResults

  const ss=SpreadsheetApp.openByUrl(sheet_url)
  
  let data=[]  
  searchResults = AdsApp.search( `SELECT  segments.day_of_week, segments.hour, metrics.conversions, metrics.conversions_value, metrics.clicks, campaign.id,
  metrics.cost_micros, metrics.impressions  FROM campaign 
  WHERE campaign.advertising_channel_type = PERFORMANCE_MAX AND segments.date>='${date_format(start)}' AND segments.date <='${date_format(end)}' `)
  // ORDER BY segments.day_of_week ASC`
  for (const row of searchResults) {
    //Logger.log(row)
    data.push([row.segments.dayOfWeek,row.segments.hour, row.campaign.id, row.metrics.impressions,row.metrics.clicks,row.metrics.conversions,row.metrics.conversionsValue,(parseInt(row.metrics.costMicros)/1000000).toFixed(2)])
  } 
  sh=ss.getSheetByName("day of the week - hour")
  if (sh.getMaxRows()>1) sh.getRange(2,1,sh.getMaxRows(),data[0].length).clear()
  sh.getRange(2,1,data.length, data[0].length).setValues(data)
  
  data=[]
  searchResults = AdsApp.search( `SELECT  segments.product_item_id, campaign.advertising_channel_type, metrics.conversions, metrics.conversions_value, metrics.clicks,
  metrics.cost_micros, metrics.impressions  FROM shopping_performance_view 
  WHERE campaign.advertising_channel_type = PERFORMANCE_MAX AND segments.date>='${date_format(start)}' AND segments.date <='${date_format(end)}' `)
  // ORDER BY segments.day_of_week DESC, segments.hour ASC

  for (const row of searchResults) {
    //Logger.log(row)
    data.push([row.segments.productItemId,row.metrics.impressions,row.metrics.clicks,row.metrics.conversions,row.metrics.conversionsValue,(parseInt(row.metrics.costMicros)/1000000).toFixed(2)])
  }
  sh=ss.getSheetByName("Products ID")
  if (sh.getMaxRows()>1) sh.getRange(2,1,sh.getMaxRows(),data[0].length).clear()
  sh.getRange(2,1,data.length, data[0].length).setValues(data);
  
  data=[]
  searchResults = AdsApp.search( `SELECT  asset_group.name,asset_group_listing_group_filter.case_value.product_type.level, asset_group.id,asset_group_listing_group_filter.case_value.product_item_id.value, campaign.advertising_channel_type, metrics.conversions, metrics.conversions_value, metrics.clicks,
  metrics.cost_micros, metrics.impressions,asset_group_listing_group_filter.parent_listing_group_filter, campaign.name  FROM asset_group_product_group_view
  WHERE  campaign.advertising_channel_type = PERFORMANCE_MAX AND segments.date>='${date_format(start)}' AND segments.date <='${date_format(end)}' `)
  // ORDER BY segments.day_of_week DESC, segments.hour ASC
  
  for (const row of searchResults) {
    //Logger.log(row)
    if (row.assetGroupListingGroupFilter.parentListingGroupFilter!=null) continue
   // if (row.assetGroupListingGroupFilter.caseValue&&row.assetGroupListingGroupFilter.caseValue.productItemId.value) pid=row.assetGroupListingGroupFilter.caseValue.productItemId.value; else pid=""
   // if (row.assetGroupListingGroupFilter.caseValue&&row.assetGroupListingGroupFilter.caseValue.productType) pid2=row.assetGroupListingGroupFilter.caseValue.productType.level; else pid2=""
    
    
    data.push([row.assetGroup.name,row.assetGroup.id,row.campaign.name,row.metrics.impressions,row.metrics.clicks,row.metrics.conversions,row.metrics.conversionsValue,(parseInt(row.metrics.costMicros)/1000000).toFixed(2)])
  }
  sh=ss.getSheetByName("Asset Group")
  if (sh.getMaxRows()>1) sh.getRange(2,1,sh.getMaxRows(),data[0].length).clear()
  sh.getRange(2,1,data.length, data[0].length).setValues(data);
  
}

function date_format(date){
return Utilities.formatDate(date, AdsApp.currentAccount().getTimeZone(), 'yyyy-MM-dd')
}
Show whole script!
Loading Comments
The Experts
Tibbe van Asten Team Lead Performance Marketing
Nils Rooijmans Water Cooler Topics
Martijn Kraan Freelance PPC Specialist
Bas Baudoin Teamlead SEA @ Happy Leads
Jermaya Leijen Digital Marketing Strategist
Krzysztof Bycina PPC Specialist from Poland
How about you? JOIN US!
Sharing Knowledge
Caring

Adsscripts.com is all about sharing knowledge. In the current market, PPC specialists like to keep their knowledge and experience to themselves. We're convinced that sharing knowledge can ensure that everyone gets better at their work. We want to change this by sharing our knowledge about scripts with everyone.

Do you also want to contribute? We are open to new ideas and feedback on everything you find on Adsscripts.com.

Contact us

Training &
Workshop
Contact us!
Adsscripts Training & Workshop