Howto implement google universal analytics to your WordPress

First of all you need to transfer your google property
from analytics to universal analytics
Go to analytics and to your admin panel

property1
From there you have to open “Universal Analytics Upgrade”

property2
From now on you have to wait between 24 to 48 hours.
Attention : If you have more then one property you have to do those
steps for each of them.
In the meann time you can install the wordpress universal analytics plugin.
Download here : Universal Analytics WordPress Plugin
Activate the Plugin after installing.
setting1
After the 24-48 hours you will get a new code from google analytics which will be used by
analytics.js

The code should looks like this

<!– Google Analytics –>
<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’,’//www.google-analytics.com/analytics.js’,’ga’);
ga(‘create’, ‘UA-XXXX-Y’, ‘auto’);
ga(‘send’, ‘pageview’);
</script>
<!– End Google Analytics –>

Now you have to change the UA-XXXX-Y to your property if it´s not done by the scipt
you get from google analytics.
Example : for my blog it looks like this

<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’,’//www.google-analytics.com/analytics.js’,’ga’);
ga(‘create’, ‘UA-72454909-1’, ‘webvoyager.net’);
ga(‘send’, ‘pageview’);
</script>

Copy this script to the window of the plugin and save it
settings2
 
 
settings3
Now your google analytis should collect the datas over the universal analytics code.
You can easiely check it bei your analytics reporting under “realtime reporting” -> “overview”
Click on any page of your blog and you should see the visit in you analytics

anonymize ip addresses
Specialy in germany you must anonymize ip addresses cause it´s not allowed to collect
clear ip addresses. (for me it´s anyway not important to know the ip addresses)
Google advice to use that code
ga(‘set’, ‘anonymizeIp’, true);

but this haven´t worked for me. I decided to hide the ip adresses for any individual hit.
with the following code.

ga(‘send’, ‘pageview’, {
‘anonymizeIp’: true
});
in my example:
<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’,’//www.google-analytics.com/analytics.js’,’ga’);
ga(‘create’, ‘UA-72454909-1’, ‘webvoyager.net’);
ga(‘send’, ‘pageview’, {‘anonymizeIp’: true});
ga(‘send’, ‘pageview’);
</script>
settings4
Last but not least the User Opt-out
You don ´t need to do that but I think in some countries it will give a law that you need to offer this option to your blog visitors, so I simply did it.
add this script to the page of every header of your pages. the easiest way is to use
the wordpress universal analytics plugin for this too.

that is the original example from google :

<script>
// Set to the same value as the web property used on the site
var gaProperty = ‘UA-XXXX-Y’;
// Disable tracking if the opt-out cookie exists.
var disableStr = ‘ga-disable-‘ + gaProperty;
if (document.cookie.indexOf(disableStr + ‘=true’) > -1) {
window[disableStr] = true;
}
// Opt-out function
function gaOptout() {
document.cookie = disableStr + ‘=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/’;
window[disableStr] = true;
}
</script>

in my example it looks like that
opt_out
So for this moment my hole analytics script looks like this :
<script>
// Set to the same value as the web property used on the site
var gaProperty = ‘UA-72454909-1’;
// Disable tracking if the opt-out cookie exists.
var disableStr = ‘ga-disable-‘ + gaProperty;
if (document.cookie.indexOf(disableStr + ‘=true’) > -1) {
window[disableStr] = true;
}
// Opt-out function
function gaOptout() {
document.cookie = disableStr + ‘=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/’;
window[disableStr] = true;
}
</script>
<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’,’//www.google-analytics.com/analytics.js’,’ga’);
ga(‘create’, ‘UA-72454909-1’, ‘webvoyager.net’);
ga(‘send’, ‘pageview’, {
‘anonymizeIp’: true
});
ga(‘send’, ‘pageview’);
</script>

Now the opt out script is implemented. Last step you need to do is to set a link
for your visitors where they can click. for this you need to place a link somewhere on one of your pages. I did it to my imprint page

<a href=”javascript:gaOptout()”>Click here to opt-out of Google Analytics</a>
and it looks like that
opt_out2
Now everything is implemented and when the visitor is clicking the link the tracking will be
turned off but the visitor gets no responds. So we do a small adjustment.
Go to pages in your WP and build a page like this.
turnoff
after you did this you have to add one more addional line to your script
window.location.href = “URL”;

you have to change URL to the page you just created.

In my case it´s
window.location.href = “http://webvoyager.net/tracking-turned-off”;

put this line to you analytics script. Exactly where I placed my.  see my example

<script>
// Set to the same value as the web property used on the site
var gaProperty = ‘UA-72454909-1’;
// Disable tracking if the opt-out cookie exists.
var disableStr = ‘ga-disable-‘ + gaProperty;
if (document.cookie.indexOf(disableStr + ‘=true’) > -1) {
window[disableStr] = true;
}
// Opt-out function
function gaOptout() {
document.cookie = disableStr + ‘=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/’;
window[disableStr] = true;
window.location.href = “http://webvoyager.net/tracking-turned-off”;
}
</script>
<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’,’//www.google-analytics.com/analytics.js’,’ga’);
ga(‘create’, ‘UA-72454909-1’, ‘webvoyager.net’);
ga(‘send’, ‘pageview’, {
‘anonymizeIp’: true
});
ga(‘send’, ‘pageview’);
</script>
It´s DONE.
That´s one of the small implementation you can do and it works fine.
Universal Analytics has much more options and secrets. I will write a follow
article when I will have figured it out with examples.

Enjoy

This entry was posted in social media and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *