Created
September 16, 2014 14:25
-
-
Save KATT/30178fd907fc20709574 to your computer and use it in GitHub Desktop.
Workaround for Segment.io to track page views on a pushState-based site. Dependent on History.js
This file contains hidden or 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
var utils = utils || {}; | |
// [..] | |
utils.page = (function() { | |
var previousState = History.getState(); | |
return function() { | |
var state = History.getState(); | |
var title = state.title || document.title; | |
var path = History.getShortUrl(state.url); | |
var url = state.url; | |
var referrer = previousState.url; | |
window.analytics.page(null, { | |
path: path | |
, url: url | |
, title: title | |
, referrer: referrer | |
}); | |
previousState = state; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment