ga-tracker-snippet

1.0.0 • Public • Published

ga-tracker-snippet

Build Status Build status Coverage Status Dependency Status devDependency Status

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 version

npm install ga-tracker-snippet

bower Bower version

bower install ga-tracker-snippet

Duo

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'}); //=> true

options.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-snippet

Usage

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 version

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT License.

Package Sidebar

Install

npm i ga-tracker-snippet

Weekly Downloads

9

Version

1.0.0

License

none

Last publish

Collaborators

  • shinnn