0.0.1 • Published 4 years ago

google-analytics-lite v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

google-analytics-lite npm GitHub JavaScript Style Guide

A lightweight google Analytics module.

Features

  • Lightweight
  • TypeScript support

Why?

Most other modules (such as universal-analytics and electron-google-analytics) are too large (more than 1MB) after packaging due to the import of module request, these modules also do not support TypeScript.

Install

npm install google-analytics-lite

Usage

Init

new GoogleAnalytics(tid: string, cid?: string, fetcher?: typeof fetch, root?: string)

import GoogleAnalytics from 'google-analytics-lite'

const ga = new GoogleAnalytics('UA-123456-1')

Default values

By editing gs.defaultValues:

Object.assign(gs.defaultValues, {
  an: 'My App',
  aid: 'com.company.app'
})

Protocol

pageView(dl: string, dh?: string, dp?: string, other?: GAParameters)

ga.pageView('http://examples.com/a.html').then(console.log)

event(ec: string, ea: string, el?: string, ev?: number, other?: GAParameters)

ga.event('audio', 'Play')

exception(exd?: string, exf?: boolean, other?: GAParameters)

ga.exception('Audio play exception')

social(sn: string, sa: string, st: string, other?: GAParameters)

ga.social('facebook', 'like', 'http://example.com/myApp')

Other

ga.post({ cn: 'xxx', cs: 'xxx' }) // ga.post(data: GAParameters)

If you need other protocols, please contact me through github issue! :)

Utils

import { assign, genUUID, random } from 'google-analytics-lite'

random(4) // Random string
genUUID() // Random UUID
assign(obj1, obj2) // Assign two objects

Author

Shirasawa

License

MIT