Skip to content

Instantly share code, notes, and snippets.

@seyna
Created February 12, 2014 09:50
Show Gist options
  • Save seyna/8952662 to your computer and use it in GitHub Desktop.
Save seyna/8952662 to your computer and use it in GitHub Desktop.
Facebook 分享 callback + log GA event
// reference: https://developers.facebook.com/docs/javascript/reference/FB.ui#examples
// reference: https://gist.github.com/niraj-shah/5560832
function fb_share() {
FB.ui( {
method: 'feed',
name: "Glorious Sharing",
link: "http://seyna.tumblr.com",
picture: "http://static.tumblr.com/fkm6sn6/59Xlce272/header_white.png",
caption: "Seyna Tumblr sharing test"
},
function(response) {
console.log('callback was called!');
if ( response && response.post_id ) {
console.log( "sharing success" );
// asynchronous call to log GA event
_gaq.push(['_trackEvent', 'facebook', 'share', 'seyna tumblr']);
} else {
console.log( "sharing failed" );
}
} );
}
$(document).ready(function(){
$('.share-btn').on( 'click', fb_share );
});
window.fbAsyncInit = function() {
FB.init({
appId : '1452187671671193', // replace to yours
status : true,
xfbml : true
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment