Monday, February 23, 2015

How to: Google Analytics Custom Variables - Google Analytics Custom Dimensions & Metrics

For a long time I had a problem of data mismatching with my custom recorded data vs Google AdWords data, finally today I have managed to solve it with the help of Google Analytics.

I add some custom variable each request coming from Google AdWords destination URL so I can also record in my database for extra information, such as if it’s from Google, Facebook & etc. I also use a certain keyword then I will save them to users’ cookie for 90 days, so even if the user comes to my site after some time I will still have the information where the user is from. Unfortunately, my cookie does not save some user's computer and when I get the enquiry I have no clue who & where this user came from.

But Google AdWords show all the keywords and conversions but I cannot match AdWords record and my data since it will show only the keyword and country where the user is from. Another factor is that Google AdWords cookie will save on user PC and for the same user my cookie will not save which really frustrates me.

After doing some research and digging (not only me but some of my friends are also having some wired problems and data mismatching), I luckily have found a solution from Google Analytics.

Google Analytics Custom Dimensions & Metrics (Don't search for Custom Variable you will end up in hell)

In Google Analytics Custom Dimensions & Metrics you can send custom data to Google Analytics and you can view them using custom reports.

First you have register your custom dimensions [Link] and then have to add the correct code at your goal conversion page.

Following is the code you will get from Google Analytics as tracking code, I have registered dimension1 (CustomerID) & dimension3 (EmailAddress).

I have just added 2 lines to the default code we are getting from Google Analytics - Line 07 & Line 08.


01. <script>
02. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
03. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
04. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
05. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
06. ga('create', 'UA-XXXXXXX-1', 'auto');
07. ga('set', 'dimension1', '123456');
08. ga('set', 'dimension3', '[email protected]');
09. ga('send', 'pageview');
10. </script>



I am still new with this but if you have any question how to configure and setup, please do contact me I will try my best to help.