Export data to a specific sheet in Google Docs

1,757 views
Skip to first unread message

Charl Fourie

unread,
Jan 29, 2013, 8:17:28 AM1/29/13
to adwords...@googlegroups.com
Hi there everyone,

I've only started using Scripts in Adwords the last 24h and I am seeing some great potential in it and how I manage my workflow.

Currently I compile weekly reports with data I manually from CSV files. Can I set up a script to collect data on a weekly basis and update a specific file in Google Docs? But not only that but have scripts from different accounts export data to specific sheets in a file?

Thanks in advance,
Charl

Ernő Horváth

unread,
Jan 29, 2013, 8:25:59 AM1/29/13
to adwords...@googlegroups.com
Hi Charl,

As far as I know every script runs in an account environment. So you can't run _one_ script which gathers all data from your accounts you manage.
However you can copy-paste _one_ script to all accounts you have and run them in different time frames and let them rights to manage the same Google Docs, eg different sheets.

Here is an example how you can handle a Google Spreadsheet, if you name the different sheets to 'company 1', 'company 2' you can gather all reports to one Google Spreadsheet.

Regards,
Erno Horvath

Charl Fourie

unread,
Jan 29, 2013, 9:15:30 AM1/29/13
to adwords...@googlegroups.com
Thanks for that Erno.

Just trying to get the basics done first.

How would I write the following script to an existing Spreadsheet in Google Docs?

function main() {
  // Get all campaigns data for the last week.
  var campaignsIterator = AdWordsApp.campaigns()
      .forDateRange("LAST_WEEK")
      .get();
  while (campaignsIterator.hasNext()) {
    var campaign = campaignsIterator.next();
    var stats = campaign.getStatsFor("LAST_WEEK");
    Logger.log("Last month, campaign " + campaign.getName() +
        " cost " + stats.getCost() +
        " and received " + stats.getClicks() + " clicks");
  }
}

Kevin Winter (AdWords Scripts Team)

unread,
Jan 30, 2013, 10:19:03 AM1/30/13
to adwords...@googlegroups.com
Hi Charl,
  This tutorial has a script that opens a specific spreadsheet (by url) and makes a copy of it: https://developers.google.com/adwords/scripts/docs/tutorials/keyword-performance-report

If you drop the copy portion, you can write directly to the same spreadsheet every execution.  This snippet in particular writes the data to the spreadsheet:

  // Output data to spreadsheet
  var rows = [];
  for (var key in qualityScoreMap) {
    var ctr = 0;
    var cost = 0.0;
    if (qualityScoreMap[key].numKeywords > 0) {
      ctr = (qualityScoreMap[key].totalClicks /
        qualityScoreMap[key].totalImpressions) * 100;
    }
    var row = [
      key,
      qualityScoreMap[key].numKeywords,
      qualityScoreMap[key].totalImpressions,
      qualityScoreMap[key].totalClicks,
      ctr.toFixed(2),
      qualityScoreMap[key].totalCost];
    rows.push(row);
  }
  sheet.getRange(2, 1, rows.length, 6).setValues(rows);

- Kevin Winter
AdWords Scripts Team

Mathies Overtoom

unread,
Oct 15, 2014, 8:43:58 AM10/15/14
to adwords...@googlegroups.com
Hi Erno, 

I came across your message while searching for snippets/examples for doing exactly as you describe below (!). However I cannot find any examples, as you mention in your message.. I was hoping you could still provide me with such an example!

Many thanks in advance!

Regards, 
Mathies


Op dinsdag 29 januari 2013 14:25:59 UTC+1 schreef Ernő Horváth:

Anash Oommen

unread,
Oct 16, 2014, 8:21:32 AM10/16/14
to adwords...@googlegroups.com
Hi Mathies,

You can find code examples and snippets on our documentation site.


If you have specific questions, feel free to open a new thread and I'll answer your questions.

Cheers,
Anash P. Oommen,
AdWords Scripts Team.
Reply all
Reply to author
Forward
0 new messages