Skip to content

Commit

Permalink
Sets non-interaction flag for scroll analytics events
Browse files Browse the repository at this point in the history
Before, ScrollTo events were not being flagged as non-interaction events,
so google was factoring them into bounce rates. This flags ScrollTo events
as non-interactive to fix this.

Info on non-interactive flag:
https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide#non-interaction
  • Loading branch information
Will Tomlins committed Jun 23, 2014
1 parent 0703482 commit 1cc7a49
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/assets/javascripts/analytics/scroll-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@
for ( var i=0; i<this.trackedNodes.length; i++ ) {
if ( this.trackedNodes[i].isVisible() && !this.trackedNodes[i].alreadySeen ) {
this.trackedNodes[i].alreadySeen = true;
GOVUK.sendToAnalytics(["_trackEvent"].concat(this.trackedNodes[i].eventData));
GOVUK.sendToAnalytics(["_trackEvent"].concat(this.trackedNodes[i].eventData).concat([true]));
// Last 'true' sets non-interaction flag
// https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide#non-interaction
}
}
};
Expand Down
10 changes: 5 additions & 5 deletions spec/javascripts/analytics/scroll-tracker-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ describe("GOVUK.ScrollTracker", function() {
scrollToPercent(60);

expect(GOVUK.sendToAnalytics.calls.count()).toBe(2);
expect(GOVUK.sendToAnalytics.calls.argsFor(0)).toEqual([ ["_trackEvent", "ScrollTo", "Percent", "25"] ]);
expect(GOVUK.sendToAnalytics.calls.argsFor(1)).toEqual([ ["_trackEvent", "ScrollTo", "Percent", "50"] ]);
expect(GOVUK.sendToAnalytics.calls.argsFor(0)).toEqual([ ["_trackEvent", "ScrollTo", "Percent", "25", true] ]);
expect(GOVUK.sendToAnalytics.calls.argsFor(1)).toEqual([ ["_trackEvent", "ScrollTo", "Percent", "50", true] ]);
});
});

describe("tracking by headings", function() {
var FIXTURE = "\
<h1>This is the first <span>heading</span></h1>\
<h2>This is the second heading</h2>\
<h4>
<h4>\
This is the third&nbsp;heading \
</h4>";

Expand All @@ -71,7 +71,7 @@ describe("GOVUK.ScrollTracker", function() {
scrollToShowHeadingNumber(1);

expect(GOVUK.sendToAnalytics.calls.count()).toBe(1);
expect(GOVUK.sendToAnalytics.calls.argsFor(0)).toEqual([ ["_trackEvent", "ScrollTo", "Heading", "This is the first heading"] ]);
expect(GOVUK.sendToAnalytics.calls.argsFor(0)).toEqual([ ["_trackEvent", "ScrollTo", "Heading", "This is the first heading", true] ]);

scrollToShowHeadingNumber(2);

Expand All @@ -80,7 +80,7 @@ describe("GOVUK.ScrollTracker", function() {
scrollToShowHeadingNumber(3);

expect(GOVUK.sendToAnalytics.calls.count()).toBe(2);
expect(GOVUK.sendToAnalytics.calls.argsFor(1)).toEqual([ ["_trackEvent", "ScrollTo", "Heading", "This is the third heading"] ]);
expect(GOVUK.sendToAnalytics.calls.argsFor(1)).toEqual([ ["_trackEvent", "ScrollTo", "Heading", "This is the third heading", true] ]);
});
});

Expand Down

0 comments on commit 1cc7a49

Please sign in to comment.