Skip to content

Instantly share code, notes, and snippets.

@badcrocodile
Last active August 29, 2015 14:03
Show Gist options
  • Save badcrocodile/a53f9ba9265d493b80fc to your computer and use it in GitHub Desktop.
Save badcrocodile/a53f9ba9265d493b80fc to your computer and use it in GitHub Desktop.
A facebook share button that supports custom GA event tracking.
<!-- https://developers.facebook.com/docs/sharing/reference/share-dialog -->
<div id="shareButton" data-href="<?php echo $bar_fb_url_conf; ?>" style="outline:1px solid red; width: 86px; height:20px; position: relative;"></div>
<script>
$('#shareButton').click(function() {
FB.ui({
method: 'share',
href: $(this).data('href'),
}, function(response){
if (response === null) {
console.log('was not shared');
} else {
console.log('shared - post id is ' + response.post_id);
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment