-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
44 lines (34 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// https://developers.google.com/analytics/devguides/collection/analyticsjs/writing-plugins
;(function( ) { // eslint-disable-line
'use strict';
function _ga( ) {
return window[ window.GoogleAnalyticsObject || 'ga' ];
}
// :: ( pluginName: String, pluginConstructor: Function ) → null
// Provides a plugin name and constructor function to analytics.js. This
// function works even if the site has customized the ga global identifier.
function providePlugin( pluginName, pluginConstructor ) {
if ( typeof _ga() === 'function' ) {
_ga()( 'provide', pluginName, pluginConstructor );
}
}
function CleanUrls( tracker, opts ) {
// push callback to the end of the queue
_ga()( stripUtmQueries );
}
function stripUtmQueries( ) {
// support test
if ( !window.history.replaceState ) { return; }
var cleanSearch = window.location.search
// remove UTM codes
.replace( /utm_[^&]+&?/g, '' )
// cleanup residual ampersands
.replace( /&$/, ' ')
// cleanup residual question marks
.replace( /^\?$/, '' );
var cleanUrl = window.location.pathname + cleanSearch + window.location.hash;
window.history.replaceState( {}, '', cleanUrl );
}
// registers the plugin for use
providePlugin( 'cleanUrls', CleanUrls );
}( ));