Awesome Open Source
Awesome Open Source


npm version Build Status Coverage Status

Generate Google Analytics code with any isogrammic parameters you like




Here is the default tracking code of Google Analytics.

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//','ga');

It has the immediate invoked function with seven parameters i s o g r a m.

On the other hand, the index.html of HTML5 Boilerplate includes the following tracking code:

(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;e=o.createElement(i);r=o.getElementsByTagName(i)[0];e.src='//';r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));

As you can see, its parameters are b o i l e r, different from the original's. This amusing alteration is authored by Mathias Bynens, based on the way of optimization and minification he blogged.

After seeing that, I modularized Bynens's way as this program, isogram.

What it does

isogram is a code generator. It enables us to change the parameters of the Google Analytics tracking code, as we like, as long as they are isogrammic.

Isn't it very useful? Indeed, it isn't. But, I think, isogram can surprise the people seeing the source code of your website, such as Bynens's commit.

Websites using isogram

The real-life examples that uses the code isogram generates in their pages

Website (A - Z) URL Tracking code parameters
apiDoc a p i d o c
BrowserSync s y n c I t
Chris Down's website c d o w n L I C e N S E
cssnext c s S n e x t
Dogescript W o w s u c h
Donavon West's blog D o N a V O n
Go, muffins go! M U F f I N S
gulp.js g u l p j s
hapi h a p i j s i n k t w e b
Jekyll j e k y l L k a n y e
starico s t a r i c o
Tim De Pauw's website t m d p w e u
Zachary Espiritu's website z a c h A r y

Feel free to create a pull request to add your site here.



Use npm.

npm install --global isogram


isogram [parameters] [options]


Default: GoOgle

[parameters] need to be a nonpattern word with no fewer than 3 and no greater than 7 characters, each of whom can be a valid JavaScript variable name.

For example, yummy is not valid, but YuMmy is valid.


--id,       -i <ID>      Set web property ID
--domain,   -d <domain>  Set domain
--global,   -g <name>    Change global variable name ("ga" by default)
--double,   -w           Use double quotes (single quotes by default)
--minify,   -m           Minify output like UglifyJS
--no-color,              Print code in a single color
--color,    -c           Colorize parameters anyway (enabled by default)
--no-track,              Just load, don't send a pageview
--track,    -t           Send a pageview after loading (enabled by default)
--help,     -h           Print usage information
--version,  -v           Print version


isogram YoyOjs --id 12345678-9 --domain


(Y[y].q=Y[y].q||[]).push(arguments)});Y[y].l=+new Date;j=o.createElement(O);

ga('create', 'UA-12345678-9', '');
ga('send', 'pageview');


You can use isogram as a JavaScript library instead of CLI.


Package managers

npm install isogram


Download the standalone build.


isogram([parameters, options])

parameters: String (3 or more and 7 or less characters)
options: Object
Return: String

It returns a string of Google Analytics JavaScript code.

// Default
isogram(); //=> '!function(G,o,O,g,l,e){G.GoogleAnalyticsObject=O,G[O]||(G[O]=function(){\n(G[O].q=G[O].q||[]).push(arguments)}),G[O].l=+new Date,l=o.createElement(g),\ne=o.getElementsByTagName(g)[0],l.src=\'//\',\ne.parentNode.insertBefore(l,e)}(window,document,\'ga\',\'script\');\n\nga(\'create\', \'UA-XXXXX-X\', \'auto\');\nga(\'send\', \'pageview\');'

// Specify parameters
isogram('abcdef'); //=> '!function(a,b,c,d,e,f){a.GoogleAnalyticsObject=c,a[c]||(a[c]=function(){\n(a[c].q=a[c].q||[]).push(arguments)}),a[c].l=+new Date,e=b.createElement(d),\nf=b.getElementsByTagName(d)[0],e.src=\'//\',\nf.parentNode.insertBefore(e,f)}(window,document,\'ga\',\'script\');\n\nga(\'create\', \'UA-XXXXX-X\', \'auto\');\nga(\'send\', \'pageview\');'

Type: String
Default: XXXXX-X

Set web property ID. UA- prefix maybe omitted.

isogram({id: '36461297-9'}); //=> '!function( ... , \'UA-36461297-9\', \'auto\');\nga(\'send\', \'pageview\');'

isogram({id: 'UA-36461297-9'}) === isogram({id: '36461297-9'}); //=> true

Type: String
Default: auto

Set domain of the site.

isogram({domain: ''}); //=> '!function( ... , \'\');\nga(\'send\', \'pageview\');'

Type: String
Default: ga

Change the global function name.

isogram({globalName: '__tracker'}); //=> '!function( ... ,document,\'__tracker\',\'script\');\n\n__tracker(\'create\', \'UA-XXXXX-X\', \'auto\');\n__tracker(\'send\', \'pageview\');'

Type: Boolean
Default: false

Omit unnecessary whitespaces and newlines from the result.


Type: Boolean
Default: true

false replaces all single quotes with double quotes.


Type: Boolean
Default: false

Colorize the parameters with ANSI escape code.


Type: Boolean
Default: true

false excludes create and send commands after the loading code.


Copyright (c) 2013 - 2018 Shinnosuke Watanabe

Licensed under the MIT License.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
javascript (69,927
nodejs (3,761
cli (1,768
code-generator (109
ecmascript (91
google-analytics (75