Autmatically Import Google Analytics Data into Apps Script Product 'Docs, Sites, Spreadsheets'

To help automating Google Analytics reporting, with an ability to manipulate Analytics data, create new visualizations, and build internal dashboards -- Google today integrated Analytics data into any Apps Script supported product, such as Google Docs, Sites, or Spreadsheets.Here's an example of Google Analytics data accessed through Apps Script and displayed in a Google Spreadsheet.Custom […]

To help automating Google Analytics reporting, with an ability to manipulate Analytics data, create new visualizations, and build internal dashboards -- Google today integrated Analytics data into any Apps Script supported product, such as Google Docs, Sites, or Spreadsheets.

Here's an example of Google Analytics data accessed through Apps Script and displayed in a Google Spreadsheet.

Custom API Dashboards - (No Code Required)
To help easily create dashboards that automatically update -- Google added a script called "Google Analytics Report Automation (Magic)," to the Spreadsheets script gallery that handles all this work.

You can find this script by opening or creating a Google Spreadsheet, clicking Tools -> Script Gallery and searching for "analytics magic".

Also, with the new Analytics - Apps Script integration, it is now possible to request the total visitors, visits, and pageviews over time and put this data into a spreadsheet with just the code (under this post).

Google Analytics integrates with Google Apps Script

Finally, to those first 15 developers who build a solution using both APIs -- Google is offering Google Analytics developer t-shirts.

"To be eligible, you must publish your solution to either the Chrome Web Store or the Spreadsheets Script Gallery and include a description of a business problem the script solves," Google stated.

To get started now, read Automated Access to Google Analytics Data in Google Spreadsheets tutorial. Also check out the Google Analytics Apps Script reference docs.

Below is a video demoing how to build a dashboard using this script:

// Get Data.
var results = Analytics.Data.Ga.get(
    tableId,
    startDate,
    endDate,
    'ga:visitors,ga:visits,ga:pageviews',
    {‘dimensions’: ‘ga:date’});

// Output to spreadsheet.
var sheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet();
sheet.getRange(2, 1, results.getRows().length, headerNames.length)
    .setValues(results.getRows());

// Make Sandwich.