Package Exports
- ga-tracker-snippet
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ga-tracker-snippet) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ga-tracker-snippet
Generate a code snippet to create a Google Analytics tracker object
gaTrackerSnippet({id: '36461297-9', domain: 'shinnn.github.io'});yields:
ga('create', 'UA-36461297-9', 'shinnn.github.io');
ga('send', 'pageview');Installation
Package managers
npm 
npm install ga-tracker-snippetbower 
bower install ga-tracker-snippetDuo
var gaTrackerSnippet = require('shinnn/ga-tracker-snippet');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.
gaTrackerSnippet(); //=> 'ga(\'create\', \'UA-XXXXX-X\', \'auto\');\nga(\'send\', \'pageview\');'options.id
Type: String
Default: XXXXX-X
Set web property ID. UA- prefix maybe omitted.
gaTrackerSnippet({id: '36461297-9'}); //=> 'ga(\'create\', \'UA-36461297-9\', ... '
gaTrackerSnippet({id: 'UA-36461297-9'}) === gaTrackerSnippet({id: '36461297-9'}); //=> trueoptions.domain
Type: String
Default: auto
Set domain of the site.
gaTrackerSnippet({domain: 'foo.example.com'});
//=> 'ga(\'create\', \'UA-XXXXX-X\', \'foo.example.com\');\nga(\'send\', \'pageview\');'options.globalName
Type: String
Default: ga
Change the global function name.
gaTrackerSnippet({globalName: '__tracker'});
//=> '__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.
gaTrackerSnippet('36461297-9', 'foo.example.com');
//=> '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-snippetUsage
Usage: ga-tracker-snippet [options]
Options:
--id, -i Set web property ID
--domain, -d Set domain ("auto" by default)
--global, -g Change the global function name ("ga" by default)
--minify, -m Omit whitespaces and newlines from output
--double, -w Use double quotes (single quotes by default)
--help, -h Print usage information
--version, -v Print versionLicense
Copyright (c) 2014 Shinnosuke Watanabe
Licensed under the MIT License.