Tracking Social Events

Thanks to Tristan at grasshopperherder.com for compiling this list.

How do I track Facebook events?

The Facebook social plugins emit a number of events, most importantly the edge.create event. This is triggered when a user clicks a Like button on your page. If you are using the Facebook JavaScript SDK (rather than a plugin that inserts an iFrame),you can use the following snippet:

<script type="text/javascript">
  FB.Event.subscribe('edge.create', function(response) {
    _kmq.push(['record', 'Facebook like']);
  });
</script>

You should paste this code below wherever you include the button.

Facebook’s Developers portal has more up-to-date examples of how best to use their API: https://developers.facebook.com/docs/reference/javascript/

Other events are documented here: http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

How do I track Twitter events?

Tracking Twitter events is very similar to Facebook tracking.

<script type="text/javascript">
  twttr.events.bind('follow', function(event) {
    _kmq.push(['record', 'Twitter follow']);
  });
</script>
<script type="text/javascript">
  twttr.events.bind('tweet', function(event) {
    _kmq.push(['record', 'Tweeted']);
  });
</script>

A full list of events you can track is in the Twitter dev docs: https://dev.twitter.com/docs/intents/events

How do I track Google +1 (plusone)?

It’s easiest to add the tracking when you create your button: https://developers.google.com/search/blog/2011/03/introducing-1-button

Click on “Advanced Options” and enter “plusone_vote” into the “JS Callback Function” field.

<script type="text/javascript">
  function plusone_vote( obj ) {
    _kmq.push(['record', 'Plus 1 vote']);
  }
</script>

How do I track LinkedIn shares?

This currently requires an undocumented feature, so keep in mind that this might change in the future.

Start by creating your button on the LinkedIn dev pages. Inside the “IN/Share” tag section you need to add the data-onSuccess callback function.

<script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/Share" data-url="http://www.streamhead.com/"
  data-counter="right" data-onSuccess="linkedin_share"></script>
<script type="text/javascript">
function linkedin_share() {
  _kmq.push(['record', 'Shared on LinkedIn']);
}
</script>