-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GeoBlacklight Google Anaytics Module
Addresses #13
- Loading branch information
Showing
9 changed files
with
121 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Inspired by and modified from http://railsapps.github.io/rails-google-analytics.html | ||
|
||
GoogleAnalytics = (function() { | ||
function GoogleAnalytics() {} | ||
|
||
GoogleAnalytics.load = function() { | ||
var firstScript, ga; | ||
window._gaq = []; | ||
GoogleAnalytics.analyticsId = GoogleAnalytics.getAnalyticsId(); | ||
window._gaq.push(['_setAccount', GoogleAnalytics.analyticsId]); | ||
ga = document.createElement('script'); | ||
ga.type = 'text/javascript'; | ||
ga.async = true; | ||
ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | ||
firstScript = document.getElementsByTagName('script')[0]; | ||
firstScript.parentNode.insertBefore(ga, firstScript); | ||
}; | ||
|
||
GoogleAnalytics.trackPageview = function(url) { | ||
if (!GoogleAnalytics.isLocalRequest()) { | ||
if (url) { | ||
window._gaq.push(['_trackPageview', url]); | ||
} else { | ||
window._gaq.push(['_trackPageview']); | ||
} | ||
return window._gaq.push(['_trackPageLoadTime']); | ||
} | ||
}; | ||
|
||
GoogleAnalytics.isLocalRequest = function() { | ||
return GoogleAnalytics.documentDomainIncludes('local'); | ||
}; | ||
|
||
GoogleAnalytics.documentDomainIncludes = function(str) { | ||
return document.domain.indexOf(str) !== -1; | ||
}; | ||
|
||
GoogleAnalytics.getAnalyticsId = function() { | ||
return $('[data-analytics-id]').data('analytics-id'); | ||
}; | ||
|
||
return GoogleAnalytics; | ||
|
||
})(); | ||
|
||
Blacklight.onLoad(function() { | ||
GoogleAnalytics.load(); | ||
if (GoogleAnalytics.analyticsId) { | ||
GoogleAnalytics.trackPageview(); | ||
} | ||
|
||
// Log spatial search events | ||
|
||
// Map Moved | ||
History.Adapter.bind(window, 'statechange', function(e) { | ||
var state = History.getState(); | ||
window._gaq.push(['_trackEvent', 'Spatial Search', 'Map Moved', state.url]); | ||
}); | ||
|
||
// Initiate search in an area | ||
$('.leaflet-control.search-control a.btn-primary').on('click', function(e) { | ||
window._gaq.push(['_trackEvent', 'Spatial Search', 'Search Here', e.currentTarget.baseURI]); | ||
}); | ||
|
||
// Log download clicks | ||
$(document).on('click', '[data-download="trigger"]', function(e) { | ||
var data = $(e.target).data(); | ||
window._gaq.push(['_trackEvent', 'Download', data.downloadId, data.downloadType]); | ||
}); | ||
|
||
// Log failed download | ||
$(document).on('DOMNodeInserted', '[data-download="error"]', function(e) { | ||
var data = $(e.target).data(); | ||
window._gaq.push(['_trackEvent', 'Failed Download', data.downloadId, data.downloadType]); | ||
}); | ||
|
||
// Log all show page tool clicks | ||
$(document).on('click', 'div.show-tools li a', function() { | ||
var data = $(this); | ||
window._gaq.push(['_trackEvent', $.trim(data[0].innerText), window.location.href.split("/").pop()]); | ||
}); | ||
|
||
// Log all facet expand/collapse clicks | ||
$('#facets h3').on('click', function(){ | ||
var label = $(this).text(); | ||
var heading_values = ['Facets', 'collapse_expand', label]; | ||
_gaq.push(['_trackEvent'].concat(heading_values)); | ||
}); | ||
|
||
// Log all facet more link clicks | ||
$('#facets li.more_facets a').on('click', function(){ | ||
var label = $(this).find("span").text(); | ||
var heading_values = ['Facets', 'more_link', label]; | ||
_gaq.push(['_trackEvent'].concat(heading_values)); | ||
}); | ||
|
||
// Log all item viewer definition rollovers | ||
$('#viewer-container a[data-toggle="popover"]').hover(function(){ | ||
window._gaq.push(['_trackEvent', 'Item Viewer Popover', window.location.href.split("/").pop()]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
//= require geoblacklight | ||
|
||
// UMass | ||
//= require analytics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters