Last active
May 13, 2020 11:14
-
-
Save derekmartinla/88ce6f0a67a40d523c2e to your computer and use it in GitHub Desktop.
Track Adwords Gclid Ids
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var GOOGLE_DOC_URL = "URL"; | |
function main() { | |
clicks = runCampaignReport(); | |
modifySpreadSheet(clicks); | |
} | |
function runCampaignReport() { | |
var listOfClicks = []; | |
var report = AdWordsApp.report( | |
'SELECT Date, GclId, ClickType, Page, Slot, AdFormat, CityCriteriaId, RegionCriteriaId, CountryCriteriaId, CriteriaParameters ' + | |
'FROM CLICK_PERFORMANCE_REPORT ' + | |
'DURING YESTERDAY'); | |
var rows = report.rows(); | |
while (rows.hasNext()) { | |
var row = rows.next(); | |
var date = row['Date']; | |
var gclid = row['GclId']; | |
var clickType = row['ClickType']; | |
var page = row['Page']; | |
var slot = row['Slot']; | |
var criteria = row['CriteriaParameters']; | |
var adFormat = row['AdFormat']; | |
var city = row['CityCriteriaId']; | |
var state = row['RegionCriteriaId']; | |
var country = row['CountryCriteriaId']; | |
var userList = row['UserListId'] | |
var clickResult = new clickData(date, gclid, clickType, page, slot, criteria, adFormat, city, state, country, userList); | |
listOfClicks.push(clickResult); | |
} // end of report run | |
return listOfClicks; | |
} | |
function clickData(date, gclid, clickType, page, slot, criteria, adFormat, city, state, country, userList) { | |
this.date = date; | |
this.gclid = gclid; | |
this.clickType = clickType; | |
this.page = page; | |
this.slot = slot; | |
this.criteria = criteria; | |
this.adFormat = adFormat; | |
this.city = city; | |
this.state = state; | |
this.country = country; | |
this.userList = userList; | |
} | |
function modifySpreadSheet(results) { | |
var gclidResults = results; | |
var gclidSS = SpreadsheetApp.openByUrl(GOOGLE_DOC_URL); | |
var sheet = gclidSS.getActiveSheet(); | |
var columnNames = ["Date", "Gclid", "Criteria", "ClickType", "Page", "Slot", "AdFormat","City", "State", "Country","UserList"]; | |
var headersRange = sheet.getRange(1, 1, 1, columnNames.length); | |
for (i = 0; i < gclidResults.length; i++) { | |
headersRange.setValues([columnNames]); | |
var date = gclidResults[i].date; | |
var gclid = gclidResults[i].gclid; | |
var criteria = " " + gclidResults[i].criteria; | |
var clickType = gclidResults[i].clickType; | |
var page = gclidResults[i].page; | |
var slot = gclidResults[i].slot; | |
var adFormat = gclidResults[i].adFormat; | |
var city = gclidResults[i].city; | |
var state = gclidResults[i].state; | |
var country = gclidResults[i].country; | |
sheet.appendRow([date, gclid, criteria, clickType, page, slot, adFormat, city, state, country]); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
I can't get CitycriteriaID and RegioncriteriaID in this Performance report. Any idea why?