skip-event-bridge
Project that consolidates the tracking of all events monitored in the APP and on the Web.
Requirements:
- Any Javascript based project 😃
Instalation
yarn add skip-event-bridge
or if you're using npm
npm install skip-event-bridge --save
Lib initialization
import { BugsnagClient } from '@utils/Bugsnag';
import { EventSDK, MobileClevertap } from 'skip-event-bridge';
import * as CleverTap from 'clevertap-react-native';
const eventSDK = new EventSDK();
eventSDK.addProvider(new MobileClevertap(CleverTap));
eventSDK.addErrorHandler(() => BugsnagClient.notify);
export default eventSDK;
Setting user properties for the providers (Every provider have your specific methods)
eventSDK.tryOnUserLogin({ customer }, []);
Usage, Calling an event
First, import your created instance
import eventSDK from '@event-providers';
Then, call your event
eventSDK.tryAppReviewed({ store: storeName, thumbs: 'up', body: null }, []);
OBS: First parameter is a payload, second parameter is the ID's of the provider you wan to send the event, optional. If empty, will be sended for all providers that implemented that event.
Instructions for improve this lib
How to test this library without install then on package.json and reflect all of your changes in real time.
In Web
In this repository clonned on your PC, run
$ yarn link
In your project folder run this
$ yarn link skip-event-bridge
In React Native
Your metro.config file probaly looks like this
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false
}
})
}
};
Now, Just put extraNodeModules in resolver and add an new watchFolders
const path = require('path');
const extraNodeModules = {
'skip-event-bridge': path.resolve(__dirname + '/../skip-event-bridge/'),
};
const watchFolders = [path.resolve(__dirname + '/../skip-event-bridge/')];
module.exports = {
resolver: {
extraNodeModules,
},
watchFolders,
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};
👮🏿 BEFORE YOUR PROCEED 👮🏻
Events will be accepted only if it is documented HERE
All events have to be typed objects, you NEED to create the type of event in types.ts or your pull request will be dropped.
You need to implement an transform method to return your typed object event before send to your(s) provider(s)
Example in transforms.mobile.ts
export const intoSkipListProduct = (skiplist: any, product: any): SkipListProduct => {
const newProduct: Product = productDetailIntoProduct(product.fullProduct || product);
const productSkipList: SkipListProduct = {
skip_list_id: skiplist.id,
skip_list_name: skiplist.name,
skip_list_url: skiplist.url,
...newProduct
};
return productSkipList;
};
How to create an new event
Add the interface for try send event in types.ts file with this parameters, folow these sample.
export interface EventSdk {
tryYourNewEvent(payload: any, ids: Array<string>): void;
}
Then implement the interface provider in types.ts file with this parameters, folow these sample.
export interface Provider {
yourNewEvent?: ProviderMethod;
}
Implement the method declareted in the interface EventSdk in SkipEventSdk.ts
tryYourNewEvent(payload: any, ids: Array<string>): void {
this.runAll('yourNewEvent', payload, ids);
}
Implement the method declareted in the interface interface Provider in EventActions.ts
yourNewEvent(sender: Function, skipList: SkipList): void {
sender('Your New Event', makeTrustworthy(skipList));
}
Implement the object transform in MobileStrategy.ts
This event created in MobileStrategy.ts will be sent in all providers
yourNewEvent(payload: any): void {
const { skiplist, product } = payload;
const productSkipList = intoSkipListProduct(skiplist, product);
this.action.yourNewEvent(this.addEvent.bind(this), productSkipList);
}
If you want to create some specific treatments for a provider just create a new provider that extends MobileStrategy.ts and implements Provider
This event created in hypothetical MobileFirebaseStrategy.ts will be sent overrided to Firebase
export default class MobileFirebaseStrategy extends WebStrategy implements Provider {
private provider: any;
private action: EventAction;
constructor(firebase: any) {
super();
this.action = new EventAction();
this.provider = firebase;
}
addEvent(eventName: string, payload: Record<string, any>): void {
let newEventName = eventName.replace(/ /g,"_");
this.provider.logEvent(newEventName, payload);
}
yourNewEvent(payload: any): void {
const { skiplist, product } = payload;
const productSkipList = specificTransformForFirebase(skiplist, product);
this.action.yourNewEvent(this.addEvent.bind(this), productSkipList);
}
}
How to create an new Provider
In strategies folder, create your named provider, for example MobileClevertapStrategy.ts
Create a class with the name of provider, to your new provider be capable to send previous implemented events, these provider will inherit MobileStrategy, like this:
export default class MobileClevertapStrategy extends MobileStrategy implements Provider {
constructor(clevertap: any) {
super(clevertap);
}
}
Now your are capable to create specific methods or events for this provider or override the default behaviour of an event, just folow the previous instructions to create an new event then:
private setFCMtoken(token: string): void {
this.provider.setPushToken(token, 'FCM');
}
yourNewEvent(payload: any): void {
const { skiplist, product } = payload;
const productSkipList = specificTransformForClevertap(skiplist, product);
this.action.yourNewEvent(this.addEvent.bind(this), productSkipList);
}
And, thats it! 🚀
Now your are capable to create your specific provider that send all previous events and are capable to override some behaviours.
Open your pull request and we will publish a newer version of this library