1.0.0 • Published 6 years ago

wrapped-analytics v1.0.0

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

wrapped-analytics

Small wrapper for external analytics scripts, made for embeddable widgets. It detects installed web analytics scripts and provides unified API for reporting events from your widget.

Install

$ npm install --save wrapped-analytics

Usage

import {
  wrappedAnalytics,
  googleGA,
  googleGTAG,
} from 'wrapped-analytics';

const trackEvent = wrappedAnalytics([
  googleGA,
  googleGTAG,
]);

trackEvent('subscribe', {
  category: 'subscriptionForms',
  label: 'newsletter',
});

API Reference

All adapters have same API:

trackEvent(
  event,            // Event to track (string)
  eventProperties,  // Optional event properties
);

// Each field here is optional too
eventProperties = {
  category, 
  label,
  value,
};

wrappedAnalytics accepts list of adapters and produce a single trackEvent function which passes data to each of registered adapters.

Browser support

IE9+