Skip to content

Instantly share code, notes, and snippets.

@mathiasbynens
Forked from 140bytes/LICENSE.txt
Created May 23, 2011 07:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathiasbynens/986371 to your computer and use it in GitHub Desktop.
Save mathiasbynens/986371 to your computer and use it in GitHub Desktop.
Google Analytics snippet in 140 bytes
function(){with(document)body.appendChild(createElement('script')).src='//mths.be/g',_gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']]}
Author: Mathias Bynens <http://mathiasbynens.be/>
This code is licensed under the WTFPL. Feel free to relicense as needed.
{
"name": "googleAnalytics",
"keywords": [
"google",
"analytics",
"google analytics",
"tracking"
]
}
@jed
Copy link

jed commented May 23, 2011

hmmm, it really needs to be assignable. how about:

function(){with(document)body.appendChild(createElement('script')).src='//mths.be/g',_gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']]}

or this

((_gaq=document).body.appendChild(_gaq.createElement('script')).src='//mths.be/g',_gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']]})

@mathiasbynens
Copy link
Author

Great stuff, @jed!

Note that this snippet breaks the following 140bytes rules:

  • no globals → _gaq is required to be global for Google Analytics to work correctly
  • MIT license → IMHO, trivial code snippets like these shouldn’t be licensed — to be honest, I’m not even sure if it’s legally possible. I decided to go with the WTFPL license, which allows relicensing. Hope that’s okay.

@jed
Copy link

jed commented May 23, 2011

yeah,

  • by no globals, i mean no unintentional global leakage. JSONP also leaks, but that side-effect is its whole purpose.
  • as for the license, i just want to make sure it's permissive. how about we change the default license to the WTFPL?

@mathiasbynens
Copy link
Author

@jed +1 on making WTFPL the default. Makes much more sense, IMO.

@jed
Copy link

jed commented May 23, 2011

okay, i changed it. i just want to make sure it's permissive more than anything. not too thrilled putting profanity in each entry... can we link to the license instead?

@mathiasbynens
Copy link
Author

The WTFPL explicitly allows changing + renaming it:

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004

 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed.

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. You just DO WHAT THE FUCK YOU WANT TO.

Either way, just a link would be fine.

@jed
Copy link

jed commented May 23, 2011

would you mind drafting something generic with name/url placeholders that we can include?

@jed
Copy link

jed commented May 23, 2011

i also think you could save bytes and make this more useful by passing the UA-XXXXX-X id as a parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment