Capturing Disqus commenting activity via callbacks

If you would like to track new comments and replies via your own analytics service, such as Omniture or Google Analytics, you can do so via the following callback function.

The following callback can be added to the disqus_config function which already exists within the universal embed code:

var disqus_config = function () {
    this.callbacks.onNewComment = [function() { trackComment(); }];
};

Make sure to replace trackComment(); with the script you wish to track via your analytics service.

NOTE: If you're using the Wordpress plugin, you'll need to edit the plugin and add your tracker to the existing disqus_config function.

Getting comment information

This callback function accepts one parameter comment which is a JavaScript object with comment ID and text. For example you can find the unique comment ID and comment text for further analysis the following way:

var disqus_config = function () {
    this.callbacks.onNewComment = [function(comment) { 
      alert(comment.id);
      alert(comment.text);
    }];
}

Example within Full Embed Code

<div id="disqus_thread"></div>
<script>
    /**
     *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
     *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables
     */
    
    var disqus_config = function () {
        this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
        this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
        this.callbacks.onNewComment = [function(comment) {
              alert(comment.id);
              alert(comment.text);
        }];
    };
    
    (function() {  // DON'T EDIT BELOW THIS LINE
        var d = document, s = d.createElement('script');
        
        s.src = '//EXAMPLE.disqus.com/embed.js';
        
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
Ask the Community Contact us

Still need help? Discuss Disqus is our most active place for getting quick help, sharing feedback, and discussing issues with others – a knowledgeable and helpful support team and community are there right now. Our 101 post is the best place to get started.

Make sure to search our Knowledge Base first... your answer might be just a click away!