Skip to content
A plugin for Google Analytics to remove UTM query strings from URLs
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig
.eslintrc.js
.gitignore
.travis.yml
LICENSE.md
README.md
index.js
index.min.js
package.json

README.md

Google Analytics Plugin: Clean URLs Build Status npm File Size

A plugin for Google Analytics to remove UTM query strings from URLs

This plugin is heavily inspired by Wistia's Fresh URL library but I wanted something more minimal so I've implemented its core functionality as a Google Analytics plugin.

Before:

https://example.com/article/?utm_source=twitter&utm_medium=tweet&utm_campaign=website&foo=bar

After:

https://example.com/article/?foo=bar

Warning:

This module is pre-1.0 and has not been thoroughly tested. Please test it yourself before using it in a production environment. Bugs can be reported on the issue tracker.


Install

npm install --save ga-clean-urls

Usage

The plugin must be loaded after the 'pageview' send so the UTM parameters are tracked correctly.

<script>
	ga( 'create', 'UA-XXXXX-Y', 'auto' );
	ga( 'send', 'pageview' );

	// Require the plugin after 'pageview' send
	ga( 'require', 'cleanUrls' );
</script>

<script async src="/path/to/ga-clean-urls/index.min.js"></script>

Browser support

IE10+.

The plugin uses history.replaceState to manipulate the URL, if the browser does not support history.replaceState then it shouldn't cause any problems but the URL will remain unchanged.
See http://caniuse.com/#feat=history for detailed browser support.

Todo

  • Add tests
You can’t perform that action at this time.