diff --git a/jstests/tests/test_analytics.js b/jstests/tests/test_analytics.js
index d1614cd26..3d44b9fd3 100644
--- a/jstests/tests/test_analytics.js
+++ b/jstests/tests/test_analytics.js
@@ -1,17 +1,29 @@
define(function(require) {
"use strict";
- var analytics = require("analytics");
+ var gamodule = require("gamodule");
QUnit.module("Google Analytics");
QUnit.test("test without analytics", function (assert) {
+ var result=[];
+ window.ga = function(cmd, id, auto) {
+ result[0] = [cmd, id, auto];
+ };
window.apidata.analytics = undefined;
- var ga = analytics.init();
- assert.equal(window.ga.l, undefined);
+ var ga = gamodule.init();
+ assert.notEqual(ga, undefined);
+ assert.equal(result.length, 0);
});
QUnit.test("test with analytics", function (assert) {
+ var result=[];
+ window.ga = function(cmd, id, auto) {
+ result[0] = [cmd, id, auto];
+ };
window.apidata.analytics = {"tracking_id": "X"};
- var ga = analytics.init();
- assert.notEqual(window.ga.l, undefined);
+ var ga = gamodule.init();
+ assert.notEqual(ga, undefined);
+ assert.equal(result[0][0], "create");
+ assert.equal(result[0][1], "X");
+ assert.equal(result[0][2], "auto");
});
});
diff --git a/remoteappmanager/static/js/analytics.js b/remoteappmanager/static/js/analytics.js
deleted file mode 100644
index 597f3a9a2..000000000
--- a/remoteappmanager/static/js/analytics.js
+++ /dev/null
@@ -1,33 +0,0 @@
-define([
- "require"
-], function (require) {
- "use strict";
-
- function init() {
- var module;
-
- if (window.apidata.analytics !== undefined) {
- window.GoogleAnalyticsObject = "ga";
- window.ga = function () {
- (window.ga.q = window.ga.q || []).push(arguments);
- };
- window.ga.l = 1 * new Date();
- module = function () {
- window.ga.apply(this, arguments);
- };
- require(["//www.google-analytics.com/analytics.js"]);
- window.ga('create', window.apidata.analytics.tracking_id, 'auto');
- } else {
- window.ga = function () {
- };
- module = function () {
- window.ga.apply(this, arguments);
- };
- }
- return module;
- }
-
- return {
- init: init
- };
-});
diff --git a/remoteappmanager/static/js/gamodule.js b/remoteappmanager/static/js/gamodule.js
new file mode 100644
index 000000000..0795f53b9
--- /dev/null
+++ b/remoteappmanager/static/js/gamodule.js
@@ -0,0 +1,26 @@
+// This module contains the setup for google analytics.
+// MUST not be renamed to analytics. Some blockers rely on name
+// matching to prevent loading.
+define([
+], function () {
+ "use strict";
+
+ function init() {
+ var module;
+
+ if (window.apidata.analytics !== undefined) {
+ window.ga('create', window.apidata.analytics.tracking_id, 'auto');
+ } else {
+ window.ga = function () {
+ };
+ }
+ module = function () {
+ window.ga.apply(this, arguments);
+ };
+ return module;
+ }
+
+ return {
+ init: init
+ };
+});
diff --git a/remoteappmanager/static/js/home/controller.js b/remoteappmanager/static/js/home/controller.js
index eabb38f1c..1c68bdbe4 100644
--- a/remoteappmanager/static/js/home/controller.js
+++ b/remoteappmanager/static/js/home/controller.js
@@ -3,7 +3,7 @@ require([
"jquery",
"urlutils",
"dialogs",
- "analytics",
+ "gamodule",
"home/models",
"home/views/application_list_view",
"home/views/application_view",
@@ -14,7 +14,7 @@ require([
$,
urlutils,
dialogs,
- analytics,
+ gamodule,
models,
application_list_view,
application_view,
@@ -23,7 +23,7 @@ require([
init) {
"use strict";
- var ga = analytics.init();
+ var ga = gamodule.init();
init.handlebars();
// This model keeps the retrieved content from the REST query locally.
diff --git a/remoteappmanager/templates/page.html b/remoteappmanager/templates/page.html
index 9304f76bb..e4500d086 100644
--- a/remoteappmanager/templates/page.html
+++ b/remoteappmanager/templates/page.html
@@ -41,6 +41,18 @@
{% endblock %}
{% block script %}
+
+ {% if analytics %}
+
+ {% endif %}
{% endblock %}