How To Track WordPress Signups and Comments With Google Analytics

I’m sure you have heard of Google Analytics which enables you to track the behaviour of a site.  The key to success with Analytics is using website goals.  This allows you to conveniently measure the success of your website to criteria you dictate.  For a blog (for me), 2 goals would be a user registration – and a user posting a comment on a page or post.  For this, we need to ensure tracking is on all appropriate pages and that the goals are correctly configured.

If you haven’t already – you should be using the Google Analytics code (which looks something like the following).

<script type=”text/javascript”>

var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);

document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js’

type=’text/javascript’%3E%3C/script%3E”));

</script>

<script type=”text/javascript”>

var pageTracker = _gat._getTracker(“UA-XXXXXXX-X”);

pageTracker._initData();

pageTracker._trackPageview();

</script>

Install Google Analytics

Firstly, make sure the Google Tracking Code is on all pages.  You can do this by editing your themes footer.php file.  Simply paste the Google Code before </body>.  But you’re not done yet.  You need to edit wp-login.php.  Search for </body> and before every instance add your Google code here too.  This will put tracking not only on your blog contents, but also registration and various front end forms too.

Configure Goal Tracking For Blog Registrations

You are now ready to configure Google Analytics to track goal actions on your blog.  To start with, we will setup the goal for a user registration.  Remember the additional code we added to wp-login.php?  This is where it comes into use.  Create a conversion goal based on the screenshot below.  I always give a goal conversion like this a value of 1 – due to reporting and keyphrase / traffic reports – which assigns a calculated money value field to various keywords and traffic sources to work out profitable items.

To make sure this goal is only counted when people register (and not just visit the page), add the following funnel configuration too;

There we have it.  If you leave this goal running for a while – you will be able to see exactly what keywords / traffic sources are driving registrations – and infact – whether your registrations are growing or falling…

Configure Analytics For Blog / Page Comments

The new version of Google Analytics allows us to track onclick events.  Every comments box has a submit button or image.  We can track when this button is clicked using Google Analytics.  To get your head around this concept, we setup what we call a virtual page view (a page that doesnt actually exist – the submit button) and we link this virtual page view to a goal in Analytics.

The first thing to do is edit your themes template file – namely comments.php.  Unfortunately, you will need a little bit of HTML knowledge to find the HTML code for the submit/image button.  Once you have located this, add the following code to the input object;

onclick=”javascript: pageTracker._trackPageview(’/goal/wordpress.html’);”

Thats it! Now – everytime the submit button is pressed on the comments form – analytics will log that /goal/wordpress.html has been visited.  This leaves the logical conclusion to add a goal conversion to this page.  See the screenshot below on how to do this;

 

That’s all there is too it.  You have now setup goal tracking on your WordPress blog.

 

Related Posts:

  • No Related Posts
Bookmark the permalink.
  • http://www.thedan1984.com Dan Bochichio

    Good quick write up Chris. My only concern is you are doing core-hacking to do this, so if you update WP, you need to redo your changes to wp-login.php (to my knowledge).

    There’s probably a way to add it to your theme’s functions.php file so even after a WordPress update, your analytics code will still be loaded during the registration page.

    One more thing, promise!

    Do you know if there’s anyway to track HOW a user who registered arrived at the site?. I’ve been trying to find a way to get a specific user’s original referral (which lead to a sign up) logged in Analytics along with the user name.

    • Chris Dyson

      Hi Dan,

      Yeah I agree it is a bit of a “hack” & I don’t like messing with WP Core so you could create a Thank you for commenting page like Jon Cooper at Point Blank SEO has done and use the Yoast Comment Redirect Plugin.

      You should be able to track the referral source if you setup the goal correctly but as for the username that’s probably a little beyond my knowledge.

      Could you create some kind of thank you for signing up page where they re-entered their username to be entered in a prize draw??

  • Jay patel

    Sorry
    above link note working its updated with below link,,

    How
    to recover data from Microsoft office 2010 | Unsaved data

    You can
    also set auto save time to prevent this problem for next time

    Set
    minimum auto save time to save data in Microsoft office document