Created
December 21, 2015 17:01
-
-
Save devinsays/e9a5a42c1416b16f8bae to your computer and use it in GitHub Desktop.
Track JetPack Shares in Google Analytics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Javacript for loading custom Google Analytics events | |
* | |
* @since 1.0.0 | |
*/ | |
(function($) { | |
// GA Docs for Social Interactions: | |
// https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions | |
if ( typeof(ga) == "function" ) { | |
$('a.share-twitter').on( 'click', function() { | |
ga( 'send', { | |
hitType: 'social', | |
socialNetwork: 'Twitter', | |
socialAction: 'share', | |
socialTarget: $(this).attr('href').substr( 0, $(this).attr('href').indexOf('?') ) | |
}); | |
}); | |
$('a.share-facebook').on( 'click', function() { | |
ga( 'send', { | |
hitType: 'social', | |
socialNetwork: 'Facebook', | |
socialAction: 'share', | |
socialTarget: $(this).attr('href').substr( 0, $(this).attr('href').indexOf('?') ) | |
}); | |
}); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice gist! I've adapted it into a basic WordPress plugin here crediting your work in the README and code.