airbridge-react-native-sdk
Version:
Airbridge SDK for React Native
373 lines • 15.3 kB
JavaScript
import { NativeModules } from 'react-native';
import { createAttributionModule } from './module/Attribution';
import { createDeeplinkModule } from './module/Deeplink';
import { createEventModule } from './module/Event';
import { createFetchModule } from './module/Fetch';
import { createPlacementModule } from './module/Placement';
import { createRegisterModule } from './module/Register';
import { createSwitchModule } from './module/Switch';
import { createWebInterfaceModule } from './module/WebInterface';
import { check } from './utility/check';
export const createDependency = () => { };
createDependency.Airbridge = () => {
if (!check.object(NativeModules.EventInteractor)) {
return undefined;
}
return ({
attributionModule: createAttributionModule(),
deeplinkModule: createDeeplinkModule(),
eventModule: createEventModule(),
fetchModule: createFetchModule(),
placementModule: createPlacementModule(),
registerModule: createRegisterModule(),
switchModule: createSwitchModule(),
webInterfaceModule: createWebInterfaceModule(),
});
};
class Dependency {
}
Dependency.instance = createDependency.Airbridge();
export class Airbridge {
// attribution
/**
* Sets a listener for receiving attribution of install event.
* @param onReceived Map of attribution is delivered.
*/
static setOnAttributionReceived(onReceived) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.attributionModule.setOnAttributionReceived(onReceived);
}
// deeplink
/**
* Handles deeplink and deferred-deeplink.
* @param onReceived URL of deeplink is delivered.
*/
static setOnDeeplinkReceived(onReceived) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.deeplinkModule.setOnDeeplinkReceived(onReceived);
}
// event
/**
* Tracks user behavior through event tracking with attributes.
* @param category Name of event.
* @param semanticAttributes Additional attributes of the event that defined by Airbridge.
* @param customAttributes Additional attributes of the event.
*/
static trackEvent(category, semanticAttributes, customAttributes) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.eventModule.trackEvent(category, semanticAttributes, customAttributes);
}
// fetch
/**
* Fetch deviceUUID of SDK.
* @param onSuccess Callback to be invoked when deviceUUID is successfully handled.
* @param onFailure Callback to be invoked when any error occurs.
*/
static fetchDeviceUUID(onSuccess, onFailure) {
var _a, _b;
return (_b = (_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.fetchModule.fetchDeviceUUID(onSuccess, onFailure)) !== null && _b !== void 0 ? _b : Promise.resolve(false);
}
/**
* Fetch airbridgeGeneratedUUID of SDK.
* @param onSuccess Callback to be invoked when airbridgeGeneratedUUID is successfully handled.
* @param onFailure Callback to be invoked when any error occurs.
*/
static fetchAirbridgeGeneratedUUID(onSuccess, onFailure) {
var _a, _b;
return (_b = (_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.fetchModule.fetchAirbridgeGeneratedUUID(onSuccess, onFailure)) !== null && _b !== void 0 ? _b : Promise.resolve(false);
}
/**
* Indicates whether notification was sent by Airbridge to track uninstall of app.
* @param notification The notification to check.
*/
static isUninstallTrackingNotification(notification) {
var _a, _b;
return (_b = (_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.fetchModule.isUninstallTrackingNotification(notification)) !== null && _b !== void 0 ? _b : false;
}
// placement
/**
* Notifies that an in-app area within an app has been clicked on by the user.
* @param trackingLink tracking link uri
* @param onSuccess Callback to be invoked when tracking link is successfully handled.
* @param onFailure Callback to be invoked when any error occurs.
* @return `true` if all of the following conditions are met below, `false` otherwise.
* - If the SDK is initialized and enabled.
* - If tracking link is successfully handled.
*/
static click(trackingLink, onSuccess, onFailure) {
var _a, _b;
return (_b = (_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.placementModule.click(trackingLink, onSuccess, onFailure)) !== null && _b !== void 0 ? _b : Promise.resolve(false);
}
/**
* Notifies that the in-app area within the app has been exposed to the user.
* @param trackingLink tracking link uri
* @param onSuccess Callback to be invoked when tracking link is successfully handled.
* @param onFailure Callback to be invoked when any error occurs.
* @return `true` if all of the following conditions are met below, `false` otherwise.
* - If the SDK is initialized and enabled.
* - If tracking link is successfully handled.
*/
static impression(trackingLink, onSuccess, onFailure) {
var _a, _b;
return (_b = (_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.placementModule.impression(trackingLink, onSuccess, onFailure)) !== null && _b !== void 0 ? _b : Promise.resolve(false);
}
// register
/**
* Sets the user ID.
* @param id The user ID.
*/
static setUserID(id) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.setUserID(id);
}
/**
* Clear the user ID.
*/
static clearUserID() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.clearUserID();
}
/**
* Sets the user email.
* @param email The user email.
*/
static setUserEmail(email) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.setUserEmail(email);
}
/**
* Clear the user email.
*/
static clearUserEmail() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.clearUserEmail();
}
/**
* Sets the user phone number.
* @param phone The user phone number.
*/
static setUserPhone(phone) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.setUserPhone(phone);
}
/**
* Clear the user phone number.
*/
static clearUserPhone() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.clearUserPhone();
}
/**
* Sets the key, value pair to the user attribute.
* @param key The key that uniquely identifies the user attribute.
* @param value The value to set for the user attribute.
*/
static setUserAttribute(key, value) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.setUserAttribute(key, value);
}
/**
* Removes the user attribute with the given key.
* @param key The key that uniquely identifies the user attribute.
*/
static removeUserAttribute(key) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.removeUserAttribute(key);
}
/**
* Clears all user attributes.
*/
static clearUserAttributes() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.clearUserAttributes();
}
/**
* Sets the key, value pair to the user alias.
* @param key The key that uniquely identifies the user alias.
* @param value The value to set for the user alias.
*/
static setUserAlias(key, value) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.setUserAlias(key, value);
}
/**
* Removes the user alias with the given key.
* @param key The key that uniquely identifies the user alias.
*/
static removeUserAlias(key) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.removeUserAlias(key);
}
/**
* Clears all user aliases.
*/
static clearUserAlias() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.clearUserAlias();
}
/**
* Clears all user information.
*/
static clearUser() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.clearUser();
}
/**
* Sets the key, value pair to the device alias.
* @param key The key that uniquely identifies the device alias.
* @param value The value to set for the device alias.
*/
static setDeviceAlias(key, value) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.setDeviceAlias(key, value);
}
/**
* Removes the device alias with the given key.
* @param key The key that uniquely identifies the device alias.
*/
static removeDeviceAlias(key) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.removeDeviceAlias(key);
}
/**
* Clears all device aliases.
*/
static clearDeviceAlias() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.clearDeviceAlias();
}
/**
* Registers the FCM or APNS registration token to track app uninstalls.
* @param token The FCM or APNS registration token.
*/
static registerPushToken(token) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.registerModule.registerPushToken(token);
}
// switch
/**
* Enables the SDK.
*/
static enableSDK() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.switchModule.enableSDK();
}
/**
* Disables the SDK.
*/
static disableSDK() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.switchModule.disableSDK();
}
/**
* Checks whether the SDK is currently enabled.
* @return `true` if the SDK is enabled, `false` otherwise.
*/
static isSDKEnabled() {
var _a, _b;
return (_b = (_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.switchModule.isSDKEnabled()) !== null && _b !== void 0 ? _b : Promise.resolve(false);
}
/**
* Start collecting and transferring events.
*/
static startTracking() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.switchModule.startTracking();
}
/**
* Stop collecting and transferring events.
*/
static stopTracking() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.switchModule.stopTracking();
}
/**
* Checks whether the tracking feature of SDK is currently enabled.
* @return `true` if the tracking feature of SDK tracking is enabled,`false` otherwise.
*/
static isTrackingEnabled() {
var _a, _b;
return (_b = (_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.switchModule.isTrackingEnabled()) !== null && _b !== void 0 ? _b : Promise.resolve(false);
}
// web interface
/**
* Creates a script that initialize the web interface.
* @param webToken The token to initialize Airbridge Web SDK.
* @param postMessageScript The JavaScript code to post commands from web to app.
* @return web interface script
*/
static createWebInterfaceScript(webToken, postMessageScript) {
var _a, _b;
return (_b = (_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.webInterfaceModule.createWebInterfaceScript(webToken, postMessageScript)) !== null && _b !== void 0 ? _b : Promise.resolve(undefined);
}
/**
* Handles commands from the web interface.
* @param command The command to handle.
*/
static handleWebInterfaceCommand(command) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.webInterfaceModule.handleWebInterfaceCommand(command);
}
/**
* Creates a tracking-link using airbridge-server that move user
* to specific page of app and track click-event.
*
* @param channel The channel of tracking-link.
* @param option The option to create tracking-link.
* @param onSuccess Created tracking-link is delivered if succeed.
* @param onFailure Error is delivered if failed.
*/
static createTrackingLink(channel, option, onSuccess, onFailure) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.placementModule.createTrackingLink(channel, option, onSuccess, onFailure);
}
/**
* Starts tracking event automatically for each user
* purchases product through in-app-purchase.
*/
static startInAppPurchaseTracking() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.switchModule.startInAppPurchaseTracking();
}
/**
* Stops tracking event automatically for each user
* purchases product through in-app-purchase.
*/
static stopInAppPurchaseTracking() {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.switchModule.stopInAppPurchaseTracking();
}
/**
* Indicates that SDK can track event automatically for each user
* purchases product through in-app-purchase.
*
* @return `true` if the SDK is enabled for in-app-purchase tracking, `false` otherwise.
*/
static isInAppPurchaseTrackingEnabled() {
var _a, _b;
return (_b = (_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.switchModule.isInAppPurchaseTrackingEnabled()) !== null && _b !== void 0 ? _b : Promise.resolve(false);
}
/**
* Allows tracking for the specified [AirbridgeTrackingBlocklist] item.
* This function removes the given item from the current TrackingBlocklist
* applied in the `airbridge.json`, enabling tracking at runtime.
*
* @param item The tracking blocklist item to allow.
*/
static allowTrackingItem(item) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.switchModule.allowTrackingItem(item);
}
/**
* Blocks tracking for the specified [AirbridgeTrackingBlocklist] item.
* This function adds the given item to the current TrackingBlocklist
* applied in the `airbridge.json`, disabling tracking at runtime.
*
* @param item The tracking blocklist item to block.
*/
static blockTrackingItem(item) {
var _a;
(_a = Dependency.instance) === null || _a === void 0 ? void 0 : _a.switchModule.blockTrackingItem(item);
}
}
//# sourceMappingURL=Airbridge.js.map