Logging Disqus Comments with Clicky

April 5th, 2011 / Code

When someone makes a comment on my site, I like to see it in the visitor’s action list on Clicky. If you’re using Disqus with WordPress, here’s an easy way to log comments.

Inside the Disqus plugin folder, open comments.php. Scroll down to the JavaScript, and look for:

var disqus_config = function () {
  var config = this; // Access to the config object

Inside this config function, paste this snippet:

config.callbacks.onNewComment.push(function(){
  clicky.log(window.location.pathname + '#post-comment', 'Post Comment');
  clicky.goal('Post Comment');
});

Here I’ve added "#post-comment" to the end of the current page URL. This is because Clicky only allows one title per URL, and the current URL is already matched with whatever the title of your page is. Since I want this action to show up with the title "Post Comment", I have to make the URL unique. For me, appending #post-comment makes it unique, but if you use that hash for something else on the page, change it. The point is to make it something unique for the purpose of logging comments.

I also log a dynamic goal named "Post Comment". Since I’m using Clicky Monitor, I get a nice desktop notification when someone leaves a comment.

This concept of adding a callback function for new comments can be applied however you use Disqus, it doesn’t need to be with WordPress. This example is specific for Disqus + WordPress plugin. If you’re including the Disqus JavaScript yourself without a plugin, the syntax is slightly different.

If you have a question or comment, please leave it below.