Tracking Disqus comments on Google Analytics

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?

2 Answers
2

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]);
        }];
    }
</script>
<?php   
}

add_action( 'wp_footer', 'hook_disqus_config' );

Disqus should do the rest.

Leave a Comment