Skip to content

Instantly share code, notes, and snippets.

@dcvogi
dcvogi / top5pages.js
Last active July 7, 2022 06:40
Queries the data for the top 5 pages of the website.
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);
@AlienDeg
AlienDeg / sightseeing.R
Last active October 18, 2017 18:37
sightseeing optimization for people who like to walk
library(ggmap)
library(gtools)
library(dplyr)
library(ggplot2)
library(ggrepel)
what_to_see <- c('prague bus station',
"Pivo a parek, prague",
"Bar Na Palme, prague",
"Pivovar Hostivar,pragie",
"Pivni rozmanitost, prague",
@chipoglesby
chipoglesby / googleAnalyticsReporting.gs
Created June 2, 2016 15:40
Send your Google Analytics metrics and dimensions to Google Big Query using Google Apps Script.
//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");
@mhawksey
mhawksey / gist:9199459
Last active February 16, 2022 11:13
Google Apps Script snippet to send tracking data to Google Analytics using the Measurement Protocol
function onOpen(){
// example send for Sheets
sendGAMP("UA-XXXX-1", SpreadsheetApp.getActiveSpreadsheet().getUrl());
// example send for Documents
//sendGAMP("UA-XXXX-1", DocumentApp.getActiveDocument().getUrl());
// example send for Forms *NOTE* getUrl not implemented yet in New Sheets
//sendGAMP("UA-XXXX-1", FormApp.getActiveForm().getUrl());
}