Skip to content

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

License

Notifications You must be signed in to change notification settings

usermirror/analytics-event

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published