Ensuring the cluster report and analytics.js doesnt get sent or load before they make their decission

This commit is contained in:
Chris Cowan 2014-03-07 13:16:46 -07:00
parent a3630075ac
commit ec1e404d2c
2 changed files with 13 additions and 6 deletions

View file

@ -1,6 +1,7 @@
define(function (require) {
'use strict';
var config = require('/kibana/config.js');
var loaded = false;
window.GoogleAnalyticsObject = 'ga';
@ -14,19 +15,25 @@ define(function (require) {
window.ga.l = 1 * new Date();
// create the async tag and inject it into the page.
var asyncTag = document.createElement('script');
var firstScript = document.getElementsByTagName('script')[0];
asyncTag.async = 1;
asyncTag.src = '//www.google-analytics.com/analytics.js';
firstScript.parentNode.insertBefore(asyncTag, firstScript);
function load () {
if (loaded) return;
var asyncTag = document.createElement('script');
var firstScript = document.getElementsByTagName('script')[0];
asyncTag.async = 1;
asyncTag.src = '//www.google-analytics.com/analytics.js';
firstScript.parentNode.insertBefore(asyncTag, firstScript);
loaded = true;
}
// return the ga function
window.ga('create', config.ga_tracking_code, 'auto');
return {
track: function () {
load();
window.ga.apply(null, Array.prototype.slice.call(arguments));
},
pageview: function () {
load();
window.ga('send', 'pageview', {
cookieDomain: window.location.hostname,
page: window.location.pathname+window.location.hash,

View file

@ -165,7 +165,7 @@ function (angular, app, kbn, _, ga) {
// Checks if we should send a report
var checkReport = function() {
if(marvelOpts.report) {
if(marvelOpts.version && marvelOpts.report) {
if(marvelOpts.lastReport == null) {
return true;
} else if (new Date().getTime() - parseInt(marvelOpts.lastReport,10) > reportInterval) {