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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ga-tracker

v1.3.0

Published

A google analytics e-commerce wrapper for javascript

Readme

Google Analytics EC Wrapper

A javascript class designed to wrap google analytics enhanced e-commerce

It provides an unified api for both universal tracking and global site. It also keeps track of steps and lists automatically (uses localStorage)

Installation

Using npm

npm install ga-tracker

**or yarn

yarn add ga-tracker

and then import it in your projects

import GaTracker from 'ga-tracker'

Alternatively you can include a script tag point to the standalone version

<scrpit src="node_modules/ga-tracker/dist/ga-tracker.min.js"></scrpit>

Initialisation

Create a new instance of GaTracker and pass your analytics id as your first param

<script>
	var ga = new GaTracker('UA-456465-I')
</script>

or if using node

import GaTracker from 'ga-tracker'

const ga = new GaTracker('UA-456465-I')

By default it uses Universal Tracking if you want to use Global Site Tag set the second param to gtag

<script>
	var ga = new GaTracker('UA-456465-I', 'gtag')
</script>

or if using node

import GaTracker from 'ga-tracker'

const ga = new GaTracker('UA-456465-I', 'gtag')

If you already initialised Google analytics using either Universal Analytics or Global Site Tag leave the first param blank.

<script>
	var ga = new GaTracker(null, 'gtag')
</script>

or if using node

import GaTracker from 'ga-tracker'

const ga = new GaTracker(null, 'gtag')

Usage

I assume you know what each event does so I wont get into details about they are. I will instead show implementation examples.

List Impressions

var l = ga.collection()
l.setListName('My First List')

Then add some products

l.addJson({
	"id": "P12345",
	"name": "Android Warhol T-Shirt",
	"brand": "Google",
	"category": "Apparel/T-Shirts",
	"variant": "Black",
	"position": 1,
	"quantity": 2,
	"price": 2
})

var p = ga.product({
	"id": "P67890",
	"name": "Flame challenge TShirt",
	"brand": "MyBrand",
	"category": "Apparel/T-Shirts",
	"variant": "Red",
	"position": 2,
	"quantity": 1,
	"price": 3
})

l.addProduct(p)
l.impression()

Product

Impression

var p = ga.product({
	"id": "P67890",
	"name": "Flame challenge TShirt",
	"brand": "MyBrand",
	"category": "Apparel/T-Shirts",
	"variant": "Red",
	"position": 2,
	"quantity": 1,
	"price": 3
})

p.impression()

Click

<button type="button" onclick="p.click()">Go To Product</button>

Add To Basket

<script>
	var c = ga.cart()
	var p = ga.product({
		"id": "P67890",
		"name": "Flame challenge TShirt",
		"brand": "MyBrand",
		"category": "Apparel/T-Shirts",
		"variant": "Red",
		"position": 2,
		"quantity": 1,
		"price": 3
	})
</script>
<button type="button" onclick="c.add(p)">Add To Basket</button>

Remove From Basket

<script>
	var c = ga.cart()
	var p = ga.product({
		"id": "P67890",
		"name": "Flame challenge TShirt",
		"brand": "MyBrand",
		"category": "Apparel/T-Shirts",
		"variant": "Red",
		"position": 2,
		"quantity": 1,
		"price": 3
	})
</script>
<button type="button" onclick="c.remove(p)">Remove From Basket</button>

Promotions (AKA Coupon)

Impression

var promo = ga.promotion({
	"id": "abc123",
	"name": "summer_promo"
})
promo.impression()

Click

<script>
var promo = ga.promotion({
	"id": "abc123",
	"name": "summer_promo"
})
</script>
<div class="container">
	Lorem ipsum text
	<button type="button" class="cta" onclick="promo.click()">Claim Your Coupon</button>
</div>

Checkout

Begin

var tracker = new GaTracker()
var product1 = tracker.product({
	"id": "P12345",
	"name": "Android Warhol T-Shirt",
	"brand": "Google",
	"category": "Apparel/T-Shirts",
	"variant": "Black",
	"position": 1,
	"quantity": 1,
	"price": 2
})
var product2 = tracker.product({
	"id": "P67890",
	"name": "Flame challenge TShirt",
	"brand": "MyBrand",
	"category": "Apparel/T-Shirts",
	"variant": "Red",
	"position": 2,
	"quantity": 1,
	"price": 3
})
var checkout = tracker.checkout()
checkout
	.setItems([product1.getJson(), product2.getJson()])
	.begin()

Progress

var tracker = new GaTracker()
var product1 = tracker.product({
	"id": "P12345",
	"name": "Android Warhol T-Shirt",
	"brand": "Google",
	"category": "Apparel/T-Shirts",
	"variant": "Black",
	"position": 1,
	"quantity": 1,
	"price": 2
})
var product2 = tracker.product({
	"id": "P67890",
	"name": "Flame challenge TShirt",
	"brand": "MyBrand",
	"category": "Apparel/T-Shirts",
	"variant": "Red",
	"position": 2,
	"quantity": 1,
	"price": 3
})
var checkout = tracker.checkout()
checkout
	.setItems([product1.getJson(), product2.getJson()])
	.progress()

You can progress as many times as you need. It will keep adding steps to the checkout. In case you need to implicitly set the step pass it as a parameter on the progress method

checkout.progress(2)

Options

var tracker = new GaTracker()
var checkout = tracker.checkout()
checkout.option('Payment Method', 'AMEX')

Transaction

var tracker = new GaTracker()
var product1 = tracker.product({
	"id": "P12345",
	"name": "Android Warhol T-Shirt",
	"list": "Search Results",
	"brand": "Google",
	"category": "Apparel/T-Shirts",
	"variant": "Black",
	"position": 1,
	"quantity": 1,
	"price": 2
})
var product2 = tracker.product({
	"id": "P67890",
	"name": "Flame challenge TShirt",
	"list": "Search Results",
	"brand": "MyBrand",
	"category": "Apparel/T-Shirts",
	"variant": "Red",
	"position": 2,
	"quantity": 1,
	"price": 3
})
var checkout = tracker.checkout()
checkout
	.setItems([product1.getJson(), product2.getJson()])
	.purchase('T20', null, value = 20, 'GBP', 20, 0)

Refunds

var tracker = new GaTracker()
var refund = tracker.refund()
refund.refund('T20')

Licence

GPL 3.0

Credits

Thank you to hussle.com that allowed me to share this library originally developed for internal use.

Keywords

Google Analytics Tracking