Skip to content

Commit

Permalink
Fix bug 1439650 - Track performance of all Ajax requests in Google An…
Browse files Browse the repository at this point in the history
…alytics. (#878)

* Add start time to every ajax request.
* Send event to Google Analytics with the overall time of request and requested url.
  • Loading branch information
jotes authored and mathjazz committed Mar 12, 2018
1 parent a122b83 commit 288cd05
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .eslintrc.js
Expand Up @@ -41,7 +41,8 @@ module.exports = {
editor: false,
DIFF_INSERT: false,
DIFF_EQUAL: false,
DIFF_DELETE: false
DIFF_DELETE: false,
ga: false
},
plugins: [
'react',
Expand Down
18 changes: 18 additions & 0 deletions pontoon/base/static/js/main.js
Expand Up @@ -621,6 +621,24 @@ var Pontoon = (function (my) {

/* Main code */
$(function() {
/*
* If Google Analytics is enabled, frontend will send additional about Ajax calls.
*
* To send an event to GA, We pass following informations:
* event category - hardcoded 'ajax' string.
* event action - hardcoded 'request' string.
* event label - contains url that was called by $.ajax() call.
*
* GA Analytics enriches every event with additional information like e.g. browser, resolution, country etc.
*/
$(document).ajaxComplete(function(event, jqXHR, settings) {
if (typeof(ga) !== 'function') {
return;
}

ga('send', 'event', 'ajax', 'request', settings.url);
});

Pontoon.NProgressBind();

// Display any notifications
Expand Down

0 comments on commit 288cd05

Please sign in to comment.