@ashishmaurya0408/analytics-provider v1.0.1
Analytics Provider
This project provides an interface for integrating various analytics providers into your application. It currently supports CleverTap as a provider.
Installation
To install the package, run:
npm install @ashishmaurya0408/analytics-providerUsage
Initializing the Provider
To initialize the CleverTap provider, use the init method:
const cleverTapProvider = new CleverTapProvider();
cleverTapProvider.init({
accountId: 'YOUR_ACCOUNT_ID',
region: 'YOUR_REGION',
optOut: false,
debug: true,
debugLevel: 1
});Tracking Events
To track events, use the track method:
cleverTapProvider.track('EventName', { property1: 'value1', property2: 'value2' });Identifying Users
To identify users, use the identify method:
cleverTapProvider.identify('UserId', { trait1: 'value1', trait2: 'value2' });Page Tracking
To track page views, use the page method:
cleverTapProvider.page('PageName', { property1: 'value1' });Setting User Properties
To set user properties, use the setUserProperties method:
cleverTapProvider.setUserProperties({ property1: 'value1', property2: 'value2' });Resetting the Provider
To reset the provider, use the reset method:
cleverTapProvider.reset();Adding New Providers
To add a new provider, implement the ProviderInterface and define the necessary methods such as init, track, identify, page, and reset. Ensure that the new provider can be initialized and used similarly to the CleverTap provider.
Extensibility
The library is designed to be extensible, allowing easy integration of new analytics providers by following the established interface pattern.
Switching Providers
To switch from CleverTap to another provider, you need to modify the providers/index.ts file. Replace the CleverTapProvider with your desired provider, such as MixpanelProvider. Ensure that the new provider implements the ProviderInterface to maintain compatibility with the existing API.
Here's an example of how to change the provider:
// Import the new provider
import MixpanelProvider from './MixpanelProvider';
// Update the getAnalyticsProvider function
export function getAnalyticsProvider() {
return new MixpanelProvider();
}This change allows you to extend the library with minimal modifications to your application code.
6 months ago