How To Enable Google Analytics Demographics And Interest Reports In WordPress

How To Enable Google Analytics Demographics And Interest Reports In WordPress

If you’re running a WordPress blog, and have Google Analytics installed in order to track and analyze the traffic to your blog, you probably noticed that when you go to Google Analytics and click “Audience -> Demographics -> Age / Gender” it says that you need to validate tracking code after you have made this one-line, one-time update.

So I was trying to add this one line with my analytics plugin with no success. I also followed all of the instructions Google provides in order to make it happen.

Then, I tried to install a couple of different Google Analytics plugins for WordPress, even ones that declared they support demographics.

In the end, I succeeded in enabling it by playing around with the plugin’s code (Google Analytics for WordPress).

WordPress Demographics and Interest Reports support

Using this method, you can enable the demographics report on your WordPress blog. Please remember that since we’re going to change the plugin’s source code, every time you update the plugin, you’ll have to modify the code again, until some developer develops a decent analytics plugin to support demographics and interest reports.

Let’s begin:

1. Uninstall each and every analytics plugin from your blog.

2. Add this plugin to WordPress.

3. Activate the plugin, and go to “Settings -> Google Analytics”.

4. Authenticate the plugin with your Analytics account (just follow the instructions on the plugin’s settings page).

5. Using FTP software, go to “wp-content/plugins/google-analytics-for-wordpress/frontend/” and edit the file “class-frontend.php”.

6. Go to line 293, or search for ga.src.

7. Replace the following code:


ga.src = <!--?php if ( $this--->options['gajslocalhosting'] && !empty( $this->options['gajsurl'] ) ) {
echo "'" . $this->options['gajsurl'] . "';";
} else {
$script = 'ga.js';
if ( current_user_can( 'manage_options' ) && $this->options['debug'] )
$script = 'u/ga_debug.js';
echo "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/" . $script . "'";
}
?>;

with the following code:

ga.src = <?php</pre>
if ( $this->options['gajslocalhosting'] && !empty( $this->options['gajsurl'] ) ) {
echo "'" . $this->options['gajsurl'] . "';";
} else {
$script = 'dc.js';
if ( current_user_can( 'manage_options' ) && $this->options['debug'] )
$script = 'u/ga_debug.js';
echo "('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/" . $script . "'";
}
?>;

8. If you have any cache plugin installed, clear the cache. Otherwise it won’t work.

9.Go back to Google Analytics -> Audience -> Demographics -> Age / Gender and click “Validate tracking code“.

10. If everything goes well, you should get this:

Google Analytics Demographics And Interest Reports In WordPress
Success!

Leave a Reply

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

fifteen + 7 =