Skip to content

Commit

Permalink
Applying changes for Yotta statistics messages, see phetsims/yotta#30
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Dec 6, 2016
1 parent 83ea84c commit e77d235
Showing 1 changed file with 62 additions and 17 deletions.
79 changes: 62 additions & 17 deletions js/analytics/google-analytics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2015, University of Colorado Boulder
// Copyright 2002-2013, University of Colorado Boulder

/**
* Google analytics collection for HTML5 sims.
Expand Down Expand Up @@ -26,6 +26,63 @@
return;
}

var loadType;
if ( phet.chipper.getQueryParameter( 'phet-app' ) ) {
loadType = 'phet-app';
}
else if ( top !== self ) {
// Checks to see if this sim is embedded - phetsims/chipper#50
loadType = 'embedded';
}
// TODO Add additional conditions for tracking hits from the installer, etc.
else {
loadType = 'default';
}

// {boolean} - Whether an error was detected with anything relating to google analytics.
// See https://github.com/phetsims/yotta/issues/30
var googleAnalyticsErrored = false;
window.addEventListener( 'error', function( event ) {
if ( event &&
event.target &&
event.target.src &&
event.target.src.indexOf &&
event.target.src.indexOf( 'google-analytics' ) >= 0 ) {
googleAnalyticsErrored = true;
}
}, true );

// {boolean} - Whether analytics.js successfully loaded, see https://github.com/phetsims/yotta/issues/30
var googleAnalyticsLoaded = false;
function onGoogleAnalyticsLoad() {
googleAnalyticsLoaded = true;
}

var pingParams = 'pingver=2&' +
'project=' + encodeURIComponent( phet.chipper.project ) + '&' +
'version=' + encodeURIComponent( phet.chipper.version ) + '&' +
'locale=' + encodeURIComponent( phet.chipper.locale ) + '&' +
'buildTimestamp=' + encodeURIComponent( phet.chipper.buildTimestamp ) + '&' +
'domain=' + encodeURIComponent( document.domain ) + '&' +
'href=' + encodeURIComponent( window.location.href ) + '&' +
'type=html&' +
'timestamp=' + encodeURIComponent( Date.now() ) + '&' +
'loadType=' + encodeURIComponent( loadType ) + '&' +
'ref=' + encodeURIComponent( document.referrer );

function pingURL( url ) {
var img = document.createElement( 'img' );
img.src = url;
}

pingURL( 'https://phet.colorado.edu/yotta/immediate.gif?' + pingParams );

window.addEventListener( 'load', function( event ) {
pingURL( 'https://phet.colorado.edu/yotta/sanity.gif?' + pingParams + '&' +
'gaError=' + encodeURIComponent( googleAnalyticsErrored ) + '&' +
'gaLoaded=' + encodeURIComponent( googleAnalyticsLoaded ) );
}, false );

// Google Analytics snippet for loading the API
(function( i, s, o, g, r, a, m ) {
i.GoogleAnalyticsObject = r;
Expand Down Expand Up @@ -57,27 +114,15 @@
if ( phet.chipper.buildTimestamp ) {
phetPageviewOptions.dimension4 = phet.chipper.buildTimestamp; // simBuildTimestamp custom dimension
}
if ( phet.chipper.getQueryParameter( 'phet-app' ) ) {
phetPageviewOptions.dimension5 = 'phet-app';
}
else if ( phet.chipper.getQueryParameter( 'chrome-webstore' ) ) {
phetPageviewOptions.dimension5 = 'chrome-webstore';
}
else if ( top !== self ) {
// Checks to see if this sim is embedded - phetsims/chipper#50
phetPageviewOptions.dimension5 = 'embedded';
}
// TODO Add additional conditions for tracking hits from the installer, etc.
else {
phetPageviewOptions.dimension5 = 'default';
}

phetPageviewOptions.dimension5 = loadType;
phetPageviewOptions.dimension6 = document.referrer;
}

var offlineSimLocation = 'offline/html/' + phet.chipper.project + '_' + phet.chipper.locale;


// Put our function in the queue, to be invoked when the analytics.js has fully loaded.
// See https://github.com/phetsims/yotta/issues/30
window.googleAnalytics( onGoogleAnalyticsLoad );

// Main PhET tracker
window.googleAnalytics( 'create', {
Expand Down

0 comments on commit e77d235

Please sign in to comment.