-
-
Save pareshsojitra/ec93c947b914cc780f9641aa8b4e6a44 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