npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ga-tracker-snippet

v1.0.0

Published

Generate a code snippet to create a Google Analytics tracker object

Downloads

110

Readme

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.