Lazyload Facebook and events (uses jQuery and waypoints, sadly)
(function() {
function page_like(url, html_el) {
ga('send', 'event', 'Facebook', 'like', url);
}
function page_dislike(url, html_el) {
ga('send', 'event', 'Facebook', 'unlike', url);
}
function page_comment(response) {
ga('send', 'event', 'Facebook', 'commented', response.href);
}
function page_uncomment(response) {
ga('send', 'event', 'Facebook', 'uncomment', response.href);
}
function fb_ga_glue_events() {
FB.Event.subscribe('edge.create', page_like);
FB.Event.subscribe('edge.remove', page_dislike);
FB.Event.subscribe('comment.create', page_comment);
FB.Event.subscribe('comment.remove', page_uncomment);
}
function fbLoad() {
var d = document, s = 'script', id = 'facebook-jssdk';
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/es_LA/sdk.src#xfbml=1&version=v2.10&appId=1206212556115950";
fjs.parentNode.insertBefore(js, fjs);
window.fbAsyncInit = function() {
FB.init({
appId : '1206212556115950',
xfbml : true,
version : 'v2.10'
});
FB.AppEvents.logPageView();
};
}
(function($){
$(document).ready(function($) {
window.wayp = $('.widget.fb-lazy-likebox').waypoint(function(direction) {
var el = $(this.element).find('.lazy-likebox-placeholder');
el.addClass('fb-page');
fbLoad();
this.destroy();
}, { offset: 'bottom-in-view' });
});
})(jQuery);
}());