Support » Plugins and Hacks » Jetpack by WordPress.com » Hook into successful Comments & Sharing

Hook into successful Comments & Sharing

  • I want to fire some analytics code when a comment has been successfully added (happy if its when submit is clicked and not after any approval, etc) and also when one of the share buttons is clicked.

    Things like Contact Form 7 have a setting where you can add some JS for a specific hook (i.e. on_sent_ok).

    Is there anything similar I can do for JetPack comments and Shares? I’m sure I’m not the only person who wants to be able to track this sort of thing.


Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Tim Moore


    For Sharing, each of the Sharing icons has a unique ID and a class name. You could write JS to attach to that, which waits for a click event, then tracks stats.

    For Comments, you can look at the wp-comments-post.php file. There’s a filter, comment_post_redirect, which is one of the last filters that occurs before a comment is posted. You could likely attach to that to do what you want.

    Tim – not quite as simple as that. The share buttons are all accessed via iframes loading content from the respective social sites themselves. Each social site has their own way of doing things so there’s no real standardisation.

    The iFrames are child elements of list items (li) with a class that starts “share-” and I tried targeting those with an click event but it doesn’t work.

    Ideally it would be great if the JetPack team added the functionality somehow to call a JS function when the various buttons are clicked (or added in some kind of hook) and passed an argument (or allowed a token) which identified which social site an article had been shared with.

    For example:
    on_share: my_log_share_event(%button_clicked%)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hook into successful Comments & Sharing’ is closed to new replies.