Appends last week's top search queries, clicks, impressions and average position to a Google Sheet every Monday.

UsesGoogle Sheets

Weekly search performance export to Sheets

ScheduleRun every Monday at 08:00.Run every Monday at 08:00.
ValuesSet searchDataUrl to blank.Set searchDataUrl to blank.
ValuesSet accessToken to blank.Set accessToken to blank.
ValuesSet spreadsheetUrl to blank.Set spreadsheetUrl to blank.
ValuesSet sheetTab to Search performance.Set sheetTab to Search performance.
ValuesSet maxQueries to 50.Set maxQueries to 50.
ListsGet the first item of today's date shifted by -3 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.
ListsGet the first item of today's date shifted by -9 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.
HTTPSend data to searchDataUrl and save it as report.Send data to searchDataUrl and save it as report.
ValuesSet queryRows to report.body.rows.Set queryRows to report.body.rows.
ValuesSet rowsFound to 0.Set rowsFound to 0.
Decisions & LoopsIf a step below fails, save the error as noRowsErrorIf a step below fails, save the error as noRowsError
Try
ListsCount the items in queryRows and save it as rowsFound.Count the items in queryRows and save it as rowsFound.
On error
ValuesShow in the output: The search analytics endpoint returned no rows for this week..Show in the output: The search analytics endpoint returned no rows for this week..
Decisions & LoopsIf rowsFound is 0If rowsFound is 0
Yes
Decisions & LoopsFinish the run: No search data between 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
ValuesSet tabIsNew to false.Set tabIsNew to false.
Decisions & LoopsIf a step below fails, save the error as tabErrorIf a step below fails, save the error as tabError
Try
Google SheetsGoogle SheetsCreate the tab sheetTab in spreadsheetUrl.Create the tab sheetTab in spreadsheetUrl.
ValuesChange tabIsNew to true.Change tabIsNew to true.
On error
ValuesShow in the output: Adding this week's rows to the existing '@sheetTab' tab.Show in the output: Adding this week's rows to the existing '@sheetTab' tab.
Decisions & LoopsIf tabIsNew is yesIf tabIsNew is yes
Yes
Google SheetsGoogle SheetsAdd a row to sheetTab in spreadsheetUrl.Add a row to sheetTab in spreadsheetUrl.
No
No steps
ValuesSet rowsAdded to 0.Set rowsAdded to 0.
Decisions & LoopsFor each searchRow in queryRows:For each searchRow in queryRows:
ValuesSet queryText to blank.Set queryText to blank.
Decisions & LoopsIf a step below fails, save the error as queryErrorIf a step below fails, save the error as queryError
Try
TextTrim the first item of searchRow.keys and save it as queryText.Trim the first item of searchRow.keys and save it as queryText.
On error
ValuesShow in the output: Skipped a search result that carried no query text..Show in the output: Skipped a search result that carried no query text..
Decisions & LoopsIf queryText isn't emptyIf queryText isn't empty
Yes
Google SheetsGoogle SheetsAdd a row to sheetTab in spreadsheetUrl.Add a row to sheetTab in spreadsheetUrl.
ValuesAdd 1 to rowsAdded.Add 1 to rowsAdded.
No
No steps
ValuesShow in the output: Added 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.