Track WordPress Blog Comments in Google Analytics
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”).
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):
Or, if you have the Asynchronous GA code (advanced users):
<form id="commentform" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" onSubmit="_gaq.push(['_trackPageview', '/tracking/comment-submit']);">
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).
Save that and you’re done! You’ll start seeing more actionable insights from your analytics from this point on.
whats the difference between these 2 codes:
Im trying to track the post comments on this blog: http://www.adaoimoveisblog.com.br
Well, as far as I can see there are four things:
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)
Thanks nice submit form using php.
Wow, I didn’t even know this was possible, I’m going to implement it literally right now !!!!