Skip to content

Instantly share code, notes, and snippets.

@derryl
Forked from emtoledo/gist:5389833
Created April 15, 2013 17:38
Show Gist options
  • Save derryl/5389841 to your computer and use it in GitHub Desktop.
Save derryl/5389841 to your computer and use it in GitHub Desktop.
// Establish Date ranges
var date_today = new Date.today().toString("yyyy-MM-dd");
var date_lastweek = new Date().last().week().toString("yyyy-MM-dd");
var date_twoweeks = new Date().last().week().addDays(-7).toString("yyyy-MM-dd")
// Execute this function when the 'Make API Call' button is clicked
function makeApiCall() {
// FP announce page views
var fpAnnounce = gapi.client.analytics.data.ga.get({
'ids': 'ga:36091392',
'start-date': date_lastweek,
'end-date': date_today,
'metrics': 'ga:pageviews',
'dimensions': 'ga:date',
'filters':'ga:pagePath==/flightpath/',
}).execute(handleResults1);
/// Email sign up events
var emailSignups = gapi.client.analytics.data.ga.get({
'ids': 'ga:36091392',
'start-date': date_lastweek,
'end-date': date_today,
'metrics': 'ga:totalEvents',
'dimensions': 'ga:date',
'filters':'ga:eventAction==Private Beta Sign Up'
}).execute(handleResults2);
// Unique vistors 'filters':'ga:pagePath==/flightpath/apps'
// Pivots (Audience) 'filters':'ga:pagePath==(\deviceInfo\S|\SosVersion\S|\SappVersion\S|\Scountry\S)'
// Pivots (Checkpoints) 'filters':'ga:pagePath==\StopName\S'
// Pivots (Crashes) 'filters':'ga:pagePath==\SnumCrashes\S'
}
// Return resuts
function handleResults1(results) {
if (results.error) {
console.log('There was an error querying core reporting API: ' + results.message);
} else {
console.log('Total Visits: ', results.totalsForAllResults['ga:pageviews']);
}
}
// Return resuts
function handleResults2(results) {
if (results.error) {
console.log('There was an error querying core reporting API: ' + results.message);
} else {
console.log('Total Events: ', results.totalsForAllResults['ga:totalEvents']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment