-
-
Save kaugesaar/1ba9f98dabe973c857ad to your computer and use it in GitHub Desktop.
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 key = ""; // Fyll i dessa själv :) | |
var secret = ""; | |
var pushco = new PushCo(key,secret); | |
function main() { | |
// Let's consider the 20 keywords that got the most impressions yesterday. | |
var keywordsIterator = AdWordsApp.keywords() | |
.orderBy("Impressions DESC") | |
.forDateRange("YESTERDAY") | |
.withLimit(20) | |
.get(); | |
var now = new Date(); | |
var reportName = "DailyReport-" + Utilities.formatDate(now, "PST", "yyyyMMdd"); | |
// Create a new spreadsheet (will have private access for you only). | |
var spreadsheet = SpreadsheetApp.create(reportName); | |
// Get the default sheet. | |
var sheet = spreadsheet.getActiveSheet(); | |
// Write header row. | |
sheet.getRange("A1").setValue("Keyword"); | |
sheet.getRange("B1").setValue("Bid"); | |
sheet.getRange("C1").setValue("Impressions"); | |
sheet.getRange("D1").setValue("Cost"); | |
// Write body of report. | |
for (var row = 2; keywordsIterator.hasNext(); row ++) { | |
var keyword = keywordsIterator.next(); | |
var stats = keyword.getStatsFor("YESTERDAY"); | |
sheet.getRange("A" + row).setValue(keyword.getText()); | |
sheet.getRange("B" + row).setValue(keyword.getMaxCpc()); | |
sheet.getRange("C" + row).setValue(stats.getImpressions()); | |
sheet.getRange("D" + row).setValue(stats.getCost()); | |
} | |
pushco.sendPushUrl("Rapporten " + reportName + " är klar!","https://docs.google.com/spreadsheet/ccc?key=" + spreadsheet.getId()); | |
//pushco.sendPushMessage("Rapporten " + reportName + " är klar! Kolla Google Drive."); | |
Logger.log("Report ready! Visit the following URL to see it:"); | |
Logger.log("https://docs.google.com/spreadsheet/ccc?key=" + spreadsheet.getId()); | |
} | |
/* | |
* | |
* Very basic Client Lib for Push.co | |
* Send Push notifications to your iPhone from AdWords Scripts | |
* | |
* Version 1.0 | |
*/ | |
function PushCo(apiKey, apiSecret) { | |
this.API_KEY = apiKey; | |
this.API_SECRET = apiSecret; | |
this.API_URL= 'https://api.push.co/1.0/push'; | |
this.sendPushMessage = function(message) { | |
var headers = { | |
'method' : 'POST', | |
'payload': { | |
'message' : message, | |
'api_key' : this.API_KEY, | |
'api_secret' : this.API_SECRET, | |
}, | |
}; | |
http_post(this.API_URL,headers); | |
} | |
this.sendPushUrl = function(message,url) { | |
var headers = { | |
'method' : 'POST', | |
'payload' : { | |
'message' : message, | |
'url' : url, | |
'view_type' : 1, | |
'api_key' : this.API_KEY, | |
'api_secret' : this.API_SECRET, | |
}, | |
}; | |
http_post(this.API_URL,headers); | |
} | |
function http_post(url,headers) { | |
var response = UrlFetchApp.fetch(url,headers).getContentText(); | |
return JSON.parse(response)['message']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment