Track WordPress Blog Comments in Google Analytics

April 17th, 2010 → 9:15 am by Robert Kingston // 3 Comments

Comments are really important to track, if you want to create a successful blog, for a number of reasons:

  • Comments create community
  • They add fresh, new content for search engines to crawl
  • Comments give you feedback

Tracking comments in Google Analytics  lets you see what drives people to comment on your blog.

How to do it

1. Open up your WordPress Dashboard, browse to “Appearance”, “Editor” and find your comments code (usually, “comments.php”).

Click to enlarge.

2. Find the code that has something to the affect of “method=”post”" and “action=”<?php echo get_option(‘siteurl’); ?>/wp-comments-post.php”".

3. Insert the following code within the <form> tag itself.

If you have the normal GA code (this is most likely the one you need):

onSubmit="pageTracker._trackPageview('/tracking/comment-submit');"

Or, if you have the Asynchronous GA code (advanced users):

onSubmit="_gaq.push(['_trackPageview', '/tracking/comment-submit']);"

Like so:

<form id="commentform" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" onSubmit="_gaq.push(['_trackPageview', '/tracking/comment-submit']);">

Click to enlarge.

4. Setup the goal in Analytics

Login to your account, click “Edit” beside your profile and “Add new goal”. You want to use URL destination as your goal type and in the goal URL, use exact match for “/tracking/comment-submit” (without quotation marks).

Click to enlarge.

Save that and you’re done! You’ll start seeing more actionable insights from your analytics from this point on.


Share this post

Show it to your friends:


You Might Like These Posts Too

Subscribe to my blog for more great analytics and conversion optimisation tips.

3 Comments → “Track WordPress Blog Comments in Google Analytics”


  1. beto machado

    1 year ago

    hi,

    whats the difference between these 2 codes:

    onclick=””javascript:” _gaq.push(['_trackpageview',="" '=""/comment-submission.php']);”=”"

    and yours:

    onSubmit=”pageTracker._trackPageview(‘/tracking/comment-submit’);”

    Im trying to track the post comments on this blog: http://www.adaoimoveisblog.com.br

    Thanks!


  2. Rob Kingston

    1 year ago

    Hi Beto,

    Well, as far as I can see there are four things:

    The top one uses incorrect javascript syntax and won’t work
    The top one is called when someone clicks the “Submit” button rather than when the form submits – in fact onclick may be the way to go here
    The top one seems to be referring to comment-submission.php – not that it matters (whatever you put in here just needs to be unique, so you can track it in Analytics)
    The bottom one seems to have been modified – the quotation marks are not the same (use ” and ‘ rather than ” and ’ for it to work)


  3. sudhakar

    3 months ago

    Thanks nice submit form using php.


Add Your Comment