pmax search term report scrip

79 views
Skip to first unread message

Luca Tinnirello

unread,
Mar 14, 2024, 9:40:56 AM3/14/24
to Google Ads Scripts Forum
Hi,

I am using the following script for exporting search terms in google sheets

// Copyright 2023 // Free to use or alter for everyone. A mention would be nice ;-) // // Idea By: Mike Rhodes // Put on steroids by: Tibbe van Asten // // Created: 15-08-2023 // Last update: 18-08-2023: fixed a little mistake in the query, that prevents you from collecting more than 30 days data // // ABOUT THE SCRIPT // Export search term from Pmax campaigns to a spreadsheet. // //////////////////////////////////////////////////////////////////// var config = { LOG : false, // Change the number of days of which data must be exported. Only change the number! DATE_RANGE: last_n_days(30), // Edit the URL of an empty Google Sheet in here, with '/edit' at the end SPREADSHEET_URL : "" } //////////////////////////////////////////////////////////////////// function main() { var spreadsheet = SpreadsheetApp.openByUrl(config.SPREADSHEET_URL); let campaignIterator = AdsApp .performanceMaxCampaigns() .withCondition("campaign.status = ENABLED") .get(); while(campaignIterator.hasNext()){ let campaign = campaignIterator.next(); let query = AdsApp.report( "SELECT campaign_search_term_insight.category_label, metrics.clicks, metrics.impressions, metrics.conversions, metrics.conversions_value " + "FROM campaign_search_term_insight " + "WHERE campaign_search_term_insight.campaign_id = '" + campaign.getId() + "' " + "AND segments.date BETWEEN '" + config.DATE_RANGE.split(',')[0] + "' AND '" + config.DATE_RANGE.split(',')[1] + "' " + "ORDER BY metrics.impressions DESC" ); if(config.LOG === true){ Logger.log("Report " + campaign.getName() + " contains " + query.rows().totalNumEntities() + " rows."); } let sheet = checkTab(spreadsheet, campaign.getName()); query.exportToSheet(sheet); } // campaignIterator } //////////////////////////////////////////////////////////////////// function checkTab(file, tabName){ if(SpreadsheetApp.openById(file.getId()).getSheetByName(tabName)){ var tab = SpreadsheetApp.openById(file.getId()).getSheetByName(tabName); if(config.LOG === true){ Logger.log("Selected tab " + tabName); } } else { var tab = SpreadsheetApp.openById(file.getId()).insertSheet(tabName); if(config.LOG === true){ Logger.log("Created tab " + tabName); } } // Remove default tab in Dutch if(SpreadsheetApp.openById(file.getId()).getSheetByName("Blad1")){ var defaultSheet = SpreadsheetApp.openById(file.getId()).getSheetByName("Blad1") SpreadsheetApp.openById(file.getId()).deleteSheet(defaultSheet); } // Remove default tab in English if(SpreadsheetApp.openById(file.getId()).getSheetByName("Sheet1")){ var defaultSheet = SpreadsheetApp.openById(file.getId()).getSheetByName("Sheet1") SpreadsheetApp.openById(file.getId()).deleteSheet(defaultSheet); } return tab; } // function checkTab //////////////////////////////////////////////////////////////////// function last_n_days(n) { var from = new Date(), to = new Date(); to.setUTCDate(from.getUTCDate() - n); from.setUTCDate(from.getUTCDate() - 1); return google_date_range(from, to); } // function last_n_days() //////////////////////////////////////////////////////////////////// function google_date_range(from, to) { function google_format(date) { var date_array = [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()]; if (date_array[1] < 10) date_array[1] = '0' + date_array[1]; if (date_array[2] < 10) date_array[2] = '0' + date_array[2]; return date_array.join(''); } var inverse = (from > to); from = google_format(from); to = google_format(to); var result = [from, to]; if (inverse) { result = [to, from]; } return result.join(','); } // function google_date_range()
I would like to know if there is the chance to obtain the report in only one sheet and with the campaign added as a column

thanks,
Luca

Google Ads Scripts Forum Advisor

unread,
Mar 14, 2024, 1:34:31 PM3/14/24
to adwords...@googlegroups.com
Hi,

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

After reviewing your query, I understand that you want to know if there is the chance to obtain the report in only one sheet and with the campaign added as a column. I would suggest you refer to the documents Performance Max campaigns, Reporting and SpreadsheetApp to get more information on fetching data to a spreadsheet.

I hope this helps. Kindly get back to us if you have any further queries.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02rzx5N:ref" (ADR-00227286)

Thanks,
 
Google Logo Google Ads Scripts Team


Katarina Tutavac

unread,
Mar 15, 2024, 7:08:53 AM3/15/24
to Google Ads Scripts Forum on behalf of adsscripts

Unsubscribe please.

 

Liebe Grüße

 

Katarina

 

cid:image001.png@01D277FD.F1FF0920

Online Sales – Stellvertretende Teamleitung SEA&PSM
t: -410

m: +49 1514 222 6270

Das Bild wurde vom Absender entfernt. Google Logo

Google Ads Scripts Team

Das Bild wurde vom Absender entfernt.

--
-- 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 the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/QJiMq000000000000000000000000000000000000000000000SACM50000woDSF5JQxikCfmsQKrkMA%40sfdc.net.

Google Ads Scripts Forum Advisor

unread,
Mar 15, 2024, 12:28:16 PM3/15/24
to adwords...@googlegroups.com
Hi Katarina,


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

As per your request, we have unsubscribed you from the Google Ads Scripts Forum. You will not receive any emails going forward.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02rzx5N:ref" (ADR-00227286)

Thanks,
 
Google Logo Google Ads Scripts Team


Reply all
Reply to author
Forward
0 new messages