From 712459d7069b79ce74feb9e11f1e43eb3e6a6891 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Thu, 11 Dec 2014 14:49:55 -0800 Subject: [PATCH] fixes bug 1109170 - google analytics for all AJAX --- static/js/googleanalytics.js | 28 ++++++++++++++++++++++++++++ static/js/init.js | 3 +++ templates/base.html | 1 + 3 files changed, 32 insertions(+) create mode 100644 static/js/googleanalytics.js diff --git a/static/js/googleanalytics.js b/static/js/googleanalytics.js new file mode 100644 index 00000000..8ef1e08c --- /dev/null +++ b/static/js/googleanalytics.js @@ -0,0 +1,28 @@ +/*jslint browser: true, + indent: 4, + confusion: true */ +/*global jQuery document ga */ + +var MT = (function (MT, $) { + + 'use strict'; + + MT.googleAnalyticsAjax = function () { + // When you have Google Analytics enabled you get a global + // object called `ga`. If that's not defined, exit early. + if (typeof ga === 'undefined') { + return; + } + jQuery(document) + .ajaxComplete(function(event, xhr, settings) { + // e.g 'send', 'event', 'GET', '?id=184', non-interation + ga('send', 'event', 'ajax', settings.type, settings.url, true); + }) + .ajaxError(function(event, xhr, settings) { + ga('send', 'event', 'ajaxerror', settings.type, settings.url, true); + }); + }; + + return MT; + +}(MT || {}, jQuery)); diff --git a/static/js/init.js b/static/js/init.js index befa26d5..a9abccf8 100644 --- a/static/js/init.js +++ b/static/js/init.js @@ -263,6 +263,9 @@ var MT = (function (MT, $) { // owa.js MT.owa(); + // googleanalytics.js + MT.googleAnalyticsAjax(); + // general.js MT.readOnlyMode(); diff --git a/templates/base.html b/templates/base.html index b91484eb..2f338f0c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -131,6 +131,7 @@

Page Status

+ {% endcompress %}