Skip to content

Commit

Permalink
Merge pull request #2135 from sul-dlss/outbound-linkz
Browse files Browse the repository at this point in the history
tracks external link clicks using Google Analytics
  • Loading branch information
Jessie Keck committed Nov 9, 2018
2 parents b331eba + 6cb37db commit e678e45
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Adds the ability to track outbound links for usage analysis [#2135](https://github.com/sul-dlss/SearchWorks/pull/2135)
### Changed
- Now returning a 404 Not Found error when an article record is not found [#2133](https://github.com/sul-dlss/SearchWorks/pull/2133)
- Updates the way that Hoover Archive records are requested and shown in the access panel [#2123](https://github.com/sul-dlss/SearchWorks/pull/2123)
Expand Down
18 changes: 17 additions & 1 deletion app/assets/javascripts/analytics.js
Expand Up @@ -60,5 +60,21 @@ Blacklight.onLoad(function(){
$('.iiif-dnd').on('dragstart', function(e) {
var manifest = $(e.currentTarget).data().manifest;
window._gaq.push(['_trackEvent', 'IIIF DnD', 'dragged', manifest]);
})
});

// Track external link clicks
$('a[href]:not([href^="/"],[href^="#"])').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
var _this = this;
var link = $(e.currentTarget);
try {
if (link[0].host !== window.location.host) {
window._gaq.push(['_trackEvent', 'External link', 'clicked', link.attr('href')]);
}
}
finally {
window.location.href = _this.href;
}
});
});

0 comments on commit e678e45

Please sign in to comment.