Skip to content

Instantly share code, notes, and snippets.

@Vijaysinh
Created November 20, 2019 11:25
Show Gist options
  • Save Vijaysinh/5ff44211011cd02627fc0d486f30ae33 to your computer and use it in GitHub Desktop.
Save Vijaysinh/5ff44211011cd02627fc0d486f30ae33 to your computer and use it in GitHub Desktop.
GoogleAdsMCCScript for Labels
function main() {
// You can use this approach when you have only minimal processing to
// perform in each of your client accounts.
// Select the accounts to be processed.
var accountIterator = MccApp.accounts().get();
var arrayList=[];
// Save the MCC account, to switch back later.
var mccAccount = AdWordsApp.currentAccount();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
// Switch to the account you want to process.
MccApp.select(account);
Logger.log(account.getCustomerId());
var adGroupIterator = AdWordsApp.adGroups().get();
Logger.log('Total adGroups found : ' + adGroupIterator.totalNumEntities());
while (adGroupIterator.hasNext()) {
var adGroup = adGroupIterator.next();
var stats = adGroup.getStatsFor('LAST_WEEK');
var costs = stats.getCost();
if (costs !== 0){
var adgroupObject1 = new AdGroupID(adGroup.getId(), costs);
arrayList.push(adgroupObject1);
}
}
}
var options = {
'method' : 'post',
'contentType': 'application/json',
// Convert the JavaScript object to a JSON string.
'payload' : JSON.stringify(arrayList)
};
var response = UrlFetchApp.fetch('https://calloverview.com/api/add_adwords_costs.php?apikey=*************', options);
//Logger.log(response);
Logger.log("Einde");
}
function AdGroupID(id, kosten) {
this.ID = id;
this.Cost = kosten;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment