Skip to content

Commit

Permalink
GTD-56: Add GA event tracking if a user loads a page with a fragment …
Browse files Browse the repository at this point in the history
…ID that doesn't exist
  • Loading branch information
lewisnyman committed Jul 9, 2018
1 parent 90b6ac0 commit db73750
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/assets/javascripts/_analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
};
};

function catchBrokenFragmentLinks() {
var fragment = window.location.hash;
var $target = $(fragment);
if(!$target.get(0)) {
ga(
'send',
'event',
'Broken fragment ID', // Event Category
'pageview', // Event Action
window.location.pathname + fragment // Event Label
);
}
}

$(document).on('ready', function() {
if (typeof ga === 'undefined') {
return;
Expand All @@ -27,5 +41,6 @@
$('.technical-documentation a').on('click', linkTrackingEventHandler('inTextClick'));
$('.header a').on('click', linkTrackingEventHandler('topNavigationClick'));
$('.toc a').on('click', linkTrackingEventHandler('tableOfContentsNavigationClick'));
catchBrokenFragmentLinks();
});
})(jQuery);

0 comments on commit db73750

Please sign in to comment.