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.
$ npm install --save wrapped-analytics
import {
wrappedAnalytics,
googleGA,
googleGTAG,
} from 'wrapped-analytics';
const trackEvent = wrappedAnalytics([
googleGA,
googleGTAG,
]);
trackEvent('subscribe', {
category: 'subscriptionForms',
label: 'newsletter',
});
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.
IE9+