Coder Social home page Coder Social logo

ganalytics's Introduction

ganalytics Build Status

A tiny (312B) client-side module for tracking with Google Analytics

This module exposes three module definitions:

  • ES Module: dist/ganalytics.mjs
  • CommonJS: dist/ganalytics.js
  • UMD: dist/ganalytics.min.js

Please see Releases for changelog!

Install

$ npm install --save ganalytics

Usage

const GAnalytics = require('ganalytics');

const ga = new GAnalytics('UA-XXXXXXXX-X', { aid:1 });
// or
const ga = GAnalytics('UA-XXXXXXXX-X', { aid:1 });

ga.send('pageview');
ga.send('pageview', { dt:'Foobar', dp:'/foo' });

ga.send('event', { ec:'Video', ea:'Play', el:'Home Hero' });

API

GAnalytics(trackerID, options, toWait)

trackerID

Type: String

Your Google Analytics tracker ID; eg UA-XXXXXXXX-X

options

Type: Object

Any common, general options that this instance should hold onto.

Note: Any option key can be redefined or overwritten within a send() call.

options.aip

Type: Integer
Default: 0

Anonymize the sender's IP address. See Anonymize IP.

options.an

Type: String

Specifies the application's name. See Application Name.

options.aid

Type: String

Specifies the application identifier. See Application ID.

options.aiid

Type: String

Specifies the application installer identifier. See Application Installer ID.

options.av

Type: String

Specifies the application verison. See Application Version.

options.cid

Type: String

Anonymously identify a particular user, device, or browser instance. This should be persisted so that repetitive session use the same identifier. See Client ID.

Important This is required when options.uid is not defined.

options.uid

Type: String

An identifier for a known user, if possible. This value should never be persisted. See User ID.

Important This is required when options.cid is not defined.

options.ds

Type: String

Indicates the data source type of the hit; eg web or app. See Data Source.

toWait

Type: Boolean
Default: false

When truthy, a pageview event will not be sent immediately upon initialization.

ga.send(type, params)

type

Type: String

The type of hit to send. Must be one of these: pageview, screenview, event, transaction, item, social, exception, or timing.

params

Type: Object

The parameters to send based on the type of hit.

Please follow the links for each available parameter set:

For pageview hits only, if no params are provided, then the document.title and location.href values will be auto-filled. This allows you to send valid requests by writing:

ga.send('pageview');
// is the same as:
//=> ga.send('pageview', { dt:document.title, dl:location.href })

License

MIT © Luke Edwards

ganalytics's People

Contributors

santa512 avatar

Stargazers

 avatar Minion0219 avatar Keysven avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.