Appends last week's top search queries, clicks, impressions and average position to a Google Sheet every Monday.
Uses
Google Sheets
Weekly search performance export to Sheets
searchDataUrl to blank.Set searchDataUrl to blank.accessToken to blank.Set accessToken to blank.spreadsheetUrl to blank.Set spreadsheetUrl to blank.sheetTab to Search performance.Set sheetTab to Search performance.maxQueries to 50.Set maxQueries to 50.days split by T and save it as weekEnd.Get the first item of today's date shifted by -3 days split by T and save it as weekEnd.days split by T and save it as weekStart.Get the first item of today's date shifted by -9 days split by T and save it as weekStart.searchDataUrl and save it as report.Send data to searchDataUrl and save it as report.queryRows to report.body.rows.Set queryRows to report.body.rows.rowsFound to 0.Set rowsFound to 0.noRowsErrorIf a step below fails, save the error as noRowsErrorTry
queryRows and save it as rowsFound.Count the items in queryRows and save it as rowsFound.On error
The search analytics endpoint returned no rows for this week..Show in the output: The search analytics endpoint returned no rows for this week..rowsFound is 0If rowsFound is 0Yes
weekStart and weekEnd. Nothing was added to the sheet.Finish the run: No search data between weekStart and weekEnd. Nothing was added to the sheet.No
No steps
tabIsNew to false.Set tabIsNew to false.tabErrorIf a step below fails, save the error as tabErrorTry
sheetTab in spreadsheetUrl.Create the tab sheetTab in spreadsheetUrl.tabIsNew to true.Change tabIsNew to true.On error
tabIsNew is yesIf tabIsNew is yesYes
sheetTab in spreadsheetUrl.Add a row to sheetTab in spreadsheetUrl.No
No steps
rowsAdded to 0.Set rowsAdded to 0.searchRow in queryRows:For each searchRow in queryRows:queryText to blank.Set queryText to blank.queryErrorIf a step below fails, save the error as queryErrorTry
searchRow.keys and save it as queryText.Trim the first item of searchRow.keys and save it as queryText.On error
Skipped a search result that carried no query text..Show in the output: Skipped a search result that carried no query text..queryText isn't emptyIf queryText isn't emptyYes
sheetTab in spreadsheetUrl.Add a row to sheetTab in spreadsheetUrl.rowsAdded.Add 1 to rowsAdded.No
No steps
rowsAdded query rows for weekStart to weekEnd to the '@sheetTab' tab.Show in the output: Added rowsAdded query rows for weekStart to weekEnd to the '@sheetTab' tab.