WordPress.org

Ready to get started?Download WordPress

Forums

Jetpack by WordPress.com
Hook into successful Comments & Sharing (3 posts)

  1. digitalknave
    Member
    Posted 1 year ago #

    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.

    http://wordpress.org/extend/plugins/jetpack/

  2. Tim Moore
    Moderator
    Plugin Author

    Posted 1 year ago #

    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.

  3. digitalknave
    Member
    Posted 1 year ago #

    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%)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic