Created
November 5, 2018 19:48
-
-
Save sperand-io/0c1c4dccc9a5c9ace9dd5c99232a8ef6 to your computer and use it in GitHub Desktop.
Override errant referrers
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
// on page with the payment/login button that they leave from | |
var link = document.getElementById('paymentOrLoginLinkElementID') | |
var href = link.getAttribute('href'); | |
link.addEventListener('click', function(event){ | |
// before progressing to the link, save the referrer | |
event.preventDefault(); | |
sessionStorage.setItem('ctxReferrer', document.referrer); | |
window.location.href = href; | |
}); | |
// on whatever page the payment provider redirects back to | |
// ..snippet.. | |
analytics.load('writekey'); | |
analytics.ready(function() { | |
// see if there's a stored referrer | |
var referrer = sessionStorage.getItem('ctxReferrer'); | |
if (referrer) { | |
// if so, send "fixed" page call | |
analytics.page({}, { page: { referrer: referrer }}); | |
sessionStorage.removeItem('ctxReferrer'); | |
} else { | |
analytics.page(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment