Skip to content

Instantly share code, notes, and snippets.

@ryanpraski
ryanpraski / google_analytics_api_app_script.js
Created Aug 9, 2018 — forked from dcvogi/top5pages.js
Queries the data for the top 5 pages of the website.
View google_analytics_api_app_script.js
function main(){
// Set up the parameters and variables
var sheetName = '<name>'; // The name of the sheet (not the Spreadsheet) we want to write the data e.g Sheet1
var tableId = '<table id>'; // The id of the view to query the data from e.g ga:123456
var startDate = 'yyyy-MM-dd'; // The start date of the query with the appropriate format e.g 2018-04-01 (1 April 2018)
var endDate = 'yyyy-MM-dd'; // The end date of the query with the appropriate format e.g 2018-04-30 (30 April 2018)
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName(sheetName);
@ryanpraski
ryanpraski / googleAnalyticsReporting.gs
Created Jul 30, 2017 — forked from chipoglesby/googleAnalyticsReporting.gs
Send your Google Analytics metrics and dimensions to Google Big Query using Google Apps Script.
View googleAnalyticsReporting.gs
//Replace xxx with your values as necessary.
function googleAnalyticsReporting() {
projectId = "xxx";
datasetId = "xxx";
tableId = 'xxx';
data = [];
yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday = Utilities.formatDate(yesterday, 'UTC', "yyyy-MM-dd");
@ryanpraski
ryanpraski / costdata.gs
Last active Jan 19, 2021 — forked from chipoglesby/costdata.gs
Cost Data Upload via Google Analytic's Management API with Google Sheets
View costdata.gs
function uploadData() {
var accountId = "xxxxxxxx";
var webPropertyId = "UA-xxxxxxxx-x";
var customDataSourceId = "xxxxxxxx";
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var maxRows = ss.getLastRow();
var maxColumns = ss.getLastColumn();
var data = [];
for (var i = 1; i <= maxRows; i++) {
data.push(ss.getRange([i], 1, 1, maxColumns).getValues());