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 }
 
// begin of my work
wp_enqueue_script("jquery");
// end of my hard work
//add our hook with higher-than-default priority
add_action('wp_footer', 'bb_ga_social_footer', 20)
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment