ga-tracker-snippet
Generate a code snippet to create a Google Analytics tracker object
;
yields:
;;
Installation
Package managers
npm
npm install ga-tracker-snippet
bower
bower install ga-tracker-snippet
Duo
var gaTrackerSnippet = ;
Standalone
Download the standalone build.
API
gaTrackerSnippet([options])
options: Object
Return: String
It returns a string of JavaScript code which creates a tracker object of Google Universal Analytics.
; //=> 'ga(\'create\', \'UA-XXXXX-X\', \'auto\');\nga(\'send\', \'pageview\');'
options.id
Type: String
Default: XXXXX-X
Set web property ID. UA-
prefix maybe omitted.
; //=> 'ga(\'create\', \'UA-36461297-9\', ... ' === ; //=> true
options.domain
Type: String
Default: auto
Set domain of the site.
;//=> 'ga(\'create\', \'UA-XXXXX-X\', \'foo.example.com\');\nga(\'send\', \'pageview\');'
options.globalName
Type: String
Default: ga
Change the global function name.
;//=> '__tracker(\'create\', \'UA-XXXXX-X\', \'auto\');\n__tracker(\'send\', \'pageview\');'
options.minify
Type: Boolean
Default: false
Omit whitespaces and newlines from the result.
options.singleQuotes
Type: Boolean
Default: true
false
replaces all single quotes with double quotes.
gaTrackerSnippet([id, domain])
A simple alias using two strings as its arguments instead of an object.
;//=> 'ga(\'create\', \'UA-36461297-9\', \'foo.example.com\');\nga(\'send\', \'pageview\');'
CLI
You can use this module as a CLI tool by installing it globally.
npm install -g ga-tracker-snippet
Usage
Usage: ga-tracker-snippet [options] Options:--id, -i Set web property ID--domain, -d Set domain --global, -g Change the global --minify, -m Omit whitespaces and newlines from output--double, -w Use double quotes --help, -h Print usage information--version, -v Print version
License
Copyright (c) 2014 Shinnosuke Watanabe
Licensed under the MIT License.