bernie-plugin-analytics
v1.5.1
Published
A React-based utility package for integrating Bernie analytics into applications.
Maintainers
Readme
bernie-plugin-analytics
A React-based utility package for integrating Bernie analytics into your application. It provides context providers and tracking functions to manage and send clickstream events.
Features
- BernieAnalyticsProvider: Context provider for sharing analytics configuration across your React app.
- useBernieAnalyticsContext: Hook to access the current analytics instance from any component.
- trackEvent: Function to manually track clickstream events with customizable namespace, referrers, and link names.
Installation
npm install bernie-plugin-analyticsor with yarn:
yarn add bernie-plugin-analyticsUsage
Providing Analytics Context
Wrap your application (or a specific part of it) with BernieAnalyticsProvider to make the analytics instance available to child components.
import React from 'react';
import { BernieAnalyticsProvider } from 'bernie-plugin-analytics';
const App = () => {
const analyticsInstance = {
// Your analytics configuration/instance
};
return (
<BernieAnalyticsProvider analytics={analyticsInstance}>
<YourAppComponent />
</BernieAnalyticsProvider>
);
};Using Analytics Context
Access the analytics instance from any functional component using the useBernieAnalyticsContext hook.
import React from 'react';
import { useBernieAnalyticsContext } from 'bernie-plugin-analytics';
const TrackingComponent = () => {
const analytics = useBernieAnalyticsContext();
// Use the analytics instance
return <div>Tracking active!</div>;
};Tracking Events
The package provides a trackEvent function for manual event tracking.
import { trackEvent } from 'bernie-plugin-analytics';
trackEvent(
'your-namespace',
'referrer-id',
'link-name',
[], // micro messages
[], // events
false, // track immediate
loggerInstance,
platformAnalyticsInstance
);Configuration
The trackEvent function requires several parameters to ensure consistent and accurate tracking:
namespace: (String) Minimum 3 characters.rfrr: (String) Referrer ID, minimum 3 characters.linkName: (String) The name of the link or interaction being tracked, minimum 3 characters.
License
MIT
