In order to receive as many information as possible from Google Analytics, we have to create two “Custom Dimensions“. Since the release of Universal Analytics, those “Custom Dimensions” have to be manually registered in the Google Analytics account before they can be used.
First step is to log into your Google Analytics account. You need administrator access for the following operations. Open the “Admin” menu.
In the middle column locate the link “Custom Definitions” and click on it. A submenu opens. In the submenu click on the link “Custom Dimensions“.
A new page opens with an empty table and a button “+ New Custom Dimension“. Click that button.
The next page shows a form. Fill in the name “clientid“, choose the scope “User” and make sure “Active” is checked. Then click on “Create“.
Afterwards click the red “+ Add New Dimension” button again and create a second dimension with the name “sessionid” and the scope “Session“. Make sure it is active. The click “Create“.
Now you should see two dimensions in the table like in the screenshot below.
The custom dimensions are now created and you can proceed and implement the Universal Analytics tracking pixel into your page.
Instead using the default Universal Analytics tracking pixel, we use a slightly modified version to leverage the custom dimensions we just created. It is absolutely crucial that you change the line 7 “ga(‘create’, ‘UA-11111111-1’);” and replace UA-11111111-1 with your own account number.
<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-11111111-1'); ga(function(tracker) { var t=(new Date()).getTime(); var clientId = tracker.get('clientId'); if (clientId == "") { clientId = Math.random().toString(36).substr(2,9)+"."+t; } var wd_s_id = null; var name = 'wd_s_id='; var cookies = document.cookie.split(';'); for (var i=0; i < cookies.length; i++) { var c = cookies[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(name) == 0) { wd_s_id = c.substring(name.length, c.length); break; } } if (wd_s_id == null) { wd_s_id = clientId + '.' + t; document.cookie = name + wd_s_id + '; path=/'; } tracker.send('pageview', { 'dimension1': clientId, 'dimension2': wd_s_id }); }); </script>
Google recommends to place the tag above directly under the opening <body> tag on all of your pages.