Skip to content

Instantly share code, notes, and snippets.

@da2x
Created March 10, 2018 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save da2x/4a2374cb6ece2fa0b27ba295cd85a68a to your computer and use it in GitHub Desktop.
Save da2x/4a2374cb6ece2fa0b27ba295cd85a68a to your computer and use it in GitHub Desktop.
Hash-based tracking links
/*
Tracking links that use hashes rather than query parameters.
Improves privacy by not including campaign data in referral-out links.
Improves CDN/proxy privacy by not sharing campaign data with them. Also improves caching!
Tracking links can (optionally) be removed from URLbar/history without a redirect.
Example links:
/document#s:feed
/document#s:email
*/
if (document.location.hash && document.location.hash.startsWith('#s:'))
{
var source = document.location.hash.split(':')[1];
// TODO: add source to tracking object.
if (history!==undefined)
{
history.replaceState({}, document.location.toString(),
document.location.toString().replace(document.location.hash,''));
} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment