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

requirejs-google-analytics

vundefined

Published

Google Analytics loader

Readme

#requirejs-google-analytics Build Status Dependency Status DevDependency Status Bitdeli Badge

Asynchronously load Google Analytics using requirejs.

Setup

This module utilises requirejs module configuration. It requires the following JS to be added to the page

requirejs.config({
	config: {
		'GA': {
			'id' : 'ACCOUNT_ID'
		}
	},
    paths: {
        EventEmitter: 'bower_components/event-emitter/dist/EventEmitter'
        GA: 'bower_components/requirejs-google-analytics/dist/GoogleAnalytics'
    }
});

Installation

Installation via bower

{
  "dependencies": {
  	"requirejs-google-analytics": "~0.1.6"
  }
}

Usage

GA.ready(cb)

  • cb - (function) Callback to fire when Google Analytics is fully loaded
require(['GA'], function (GA) {
    GA.ready(function (ga) {
        // GA is fully loaded
        console.log(ga);
    });
});

GA.view(override)

Page Tracking

  • override (string/object) - Either a string to override the default page or an object to override the title/location as well

GA.event(category, action, label, value, fields)

Event Tracking

  • category (string) - Typically the object that was interacted with (e.g. button) - required
  • action (string) - The type of interaction (e.g. click) - required
  • label (string) - Useful for categorizing events (e.g. nav buttons)
  • value (number) - Values must be non-negative. Useful to pass counts (e.g. 4 times)
  • fields (object) - The field object is a standard JavaScript object, but defines specific field names and values accepted by analytics.js

GA.social(network, action, target, fields)

Social Interactions

  • network (string) - The network on which the action occurs (e.g. Facebook, Twitter) - required
  • action (string) - The type of action that happens (e.g. Like, Send, Tweet) - required
  • target (string) - Specifies the target of a social interaction. This value is typically a URL but can be any text (e.g. http://mycoolpage.com) - required
  • fields (number) - The field object is a standard JavaScript object, but defines specific field names and values accepted by analytics.js

GA.timing(category, action, label, value, fields)

User Timings

  • category (string) - A string for categorizing all user timing variables into logical groups (e.g jQuery) - required
  • var (string) - A string to identify the variable being recorded. (e.g. JavaScript Load) - required
  • value (number) - The number of milliseconds in elapsed time to report to Google Analytics (e.g. 20) - required
  • label (string) - A string that can be used to add flexibility in visualizing user timings in the reports (e.g. Google CDN)
  • fields (number) - The field object is a standard JavaScript object, but defines specific field names and values accepted by analytics.js

Ecommerce

GA.ecomTran(data)

Adding a Transaction

  • data (object) - an object with the following attributes:
    • id (string) - The transaction ID (e.g. 1234) - required
    • affiliation (string) - The store or affiliation from which this transaction occurred (e.g. Acme Clothing)
    • revenue (currency) - Specifies the total revenue / grand total associated with the transaction. This value should include any shipping or tax costs (e.g. 11.99)
    • shipping (currency) - Specifies the total shipping cost of the transaction (e.g. 5)
    • tax (currency) - Specifies the total tax of the transaction (e.g. 1.29)

GA.ecomItem(data)

Adding Items

  • data (object) - an object with the following attributes:
    • id (string) - The transaction ID (e.g. 1234) - required
    • name (string) - The item name (e.g. Fluffy Pink Bunnies) - required
    • sku (string) - Specifies the SKU or item code (e.g. SKU47)
    • category (string) - The category to which the item belongs (e.g. Party Toys)
    • price (currency) - The individual, unit, price for each item (e.g. 11.99)
    • quantity (currency) - The number of units purchased in the transaction (e.g. 1)

GA.ecomSend()

Sending Data

GA.ecomClear()

Clearing Data

Advanced Usage

GA.newTracker(config)

Multiple Trackers

  • config (object) - An object the same that would be specified in requirejs.config.config.GA

GA.set(field, value)

Fields

  • field (string/object) - Either a string containing the name of a field or a mapping of fields and values - required
  • value (any) - the value of the field

Create Only Fields

requirejs.config({
    config: {
        'GA': {
            'id' : 'ACCOUNT_ID',
            'fields': {
                // Create only fields go here:
                name: 'myTracker'
            }
        }
    },
    paths: {
        EventEmitter: 'bower_components/event-emitter/dist/EventEmitter'
        GA: 'bower_components/requirejs-google-analytics/dist/GoogleAnalytics'
    }
});

Experiments

requirejs.config({
    config: {
        'GA': {
            'id' : 'ACCOUNT_ID',
            // Experiment ID and Var go here:
            'expId' : $expermentId,
            'expVar' : $expermentVar,
        }
    },
    paths: {
        EventEmitter: 'bower_components/event-emitter/dist/EventEmitter'
        GA: 'bower_components/requirejs-google-analytics/dist/GoogleAnalytics'
    }
});