Skip to content

Instantly share code, notes, and snippets.

@dingram
Created September 10, 2012 14:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dingram/3691187 to your computer and use it in GitHub Desktop.
Save dingram/3691187 to your computer and use it in GitHub Desktop.
A minimalist way of including social JavaScript SDKs into a page. Includes Google Analytics, Twitter widgets, Facebook, and Google +1
window.___gcfg={lang:'en-GB'};var _gaq=_gaq||[];_gaq.push(['_setAccount','UA-123456-9']);_gaq.push(['_trackPageview']);!function(d,s){var st=d.getElementsByTagName(s)[0],j=function(i,u){if(d.getElementById(i))return;var js=d.createElement(s);js.id=i;js.async=true;js.src=u;st.parentNode.insertBefore(js,st)};setTimeout(function(){j("twitter-wjs","//platform.twitter.com/widgets.js");j("facebook-jssdk","//connect.facebook.net/en_GB/all.js#xfbml=1");j("gplusone-sdk","https://apis.google.com/js/plusone.js")}, 0);j("ga-sdk",('https:'==d.location.protocol?'https://ssl':'http://www')+'.google-analytics.com/ga.js')}(document,'script');
window.___gcfg = {lang: 'en-GB'};
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-123456-9']);
_gaq.push(['_trackPageview']);
!function(d,s){
var st = d.getElementsByTagName(s)[0],
j = function(id, url){
if (d.getElementById(id)) return;
var js=d.createElement(s);
js.id=id; js.async=true; js.src=url;
st.parentNode.insertBefore(js,st);
};
setTimeout(function(){
j("twitter-wjs", "//platform.twitter.com/widgets.js");
j("facebook-jssdk", "//connect.facebook.net/en_GB/all.js#xfbml=1");
j("gplusone-sdk", "https://apis.google.com/js/plusone.js");
}, 0);
// Keep Analytics on the main thread so there's no chance of losing analytic data from the user interacting with the page before the script loads
j("ga-sdk", ('https:'==d.location.protocol?'https://ssl':'http://www')+'.google-analytics.com/ga.js');
}(document,'script');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment