Skip to content

Commit

Permalink
Merge pull request #30 from ConvivioTeam/GTD-56-track-out-of-date-fra…
Browse files Browse the repository at this point in the history
…gment-links

GTD-56: Add GA event tracking if a user loads a page with a fragment ID that doesn't exist
  • Loading branch information
jonathanglassman authored Jul 17, 2018
2 parents 173e403 + db73750 commit 625ba34
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 625ba34

Please sign in to comment.