Skip to content

Commit

Permalink
add google analytics timing for app load
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed Mar 12, 2018
1 parent 2ba081a commit 805e20b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
waitSeconds: 30
};

// Progress Bar
(function () {
var progressBar = document.getElementById('app_loading_progress');
var message = document.getElementById('app_loading_message');
Expand All @@ -78,6 +79,7 @@
window.__setAppLoadingProgress(5, 'Downloading Assets');
window.__PAGE_LOAD_TIMESTAMP = new Date();

// Show a reload button if the page is taking too long
setTimeout(function check () {
if (progressValue !== 100) {
var msg = 'Loading the application is taking a long time... ';
Expand Down
28 changes: 17 additions & 11 deletions src/js/apps/discovery/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ define(['config', 'module'], function(config, module) {
'js/components/application',
'js/mixins/discovery_bootstrap',
'js/mixins/api_access',
'analytics',
'es5-shim'
],
function(Router,
Application,
DiscoveryBootstrap,
ApiAccess
) {
], function(Router, Application, DiscoveryBootstrap, ApiAccess, analytics) {

var updateProgress = (typeof window.__setAppLoadingProgress === 'function') ?
window.__setAppLoadingProgress : function () {};
Expand Down Expand Up @@ -54,7 +50,6 @@ define(['config', 'module'], function(config, module) {
var pubsub = app.getService('PubSub');
pubsub.publish(pubsub.getCurrentPubSubKey(), pubsub.APP_LOADED);


// set some important urls, parameters before doing anything
app.configure();

Expand Down Expand Up @@ -90,6 +85,21 @@ define(['config', 'module'], function(config, module) {
window.bbb = app;
}

// app is loaded, send timing event

if (__PAGE_LOAD_TIMESTAMP) {
var time = new Date() - __PAGE_LOAD_TIMESTAMP;
analytics('send', {
hitType: 'timing',
timingCategory: 'Application',
timingVar: 'Loaded',
timingValue: time
});
if (debug) {
console.log('Application Started: ' + time + 'ms');
}

}
}).fail(function () {
app.redirect('500.html');
});
Expand All @@ -104,8 +114,4 @@ define(['config', 'module'], function(config, module) {
});

});




});

0 comments on commit 805e20b

Please sign in to comment.