Title: Adding goal conversion tracking for comments
Last modified: August 18, 2016

---

# Adding goal conversion tracking for comments

 *  [tamar](https://wordpress.org/support/users/tamar/)
 * (@tamar)
 * [19 years ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/)
 * I want to be able to track comments but I can’t figure out what file to edit 
   with the Google Analytics Javascript snippet. I thought it was wp-comments-post.
   php but it doesn’t seem to be working. Where would this snippet go and how can
   I use it to track the number of comments?
 * Thanks.

Viewing 10 replies - 1 through 10 (of 10 total)

 *  [binarymoon](https://wordpress.org/support/users/binarymoon/)
 * (@binarymoon)
 * [19 years ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/#post-578220)
 * I’m not sure how I would do this. Since Google Analytics uses javascript and 
   wordpress is in php it would probably be easier to write it as a plugin.
 * I would have thought it would be best to intercept the form submit process with
   javascript, run the Google Analytics query, and then submit the form.
 * I’m not good enough with javascript to tell you how to do this though. Sorry.
 *  Thread Starter [tamar](https://wordpress.org/support/users/tamar/)
 * (@tamar)
 * [19 years ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/#post-578243)
 * Anyone have an idea without requiring an addon plugin?
 *  Thread Starter [tamar](https://wordpress.org/support/users/tamar/)
 * (@tamar)
 * [19 years ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/#post-578290)
 * Someone? Anyone?
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/#post-578291)
 * I had to look up the Goal Tracking on Google Analytics to understand what it 
   does and how it works.
 * Comments are made to wp-comments-form.php, and then it sends a redirect to the
   browser which sends them back to the post’s page. If you need some kind of intermediate
   page, you could do that with a plugin, but you’d be relying on a meta redirect
   or something.
 * In short, without a plugin, there’s probably no way to do it. The comment posting
   process has no defined intermediate page.
 *  Thread Starter [tamar](https://wordpress.org/support/users/tamar/)
 * (@tamar)
 * [19 years ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/#post-578299)
 * Otto42: thanks for getting back to me. Is there no way to embed a Javascript 
   snippet into the PHP script? That’s basically what I’m aiming for, but I don’t
   know how to do so effectively and I’m not very familiar with either programming
   language.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/#post-578305)
 * The problem is the way the goal tracking works. It works based on the URL of 
   the page containing the javascript. Basically, once the user gets to some URL,
   he’s met the goal.
 * But WordPress doesn’t have any particular final destination URL for making a 
   comment. You submit the comment, it saves, and you are redirected back to the
   page itself. There’s no single URL to define as the goal.
 * As for where to put the Google Analytics javascript, you put it in header.php
   of your theme. It tracks on every single page you have, there’s no “goal specific”
   javascript.
 *  Thread Starter [tamar](https://wordpress.org/support/users/tamar/)
 * (@tamar)
 * [19 years ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/#post-578306)
 * Right. I have regular analytics there, but not so much for tracking the number
   of comments. It would be nice if there was a way to do this, but I guess I’m 
   hoping for too much! Ah well, thanks for clarifying. 🙂
 *  [Gavin White](https://wordpress.org/support/users/heaventwig/)
 * (@heaventwig)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/#post-578400)
 * > Google Analytic’s [urchinTracker](https://www.google.com/support/googleanalytics/bin/answer.py?answer=55597)
   > allows you to track events on your site that do not generate a pageview.
 * This looks like it should provide a means to accomplish this functionality, which
   I’d also like to see. I don’t, however, have the necessary familiarity with the
   wordpress codebase to implement it.
 * Perhaps someone else can give it a try?
 * Thanks!
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 8 months ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/#post-578401)
 * In your theme’s comments.php file, you should find something like this:
 * `<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method
   ="post" id="commentform">`
 * Try changing it to something like this:
    `<form action="<?php echo get_option('
   siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" onsubmit="
   urchinTracker('/wp-comments-post.php'); return true;">`
 * That will allow it to track when somebody submits a comment using your comment
   form. It will show up in Google Analytics as a pageview of /wp-comments-post.
   php.
 *  [Gavin White](https://wordpress.org/support/users/heaventwig/)
 * (@heaventwig)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/#post-578402)
 * Thanks, Otto!
 * I imagine, though, that this will leave me getting “comment” hits from all the
   spam – is there some way you can think of to integrate this with Akismet, or 
   only to make it a hit when someone is auto-approved by virtue of already having
   posted a non-spam comment?
 * It seems like the latter could be done somewhere in comments.php, whereas the
   former would have to involve tinkering with Akismet itself.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Adding goal conversion tracking for comments’ is closed to new replies.

## Tags

 * [goal](https://wordpress.org/support/topic-tag/goal/)

 * 10 replies
 * 4 participants
 * Last reply from: [Gavin White](https://wordpress.org/support/users/heaventwig/)
 * Last activity: [18 years, 8 months ago](https://wordpress.org/support/topic/adding-goal-conversion-tracking-for-comments/#post-578402)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
