Fixes per @boaz

- Moved the Google Analytics tracking code to config.js
- Changed the config.js to use an absolute url for the settings
  dependency since analytics.js needs to reuse the config (only an issue in Sense )
- Moved analytics to the common directory
- Refactored analytics to return an object with a track function for
  fine grain tracking and a pageview for sending the page view
- Added checks around the pageview code to only trigger a pageview()
  when the user has implictly set their optin/optout status (checking
  marvelOpts.version is set)
- Added ga.pageview() to setOptIn() to fire if the user opts in
This commit is contained in:
Chris Cowan 2014-03-06 09:10:52 -07:00
parent eab65d8008
commit a3630075ac
8 changed files with 40 additions and 23 deletions

View file

@ -14,6 +14,10 @@ module.exports = function (grunt) {
dev: '":'+ (grunt.option('es_port') || 9200) +'"',
dist: "(window.location.port !== '' ? ':'+window.location.port : '')"
},
ga_tracking_code: {
dev: '"UA-12395217-6"',
dist: '"UA-12395217-5"'
},
statsReportUrl: {
dev: '"http://" + window.location.hostname + ":'+ (grunt.option('es_port') || 9200) +'/.marvel_cluster_report/report"',
dist: '"https://marvel-stats.elasticsearch.com/"'

View file

@ -1,5 +1,7 @@
define(function (require) {
'use strict';
var config = require('/kibana/config.js');
window.GoogleAnalyticsObject = 'ga';
// create an initali ga function. queue commands so it's executed
@ -19,8 +21,17 @@ define(function (require) {
firstScript.parentNode.insertBefore(asyncTag, firstScript);
// return the ga function
window.ga('create', 'UA-71701-3', 'auto');
return function () {
window.ga.apply(null, Array.prototype.slice.call(arguments));
};
window.ga('create', config.ga_tracking_code, 'auto');
return {
track: function () {
window.ga.apply(null, Array.prototype.slice.call(arguments));
},
pageview: function () {
window.ga('send', 'pageview', {
cookieDomain: window.location.hostname,
page: window.location.pathname+window.location.hash,
location: window.location.href
});
}
}
});

View file

@ -3,7 +3,7 @@
* config.js is where you will find the core Kibana configuration. This file contains parameter that
* must be set before kibana is run for the first time.
*/
define(['settings'],
define(['/kibana/app/components/settings.js'],
function (Settings) {
"use strict";
@ -68,6 +68,7 @@ define(['settings'],
]
});
s.stats_report_url = @@stats_report_url;
s.ga_tracking_code = @@ga_tracking_code;
return s;
});

View file

@ -14,9 +14,10 @@ define([
'app',
'kbn',
'lodash',
'/common/analytics.js',
'factories/store'
],
function (angular, app, kbn, _) {
function (angular, app, kbn, _, ga) {
'use strict';
var module = angular.module('kibana.panels.marvel.cluster', []);
@ -137,7 +138,7 @@ function (angular, app, kbn, _) {
$scope.setOptIn = function(val) {
marvelOpts.version = kbnVersion;
marvelOpts.report = val;
$scope.report = val;
if (val) ga.pageview();
};
$scope.clearMarvelStorage = function() {
@ -176,7 +177,7 @@ function (angular, app, kbn, _) {
return false;
}
};
var sendReport = function(data) {
if (!$scope.config.stats_report_url) {
return;

View file

@ -16,7 +16,7 @@ define([
'app',
'jquery',
'lodash',
'./analytics',
'/common/analytics.js',
'factories/store'
],
function (angular, app, $, _, ga) {
@ -73,12 +73,8 @@ function (angular, app, $, _, ga) {
$scope.links = $scope.panel.links;
}
if (marvelOpts.report) {
ga('send', 'pageview', {
cookieDomain: window.location.hostname,
page: window.location.pathname+window.location.hash,
location: window.location.href
});
if (marvelOpts.version && marvelOpts.report) {
ga.pageview();
}
if($scope.panel.source === 'url') {

View file

@ -24,13 +24,8 @@ define([
if (marvelOpts) {
try {
marvelOpts = JSON.parse(marvelOpts);
if (marvelOpts.report) {
var options = {
cookieDomain: window.location.hostname,
page: window.location.pathname+window.location.hash,
location: window.location.href
};
ga('send', 'pageview', options);
if (marvelOpts.version && marvelOpts.report) {
ga.pageview();
}
} catch (e) { } // Meh! Who cares...
}

View file

@ -17,7 +17,8 @@
'ace_mode_json': '../vendor/ace/mode-json',
'ace_ext_language_tools': '../vendor/ace/ext-language_tools',
'ace_ext_searchbox': '../vendor/ace/ext-searchbox',
'analytics': '../../kibana/app/panels/marvel/navigation/analytics'
'analytics': '/common/analytics',
'lodash': '/kibana/vendor/lodash'
},
map: {
'*': {

View file

@ -11,6 +11,10 @@ module.exports = function (config) {
{
match: 'stats_report_url',
replacement: '<%= statsReportUrl.dev %>',
},
{
match: 'ga_tracking_code',
replacement: '<%= ga_tracking_code.dev %>',
}
]
},
@ -28,6 +32,10 @@ module.exports = function (config) {
{
match: 'stats_report_url',
replacement: '<%= statsReportUrl.dist %>',
},
{
match: 'ga_tracking_code',
replacement: '<%= ga_tracking_code.dist %>',
}
]
},