wrapped-analytics
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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+

Readme

Keywords

none

Package Sidebar

Install

npm i wrapped-analytics

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

25.2 kB

Total Files

25

Last publish

Collaborators

  • 44px