analytics-event

1.1.0 • Public • Published

analyticsEvent

A tiny utility for working with analytics events
on the server and in the browser.



Getting Started

Installation

Install with npm:

npm install --save analytics-event

Or with yarn:

yarn add analytics-event

Examples

import AEvent from 'analytics-event'
 
// Generate event from options 
AEvent({
  name: 'User Signed Up',
  properties: {
    referral_type: 'friend'
  }
})
 
// Use your favorite analytics library to send events
analytics.track(AEvent({
  name: 'User Signed Up',
  properties: {
    referral_type: 'friend'
  }
}))

Usage

Generating an event

import AEvent from 'analytics-event'
 
// Generate an event that follows https://schema.org/AnalyticsEvent
AEvent({
  name: 'User Signed Up',
  properties: {
    referral_type: 'friend'
  }
})

Formatting an event

import AEvent from 'analytics-event'
 
// You can also just import the format function with:
// import { format, loadFormat } from 'analytics-event'
import internalDataFormat from './internal-data-format'
 
AEvent.loadFormat('internal-data', internalDataFormat)
 
function receiveIncomingEvents(batch) {
  return batch.map(msg => AEvent.format(msg, {
    preset: 'internal-data'
  }))
}

Contributing

All contributions are super welcome! analytics-event is MIT-licensed.

Package Sidebar

Install

npm i analytics-event

Weekly Downloads

4

Version

1.1.0

License

MIT

Unpacked Size

64.9 kB

Total Files

9

Last publish

Collaborators

  • fouad