Last active
October 5, 2015 22:27
-
-
Save googleanalyticsresoneo/2887422 to your computer and use it in GitHub Desktop.
AddThis and Google Analytics integration Async Syntax
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
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html> | |
<head> | |
<!-- | |
AddThis integration with Google Analytics Async - (c) 2013 analytics (chez) resoneo (point) com | |
https://gist.github.com/googleanalyticsresoneo/2887422 | |
see http://support.addthis.com/customer/portal/articles/1293805-using-addthis-asynchronously | |
--> | |
<script type="text/javascript"> | |
// standard GA async code | |
var _gaq = _gaq || []; | |
_gaq.push(['_setAccount', 'UA-YYYYYYY-XX']); | |
_gaq.push(['_trackPageview']); | |
(function () { | |
var ga = document.createElement('script'); | |
ga.type = 'text/javascript'; | |
ga.async = true; | |
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
var s = document.getElementsByTagName('script')[0]; | |
s.parentNode.insertBefore(ga, s); | |
})(); | |
</script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
// creates the options object for addthis | |
var addthis_config = addthis_config || {}; | |
addthis_config.pubid = 'YOUR PUBID'; // AddThis publisher ID, if applicable | |
addthis_config.data_ga_tracker = null; // unbind AddThis and GA | |
addthis_config.ui_click= true ; | |
_gaq.push(function () { | |
// once ga.js is loaded, bind YOUR tracker with addthis, don't let addthis create a new one | |
addthis_config.data_ga_property = null; | |
addthis_config.data_ga_tracker = _gat._getTrackerByName(); | |
addthis_config.data_ga_social = true; | |
// add the rest of Addthis config below | |
// let's load Addthis' script only once the configuration has been done | |
var adt = document.createElement('script'); | |
adt.type = 'text/javascript'; | |
adt.async = true; | |
adt.src = 'https://s7.addthis.com/js/300/addthis_widget.js#domready=1'; | |
var adte = document.getElementsByTagName('script')[0]; | |
adte.parentNode.insertBefore(adt, adte); | |
}); | |
</script> | |
<!-- AddThis Button BEGIN --> | |
<p>Actions on these buttons eventually get tracked to Google Analytics !</p> | |
<div class="addthis_toolbox addthis_default_style addthis_32x32_style"> | |
<a class="addthis_button_preferred_1"></a> | |
<a class="addthis_button_preferred_2"></a> | |
<a class="addthis_button_preferred_3"></a> | |
<a class="addthis_button_preferred_4"></a> | |
</div> | |
<!-- AddThis Button END --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment