Skip to content

Instantly share code, notes, and snippets.

@gesteves
Created May 27, 2017 16:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gesteves/fde75286febd21b32ed778e76f604d17 to your computer and use it in GitHub Desktop.
Save gesteves/fde75286febd21b32ed778e76f604d17 to your computer and use it in GitHub Desktop.
Remove UTM parameters from URL after Google Analytics hit
(function() {
var w = window;
var removeUtms = function () {
var location = w.location;
if (location.search.indexOf('utm_') !== -1 && history.replaceState) {
history.replaceState({}, '', window.location.toString().replace(/(\&|\?)utm([_a-z0-9=\.]+)/g, ''));
}
};
ga('send', 'pageview', { 'hitCallback': removeUtms });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment