Skip to content

Instantly share code, notes, and snippets.

@pareshsojitra
Forked from devinsays/tracking.js
Created February 7, 2021 15:13
Show Gist options
  • Save pareshsojitra/ec93c947b914cc780f9641aa8b4e6a44 to your computer and use it in GitHub Desktop.
Save pareshsojitra/ec93c947b914cc780f9641aa8b4e6a44 to your computer and use it in GitHub Desktop.
Track JetPack Shares in Google Analytics
/**
* 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" ) {
// Twitter
$('a.share-twitter').on( 'click', function() {
ga( 'send', {
hitType: 'social',
socialNetwork: 'Twitter',
socialAction: 'share',
socialTarget: $(this).attr('href').substr( 0, $(this).attr('href').indexOf('?') )
});
});
// Facebook
$('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