Skip to content

Instantly share code, notes, and snippets.

Forked from necolas/snippet.js
Last active Aug 29, 2015
What would you like to do?
* Updated to use the function-based method described in
* Better handling of scripts without supplied ids.
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
add = function(url, id) {
if (doc.getElementById(id)) {return;}
js = doc.createElement(script);
js.src = url;
id && ( = id);
fjs.parentNode.insertBefore(js, fjs);
// Google Analytics
add(('https:' == location.protocol ? '//ssl' : '//www') + '', 'ga');
// Google+ button
// Facebook SDK
add('//', 'facebook-jssdk');
// Twitter SDK
add('//', 'twitter-wjs');
}(document, 'script'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment