So I have been having a heck of time trying to get the new Demographics part of Google Analytics (GA) to work with WordPress. First of all I do not use any plugins for Google Analytics and WordPress, it’s useless. And like many forum posts I have been reading plugin developers are taking their sweet time updating them to work with the new demographic features.
Let me show you the easiest way to add Google Analytics to your WordPress site without a plugin, then I’ll show you what I did to get it to work.
The easiest way to add analytics to any theme in WordPress:
- Go To Appearance > Editor
- On the right hand side click on footer.php
- Scroll all the way to the bottom and place your analytics code between the </body><!–Place Analytics Code Here–></html>
- Save and your done.
How to get Demographics to work with a WordPress site:
First you are going to want to enable the feature in Google Analytics
- Go to your domain in GA
- On the top right click on “Admin”
- Then in the center menu below click on “Property Settings”
- Where it says “Enable Demographics and Interest Reports” flip the slider from Off to On
- Save and Done
Now you want to get the new tracking code from GA to place that in your footer.php file. But guess what
Don’t use the code they give you, for me at least it does not work.
Use this code instead
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-********-*’]);
_gaq.push([‘_setDomainName’, ‘yourdomainname.com’]);
_gaq.push([‘_trackPageview’]);
(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://’ : ‘http://’) + ‘stats.g.doubleclick.net/dc.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Simply change theĀ UA-********-* with your account number and change yourdomainname.com to your domain name.
Wait about an hour and BAM! you will see data.
Have a nice day!