Plugin Planet

Premium WordPress Plugins

By default, GA Pro makes it easy to add Google Analytics tracking to your WordPress-powered site. When configuring the plugin, you can choose from different tracking techniques, like Universal Analytics or Global Site Tag. When Universal Analytics tracking is enabled, the plugin outputs the required code recommended by Google. So it’s all good under the hood, as they say.

About the “auto” parameter

As of today, here is an example of what the Universal Tracking code looks like:

<script>
	(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
	ga('create', 'UA-1234567890', 'auto');
	ga('send', 'pageview');
</script>

Notice the third argument/parameter in this line:

ga('create', 'UA-1234567890', 'auto');

According to Google documentation, setting that third parameter to “auto” is the recommended default configuration, and is ideal for most tracking purposes. But some tracking techniques (for example Site Speed Sample Rate) require replacing the auto parameter with a custom argument. That is the purpose of this tutorial, how to replace the auto parameter with whatever is required.

Replace the “auto” parameter

To replace the auto parameter in Universal Analytics tracking. First add the following code to WordPress functions or a custom plugin:

// GA Google Analytics - Disable auto parameter
function ga_google_analytics_enable_auto($enable) { return false; }
add_filter('ga_google_analytics_enable_auto', 'ga_google_analytics_enable_auto');

That code requires no editing, copy and paste as-is. Once added, it effectively tells GA Pro to not include the auto parameter.

Now that auto is disabled, you can replace it with your own parameter(s). For example, to implement Universal Analytics Site Speed Sample Rate, enter the following code in the plugin setting Custom Tracker Objects:

{'siteSpeedSampleRate': 100}

Save changes and done. The resulting tracking code will now include this line:

ga('create', 'UA-1234567890', {'siteSpeedSampleRate': 100});

You can verify this change by looking at the code preview on the plugin settings page. Also you can examine the source code of your web pages, will show the same thing.

That’s all there is to it. You can use this technique to replace the auto parameter with whatever is required.