Categories
Archives Blogging Strategy

How to Set Up Blog Comments as Goals in Google Analytics Using WordPress Hacks

Google Analytics WordPress Hacks As many of you know, I love writing about Google Analytics. I’m a data junkie, and there’s nothing I enjoy more than learning more about the visitors coming to my blog. One of the best ways to get actionable data out of your Google Analytics is to set up goals.

Setting up a goal in Google Analytics tells it that someone has completed something important on your website, such as buying product, signing up to your email list, or similar. For those who aren’t interested in selling products or capturing mailing list subscribers, is there anything else you can count as a goal on your blog? Absolutely – you can start with your comments!

What You Can Learn from Setting Up Blog Comments as Goals

Here are a few things you can learn from setting up comment form submissions as goals in Google Analytics.

  • Discover what referral sites are sending the most commenters. This will let you know what social media sites, guest blog posts, or other referrers are sending traffic that not only reads your posts, but also gets engaged. On the flip side, if you are getting a lot of spam, you might discover the sites sending spam traffic to your blog. This could lead you to finding lists that are sending you nothing but spam and, if that is the case, you can ask them to remove your blog from their list.
  • Learn the difference between commenters and regular traffic. On my blog, one interesting tidbit is the average time on site for regular visitors is 1:23 vs the average time on site for commenters is 10:31! A good reason to encourage comments!
  • Find out what content on your blog your most engaged audience enjoys so you can produce more of it.
  • See what part of the world your commenters are coming from. If you are targeting a specific region, but your commenters are coming from somewhere else, you might want to look into the reasons why.

So now that you know just a few reasons to set up comments as goals, let’s look at the ways you can set up your WordPress and Google Analytics to track your blog comments as goals.

Google Analytics WordPress Hacks As many of you know, I love writing about Google Analytics. I’m a data junkie, and there’s nothing I enjoy more than learning more about the visitors coming to my blog. One of the best ways to get actionable data out of your Google Analytics is to set up goals.

Setting up a goal in Google Analytics tells it that someone has completed something important on your website, such as buying product, signing up to your email list, or similar. For those who aren’t interested in selling products or capturing mailing list subscribers, is there anything else you can count as a goal on your blog? Absolutely – you can start with your comments!

What You Can Learn from Setting Up Blog Comments as Goals

Here are a few things you can learn from setting up comment form submissions as goals in Google Analytics.

  • Discover what referral sites are sending the most commenters. This will let you know what social media sites, guest blog posts, or other referrers are sending traffic that not only reads your posts, but also gets engaged. On the flip side, if you are getting a lot of spam, you might discover the sites sending spam traffic to your blog. This could lead you to finding lists that are sending you nothing but spam and, if that is the case, you can ask them to remove your blog from their list.
  • Learn the difference between commenters and regular traffic. On my blog, one interesting tidbit is the average time on site for regular visitors is 1:23 vs the average time on site for commenters is 10:31! A good reason to encourage comments!
  • Find out what content on your blog your most engaged audience enjoys so you can produce more of it.
  • See what part of the world your commenters are coming from. If you are targeting a specific region, but your commenters are coming from somewhere else, you might want to look into the reasons why.

So now that you know just a few reasons to set up comments as goals, let’s look at the ways you can set up your WordPress and Google Analytics to track your blog comments as goals.

Method 1: Tracking First Time Commenters Using Thank You Page & URL Destination Goal Type

For those who don’t want to get into hacking code and modifying templates, this is the easiest way to go. The only downside to this method is that it will only track the first time commenters to your blog. Also note that it will track every first time visitor that submits a comment, regardless of whether you go on to approve the comment.

The Basics of How it Works

Using a plugin, you will redirect first time commenters to a custom thank you page on your blog. In Google Analytics, you will set up that thank you page as a URL Destination goal type which tells Google Analytics that anyone who reaches the thank you page has completed an important goal.

Step 1: How to Set Up the Thank You Page in WordPress

Setting up the thank you page for your first time commenters is easy. Just create a new page on your blog, name it something like Thank You for Your Comment, and add some good content. This page can be as simple or complex as you choose to make it.

Thank You for Commenting Page

The goal is to think about what you would want your first time commenters to do next on your site, such as check out the main categories on your blog, sign up for your mailing list, or check out your latest product. You could also suggest that they connect with you on Twitter, Facebook, or Google+.

Step 2: How to Set Up the Redirect to the Thank You Page

Next, you will want to set up the redirect using the Comment Redirect plugin by Yoast. Add this by going to your WordPress Dashboard > Plugins > Add New and searching for comment redirect yoast. Once activated, you will find the settings for the plugin under the Plugins menu.

Comment Redirect Settings Location

Here, all you have to do is select your thank you for commenting page from the dropdown and save settings.

Comment Redirect Settings

That’s all it takes! All of your first time commenters will be directed to your thank you page.

Step 3: How to Set Up the URL Destination Goal in Google Analytics

The following directions are for Google Analytics 5, currently in beta. To use this version, click on the link at the top of your Google Analytics dashboard for New Version.

Last, but not least, you will need to set up the URL Destination goal in Google Analytics. Simply go to your blog’s profile in Google Analytics and click on the Settings wheel. Then click on the Goals tab.

Google Analytics 5 Goals Tab

To add a new Goal, click on the + Goal link.

If you have multiple websites / blogs, and want to view blog comment data across all of them as an Advanced Segment, be sure to use the same name, Goal set and position for each site’s blog comment goals. For example, on my main site, I set up Blog Comments set up as a goal in the second position of Goal set 2.

Google Analytics 5 Goal Setup Example 1

On my next website, I did the same, even though I haven’t utilized all of the goals in Goal set 1.

Google Analytics 5 Goal Setup Example 2

You will see why this is valuable later in the section on viewing your data in Google Analytics. Goals cannot be deleted and moved around later, so if you think you have more important goals to set up on your blog (like product sales, mailing list signups, etc.), save Goal set 1 for those and use Goal set 2, 3, or 4 for your comments.

Name your goal Blog Comments or similar. Then select the Goal Type of URL Destination. Enter the URL for the “Thank You for Commenting” page you created earlier into the Goal URL field. If the full URL for your page is http://domain.com/thank-you-for-commenting/, then enter /thank-you-for-commenting/ as the Goal URL. Your goal should look like this.

Google Analytics 5 Goal Setup URL Destination Type

Click on the Save button to finish. Now your goal is ready to go. Be sure to wait at least 24 hours (and for a few comments) to collect some data before beginning your analysis.

Method 2: Using the Comment Form Submit Button & Event Goal Type

For those who don’t mind getting into the code and modifying template files, this is the alternative. Once set up, this method will track any comments submitted on your blog, by both first time and repeat commenters. Also note that it will track every visitor that submits a comment, regardless of whether you go on to approve the comment.

Disclaimer

Some of the following directions include modifying templates that generally should not be modified. Some things to keep in mind regarding this…

  • Whenever you are modifying a template, be sure that you have a clean back up of it that you can upload immediately via FTP to your server in case your modifications make your website crash. Uploading an original file should set things straight. I use FileZilla, a free FTP solution or you can use the FTP client provided by your hosting company.
  • Some theme providers will void their support if you modify their templates. Keep this in mind if you are used to getting support and will continue to need it. Or, if your site needs suport later down the road, upload an original template file in place of the one you modified.
  • Be sure to note any template files you have changed and record the exact coding changes you have made. Whenever you upgrade the core WordPress platform, themes, or plugins, the upgrade might overwrite your changes. You will need to check after doing any upgrades that your code is still intact and possibly need to modify it again.
  • While these modifications worked on my websites, they may not necessarily work on yours due to conflicting WordPress versions, themes, and plugins. While I would love to help you if you get stuck, please note that I am not responsible for anything that happens to your website.

For all of the following directions, I have been using WordPress version 3.3.1 and specific theme versions as noted.

The Basics of How it Works

Whenever someone submits a comment on your blog, they have to click the Submit button. You will add some additional code on the Submit button for your contact form. In Google Analytics, you will set up a Event goal type which tells Google Analytics that anyone who reaches the thank you page has completed an important goal.

Step 1: How to Add Additional Code to the Submit Button

The code you will need to add to your blog’s comment form submit button is as follows.


onClick="_gaq.push(['_trackEvent', 'Forms', 'Submit', 'BlogComments']);"

The words Forms, Submit, and BlogComments sycn with the Google Analytics Event Goal Type settings for Category, Action, and Label. You can use different wording as you desire. You will add it to the Submit button for your comment form like this.


<input name="submit" type="submit" id="submit" onClick="_gaq.push(['_trackEvent', 'Forms', 'Submit', 'BlogComments']);" tabindex="5" value="<?php _e('Submit Comment', 'kubrick'); ?>" />

The only challenge is finding the comment form submit button on your theme. The following are locations and code examples for particular themes.

Standard WordPress Themes – Modifying the Comments Template File

If you’re not using Thesis or Genesis, you will want to start your search for your comment form’s submit button code in the comment template file for your theme. To view it, go to your WordPress dashboard > Appearance > Editor, and select the comments.php file from the right side. Then scroll through until you find the following highlighted code (or similar) for the comment form’s submit button.

WordPress Editor - Comments Template

You will want to add the Google Analytics event tracking code as follows, then click the Update File button to save your changes.

<input name="submit" type="submit" id="submit" onClick="_gaq.push(['_trackEvent', 'Forms', 'Submit', 'BlogComments']);" tabindex="5" value="<?php _e('Submit Comment', 'kubrick'); ?>" />

After you save the modified file, you can check your code by going to a blog post on your site, viewing the source code, and ensuring that the Submit button code looks like this.


<input name="submit" type="submit" onClick="_gaq.push(['_trackEvent', 'Forms', 'Submit', 'BlogComments']);" id="" value="Submit Comment" />

Be sure to test your comment form to ensure it is working properly by submitting a comment while logged out of your account. If the comment submits and posts properly, you can move on to the next section on setting up the Event Goal in Google Analytics.

Other WordPress Themes – Modifying the WordPress Core Comments Template File

If your theme has a comments.php file, but you can’t find the code for the submit button, you might instead find a call to the following function.

WordPress Editor - Comments Template

In this case, your theme is using the the comment form from the comment_template.php file within the core files located in /wp-includes/ folder. Most of Elegant Themes‘ templates, for example, do this. I use Notepad++ to edit files, but you can use your preferred source code editor. The line of code you are looking for should be at 1578 and looks like this.


<input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />

You will want to add the Google Analytics event tracking code as follows.


<input name="submit" type="submit" onClick="_gaq.push(['_trackEvent', 'Forms', 'Submit', 'BlogComments']);" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />

After you upload the modified file, you can check your code by going to a blog post on your site, viewing the source code, and ensuring that the Submit button code looks like this.


<input name="submit" type="submit" onClick="_gaq.push(['_trackEvent', 'Forms', 'Submit', 'BlogComments']);" id="" value="Post Comment" />

Be sure to test your comment form to ensure it is working properly by submitting a comment while logged out of your account. If the comment submits and posts properly, you can move on to the next section on setting up the Event Goal in Google Analytics.

Thesis 1.8.2

If you are using the Thesis Theme (like I am on Kikolani), version 1.8.2, then your comment form’s submit button code is in the comments.php file within /wp-content/thesis_182/lib/classes/ folder. I use Notepad++ to edit files, but you can use your preferred source code editor. The line of code you are looking for should be at 96 and looks like this.


echo "$tab\t\t\t<input name=\"submit\" class=\"form_submit\" type=\"submit\" id=\"submit\" tabindex=\"5\" value=\"" . __('Submit', 'thesis') . "\" />
";

You will want to add the Google Analytics event tracking code as follows.


echo "$tab\t\t\t<input name=\"submit\" onClick=\"_gaq.push(['_trackEvent', 'Forms', 'Submit', 'BlogComments']);\" class=\"form_submit\" type=\"submit\" id=\"submit\" tabindex=\"5\" value=\"" . __('Submit', 'thesis') . "\" />
";

After you upload the modified file, you can check your code by going to a blog post on your site, viewing the source code, and ensuring that the Submit button code looks like this.


<input name="submit" onClick="_gaq.push(['_trackEvent', 'Forms', 'Submit', 'BlogComments']);" class="form_submit" type="submit" id="submit" tabindex="5" value="Submit" />

Be sure to test your comment form to ensure it is working properly by submitting a comment while logged out of your account. If the comment submits and posts properly, you can move on to the next section on setting up the Event Goal in Google Analytics.

Genesis 1.8

StudioPress just released Genesis 1.8 Framework on Friday. I made the following changes to my blog before making the Genesis framework update, and everything was still working after the automatic upgrade to 1.8.

The Genesis Framework pulls the comment form’s submit button from the comment_template.php file within the core files located in /wp-includes/ folder. I use Notepad++ to edit files, but you can use your preferred source code editor. The line of code you are looking for should be at 1578 and looks like this.


<input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />

You will want to add the Google Analytics event tracking code as follows.


<input name="submit" type="submit" onClick="_gaq.push(['_trackEvent', 'Forms', 'Submit', 'BlogComments']);" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />

After you upload the modified file, you can check your code by going to a blog post on your site, viewing the source code, and ensuring that the Submit button code looks like this.


<input name="submit" type="submit" onClick="_gaq.push(['_trackEvent', 'Forms', 'Submit', 'BlogComments']);" id="" value="Post Comment" />

Be sure to test your comment form to ensure it is working properly by submitting a comment while logged out of your account. If the comment submits and posts properly, you can move on to the next section on setting up the Event Goal in Google Analytics.

Step 2: How to Set Up the Event Goal in Google Analytics

The following directions are for Google Analytics 5, currently in beta. To use this version, click on the link at the top of your Google Analytics dashboard for New Version.

Last, but not least, you will need to set up the Event Type goal in Google Analytics. Simply go to your blog’s profile in Google Analytics and click on the Settings wheel. Then click on the Goals tab.

Google Analytics 5 Goals Tab

To add a new Goal, click on the + Goal link.

If you have multiple websites / blogs, and want to view blog comment data across all of them as an Advanced Segment, be sure to use the same name, Goal set and position for each site’s blog comment goals. For example, on my main site, I set up Blog Comments set up as a goal in the second position of Goal set 2.

Google Analytics 5 Goal Setup Example 1

On my next website, I did the same, even though I haven’t utilized all of the goals in Goal set 1.

Google Analytics 5 Goal Setup Example 2

You will see why this is valuable later in the section on viewing your data in Google Analytics. Goals cannot be deleted and moved around later, so if you think you have more important goals to set up on your blog (like product sales, mailing list signups, etc.), save Goal set 1 for those and use Goal set 2, 3, or 4 for your comments.

Name your goal Blog Comments or similar. Then select the Goal Type of Event Type. Under Goal Details, configure the Category, Action, and Label that is equal to Forms, Submit, and BlogComments. Your completed goal should look like this.

Google Analytics 5 Goal Setup Event Type

Click on the Save button to finish. Now your goal is ready to go. Be sure to wait at least 24 hours (and for a few comments) to collect some data before beginning your analysis.

Viewing Your Data in Google Analytics

Now we are on to the fun part – analyzing the data! There are a few ways you can view your Blog Comments Goal data in Google Analytics.

Explorer View

In any section where you have the Explorer, you can click on the Goal Set corresponding to where you placed your Blog Comments goal. Since mine is in Goal Set 2, I would click on that in the Explorer.

Google Analytics 5 Goal Set Explorer View

You can then see the percentage of goal completions for the specific data you are viewing.

Google Analytics 5 Goal Set Explorer View Data

Click on the column for your Blog Comments goal to see data related to the highest goal completion rate. Specific types of data you can see in relation to your blog comment goal completions include the following.

  • Audience > Demographics > Location – View the top countries in which visitors are located and see the percentage of blog comments completed by these visitors.
  • Traffic Sources > Sources > All Traffic – View the top traffic referral sources and see the percentage of blog comments completed by these visitors.
  • Traffic Sources > Sources > Search > Organic – View the top keywords from search and see the percentage of blog comments completed by these visitors.
  • Content > Site Content > Landing Pages – View the top landing pages that visitors enter upon and see the percentage of blog comments by these visitors.

Conversions & Goals Overview

Next, you can visit the Conversions > Goals > Overview section of your data, then select your Blog Comments goal from the Goal Option dropdown.

Google Analytics 5 Conversions Goals Overview Options

Here, you can see a graph of the number of blog comment completions in the date range specified.

Google Analytics 5 - Goal Completions Overview

Below, you can see Goal Completion URLs which will generally correspond to the posts that have received the most comments.

Google Analytics 5 - Goal Completion URLs

You can also click on the Source / Medium link to see the top traffic sources that lead to blog comments.

Google Analytics 5 - Goal Completions Source Medium

Advanced Segments

This one is my favorite. By creating an Advanced Segment based on your Blog Comments goal completions, you can see all of your data within Google Analytics based on just those visitors who submitted a comment. To do this, click on the Advanced Segments tab, and then the + New Custom Segment to create a new segement.

Google Analytics 5 - New Custom Segment

Name your segment Blog Comments Goal or similar. Click on the green dropdown that starts with Ad Content, and start typing in the name you gave your Blog Comments goal. Select the one that includes Completions.

Google Analytics 5 - Advanced Segment Setup

In the next dropdown, select Great than, and then enter 0 as the value. Your completed segment should look similar to this.

Google Analytics 5 - Completed Advanced Segment Setup

Click on the Test Segment to see data from this segment, or click Save Segment to finish. Now you should see your Blog Comments goal like this.

Google Analytics 5 - Viewing Advanced Segments

To compare the data for visitors who comment vs. those who do not, click on the Advanced Segment area again and make sure the boxes for All Visits (under Default Segments) and your Blog Comments goal (under Custom Segments) are checked. Then click Apply.

Google Analytics 5 - Comparing Advanced Segments

Now you are ready to learn even more about your visitors and the differences between those that comment and those that don’t. I find that pages per visit and average time on site are much better for commenters compared to other visitors – a good reason to encourage comments!

Speaking of comments, if you have applied something similar to your blog or apply this, let me know how it goes!

By Kristi Hines

Kristi Hines is a freelance writer, professional blogger, and ghostwriter who specializes in business and marketing topics.