Create a gist now

Instantly share code, notes, and snippets.

Google Analytics Tracking of JetPack (Sharedaddy) Social Engagement
<?php
/**
* Plugin Name: Jetpack (Sharedaddy) Google Analytics Tracking
* Description: Allows tracking of Facebook and Twitter shares in Google Analytics Social Tracking
* Author: Benjamin J. Balter
* Author URI: http://ben.balter.com
* Version: 0.1
*/
/**
* Outputs javascript to document head
*/
function bb_ga_social_footer() { ?>
<script>
jQuery(document).ready(function($) {
//twitter
$('a.share-twitter').click(function(){
_gaq.push( ['_trackSocial', 'twitter', 'share',
$(this).attr('href').substr(0, $(this).attr('href').indexOf('?'))]);
});
//facebook
$('a.share-facebook').click( function() {
_gaq.push( ['_trackSocial', 'faceboook', 'share',
$(this).attr('href').substr(0, $(this).attr('href').indexOf('?'))]);
});
});
</script>
<?php }
//add our hook with higher-than-default priority
add_action('wp_footer', 'bb_ga_social_footer', 20)
/**
* Require WP to load jQuery if not already loaded
* h/t @Ramoonus
*/
function bb_ga_social_enqueue() {
wp_enqueue_script("jquery");
}
//add hook to enqueue jQuery on load
add_action('init', 'bb_ga_social_enqueue');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment