WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Disqus for my blog comments, and Google Analytics for tracking users. I have both implemented using plugins (Disqus Comment System and Google Analyticator). I'd like to track comments, but I can't figure out how to do that.

I have researched the problem, and there's some documentation for it, but it's not very clear. So far I've found some help from Disqus themselves (here), and from On Digital (here), so now I know what code to add.

What they don't mention is where to add it.

Do I insert it in one of the Disqus plugin files? My theme? Which file, and where?

share|improve this question
up vote 1 down vote accepted

You can use that snippet just anywhere where it can be rendered on single pages. For example, you can paste this under functions.php of your theme:

function hook_disqus_config(){

if( ! is_singular() ) return;

<script type="text/javascript">
    function disqus_config() {
        this.callbacks.onNewComment = [function(comment) {
            _gaq.push(['_trackEvent', 'Disqus', 'New Comment', comment.id]);

add_action( 'wp_footer', 'hook_disqus_config' );

Disqus should do the rest.

share|improve this answer
This answer isn't working for me - I was just wondering if it is still valid? The code is being added to my page after the GA scripts, and before the Disqus scripts but the function does not appear to be firing. – Tomtids Apr 21 at 13:08

According to your sources you want to add this javascript code to the footer of any page or post where there are disqus comments enabled. Because Disqus Comment System replaces all instances of your Comment box you can simply check if comments are enabled on the current post and toss it in there.

Try adding this to your functions.php file in your active theme's directory:

function track_disqus_comments() {
    $post = get_queried_object();
    if (isset($post) && $post->comment_status == "open") : ?>
    <script type="text/javascript">
    function disqus_config() {     this.callbacks.onNewComment = [function(comment) {       _gaq.push(['_trackEvent', 'Disqus', 'New Comment', comment.id]);     }]; }
} add_action('wp_footer', 'track_disqus_comments');

Keep in mind that the _gaq object needs to already be defined. Hopefully your google analytics plugin handles this for you and you won't have to worry about it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.