Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
fixes bug 1109170 - google analytics for all AJAX
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Dec 12, 2014
1 parent 7a6f193 commit 712459d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 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));
3 changes: 3 additions & 0 deletions static/js/init.js
Expand Up @@ -263,6 +263,9 @@ var MT = (function (MT, $) {
// owa.js
MT.owa();

// googleanalytics.js
MT.googleAnalyticsAjax();

// general.js
MT.readOnlyMode();

Expand Down
1 change: 1 addition & 0 deletions templates/base.html
Expand Up @@ -131,6 +131,7 @@ <h2>Page Status</h2>
<script src="{{ STATIC_URL }}js/multiselect-ajax.js"></script>
<script src="{{ STATIC_URL }}js/runtests.js"></script>
<script src="{{ STATIC_URL }}js/owa.js"></script>
<script src="{{ STATIC_URL }}js/googleanalytics.js"></script>
<script src="{{ STATIC_URL }}js/general.js"></script>
<script src="{{ STATIC_URL }}js/init.js"></script>
{% endcompress %}
Expand Down

0 comments on commit 712459d

Please sign in to comment.