Skip to content

Instantly share code, notes, and snippets.

@benbalter
Last active September 26, 2015 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benbalter/1058469 to your computer and use it in GitHub Desktop.
Save benbalter/1058469 to your computer and use it in GitHub Desktop.
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