UNPKG

capacitor-moengage-core

Version:

MoEngage is a mobile marketing automation company. This capacitor SDK helps you track events, trigger smart notifications.

1,079 lines (1,078 loc) 27.8 kB
import type { PluginListenerHandle } from '@capacitor/core'; /** * Location object */ export interface MoEGeoLocation { latitude: number; longitude: number; } /** * General Attributes for tracking events */ export interface MoEGeneralAttributes { name: string; value: string | number | boolean | Array<string> | Array<number>; } /** * Account Object */ export interface MoEAccountMeta { /** * Account identifier */ appId: string; } /** * Date and time attribute object */ export interface MoEDateTimeAttributes { /** * Date and time attribute name */ name: string; /** * Attribute value in ISO8601 format [yyyy-MM-dd'T'HH:mm:ss'Z']. */ value: string; } /** * Location attribute object */ export interface MoELocationAttributes { /** * Location Attribute name */ name: string; /** * Location attribute value. */ value: MoEGeoLocation; } /** * User attributes object */ export interface MoEProperties { /** * General Attributes */ generalAttributes?: Array<MoEGeneralAttributes>; /** * Location Attributes */ dateTimeAttributes?: Array<MoEDateTimeAttributes>; /** * Date time Attributes */ locationAttributes?: Array<MoELocationAttributes>; /** * Is the event non-interactive */ isNonInteractive?: boolean; } /** * User attribute Gender options */ export declare enum MoEUserGender { MALE = "male", FEMALE = "female", OTHER = "other" } /** * Status of the application. */ export declare enum MoEAppStatus { /** * Fresh installation of the app instance. */ INSTALL = "install", /** * App was already present and user has updated the app. */ UPDATE = "update" } /** * Campaign data. */ export interface MoEInAppCampaignData { /** * Unique Identifier for the campaign */ campaignId: string; /** * Name given to the campaign while creation on the MoEngage Dashboard. */ campaignName: string; /** * Additional Meta data related to the campaign. */ campaignContext: MoEInAppCampaignContext; } /** * Additional Meta data related to the campaign. */ export interface MoEInAppCampaignContext { /** * Formatted Campaign Id */ formattedCampaignId: string; /** * Additional Meta data related to the campaign. */ attributes: Map<string, object>; } /** * In-App lifecycle event camapaign data */ export interface MoEInAppLifecycleData { /** * Account information */ accountMeta: MoEAccountMeta; /** * In-App Campaign data */ campaignData: MoEInAppCampaignData; /** * Platform information */ platform: MoEPlatform; } /** * In-App custom event campaign data */ export interface MoEInAppCustomActionData { /** * Account information */ accountMeta: MoEAccountMeta; /** * In-App Campaign data */ campaignData: MoEInAppCampaignData; /** * Custom Action data */ customAction: MoEInAppCustomAction; /** * Platform information */ platform: MoEPlatform; } /** * InApp Action type */ export declare enum MoEInAppActionType { NAVIGATION = "navigation", CUSTOM = "custom" } /** * In-App custom action data */ export interface MoEInAppCustomAction { /** * InApp Action type */ actionType: MoEInAppActionType; /** * Key-Value Pair entered on the MoEngage Platform during campaign creation. */ kvPair: Map<string, object>; } /** * In-App navigation event campaign data */ export interface MoEInAppNavigationData { /** * Account information */ accountMeta: MoEAccountMeta; /** * In-App Campaign data */ campaignData: MoEInAppCampaignData; /** * Navigation action data */ navigation: MoEInAppNavigation; /** * Platform Data */ platform: MoEPlatform; } /** * In-App navigation action data */ export interface MoEInAppNavigation { /** * InApp Action type */ actionType: MoEInAppActionType; /** * Type of Navigation. */ navigationType: string; /** * Navigation URL */ navigationUrl: string; /** * Key-Value Pair entered on the MoEngage Platform during campaign creation. */ kvPair: Map<string, Object>; } /** * Data for self handled campaign. */ export interface MoEInAppSelfHandledCampaignData { /** * Account information */ accountMeta: MoEAccountMeta; /** * In-App Campaign data */ campaignData: MoEInAppCampaignData; /** * SelfHandled data */ selfHandled: MoEInAppSelfHandledCampaign; /** * Platform information */ platform: MoEPlatform; } /** * Self Handled campaign object */ export interface MoEInAppSelfHandledCampaign { /** * Self handled campaign payload. */ payload: string; /** * Interval after which in-app should be dismissed, unit - Seconds */ dismissInterval: number; /** * Display rules for the campaign */ displayRules: MoEInAppDisplayRules; } /** * Display rules for self handled campaign */ export interface MoEInAppDisplayRules { /** * Screen name where campaign should be displayed */ screenName: string; /** * List of contexts */ contexts: Array<string>; /** * List of screen names */ screenNames: Array<string>; } /** * Push event data */ export interface MoEPushCampaignData { /** * Account information */ accountMeta: MoEAccountMeta; /** * Push campaign object */ pushCampaign: MoEPushCampaign; /** * Platform data */ platform: MoEPlatform; } /** * Platform Data */ export declare enum MoEPlatform { iOS = "iOS", ANDROID = "android" } /** * Push campaign object */ export interface MoEPushCampaign { /** * Is the click action a defualt action */ isDefaultAction: boolean; /** * Clicked Action data */ clickedAction: Map<String, object>; /** * Key-Value Pair entered on the MoEngage Platform during campaign creation. */ payload: Map<String, object>; } /** * Supported push services */ export declare enum MoEPushService { APNS = 0, FCM = 1, MI_PUSH = 2, PUSH_KIT = 3 } /** * Push token object */ export interface MoEPushTokenData { /** * Platform type */ platform: MoEPlatform; /** * Type of push service */ pushService: MoEPushService; /** * Push Token */ token: String; } /** * Permission Type */ export declare enum MoEPermissionType { PUSH = "push" } /** * Permission Response Data */ export interface MoEPermissionResultData { /** * Platform type */ platform: MoEPlatform; /** * State of permission */ isGranted: boolean; /** * Type of permission */ type: MoEPermissionType; } /** * User Delete Response Data */ export interface MoEUserDeleteData { /** * Account information */ accountMeta: MoEAccountMeta; /** * Status of user deletion */ isSuccess: boolean; } export interface MoEInitConfig { /** * Analytics Config data */ analyticsConfig: MoEAnalyticsConfig; /** * Push Config data */ pushConfig?: MoEPushConfig; } export interface MoEAnalyticsConfig { /** * Status of whether boolean user attribute should be tracked as number or not. */ shouldTrackUserAttributeBooleanAsNumber: boolean; } export interface MoEPushConfig { /** * Whether to deliver callback when push notification is clicked in foreground */ shouldDeliverCallbackOnForegroundClick: boolean; } /** * Data for multiple self handled campaigns. */ export interface MoEInAppSelfHandledCampaignsData { /** * Account information */ accountMeta: MoEAccountMeta; /** * Array of self handled campaigns */ campaigns: Array<MoEInAppSelfHandledCampaignData>; } /** * Data returned when a logout operation is successfully completed. */ export interface MoELogoutCompleteData { /** * Account information */ accountMeta: MoEAccountMeta; /** * Platform type */ platform: MoEPlatform; } /** * Nudge Position values */ export declare enum MoENudgePosition { Top = "top", Bottom = "bottom", BottomLeft = "bottomLeft", BottomRight = "bottomRight", Any = "any" } /** * Authentication type. */ export declare enum MoEAuthenticationType { JWT = "JWT" } /** * JWT authentication error codes. */ export declare enum MoEJwtErrorCode { TimeConstraintFailure = "TIME_CONSTRAINT_FAILURE", DecryptionFailed = "DECRYPTION_FAILED", HeaderTypeIncompatible = "HEADER_TYPE_INCOMPATIBLE", PayloadContentMissing = "PAYLOAD_CONTENT_MISSING", InvalidSignature = "INVALID_SIGNATURE", IdentifierMismatch = "IDENTIFIER_MISMATCH", Unknown = "UNKNOWN", TokenNotAvailable = "TOKEN_NOT_AVAILABLE" } /** * Base interface for authentication data. */ export interface MoEAuthenticationDetails { } /** * JWT authentication payload. */ export interface MoEJwtAuthenticationData extends MoEAuthenticationDetails { token: string; userIdentifier: string; } /** * Authentication details payload. */ export interface MoEAuthenticationData { authenticationType: MoEAuthenticationType; data: MoEAuthenticationDetails; } /** * Base interface for error data. */ export interface MoEAuthenticationErrorDetails { } /** * JWT authentication error data. */ export interface MoEJwtAuthenticationErrorData extends MoEAuthenticationErrorDetails { code: MoEJwtErrorCode; token: string; userIdentifier: string; message: string; } /** * Authentication error data. */ export interface MoEAuthenticationErrorData { accountMeta: MoEAccountMeta; platform: MoEPlatform; authenticationType: MoEAuthenticationType; data: MoEAuthenticationErrorDetails; } export declare type MoEPushTokenListener = (event: MoEPushTokenData) => void; export declare type MoEPushClickListener = (event: MoEPushCampaignData) => void; export declare type MoEInAppShownListener = (event: MoEInAppLifecycleData) => void; export declare type MoEInAppDismissedListener = (event: MoEInAppLifecycleData) => void; export declare type MoEInAppClickedListener = (event: MoEInAppNavigationData) => void; export declare type MoEInAppCustomActionListener = (event: MoEInAppCustomActionData) => void; export declare type MoEInAppSelfHandledListener = (event: MoEInAppSelfHandledCampaignData) => void; export declare type MoEPermissionListener = (event: MoEPermissionResultData) => void; export declare type MoEUserDeleteCallback = (userDeleteData: MoEUserDeleteData) => void; export declare type MoELogoutCompleteListener = (event: MoELogoutCompleteData) => void; export declare type MoEAuthenticationErrorListener = (event: MoEAuthenticationErrorData) => void; export interface MoECapacitorCorePlugin { /** * Initialise MoEngage Capacitor Plugin * * @param appId Account Identifier * @param initConfig SDK initialization configuration * @param lifecycleAwareCallbackEnabled Enable lifecycle-aware callback handling. * When enabled, events are queued when app goes to background * and flushed when app returns to foreground, default as false. * @since 2.0.0 */ initialize(options: { appId: string; initConfig: MoEInitConfig; lifecycleAwareCallbackEnabled?: boolean; }): Promise<void>; /** * Track user behaviour as events with properties * * @param eventName Event Name * @param properties {\} properties of the event. * @param appId Account Identifier * * @since 2.0.0 */ trackEvent(options: { eventName: string; eventAttributes?: MoEProperties; appId: string; }): Promise<void>; /** * Set a Unique Identifier for the user. * @param uniqueId identifier * @param appId Account Identifier * * @since 2.0.0 */ setUniqueId(options: { uniqueId: string; appId: string; }): Promise<void>; /** * Set an Alias to update the existing Unique Id * @param alias identifier * @param appId Account Identifier * * @since 2.0.0 */ setAlias(options: { alias: string; appId: string; }): Promise<void>; /** * Set user's full name * @param userName full name of the user * @param appId Account Identifier * * @since 2.0.0 */ setUserName(options: { userName: string; appId: string; }): Promise<void>; /** * Set user's first name * @param firstName first name of the user * @param appId Account Identifier * * @since 2.0.0 */ setFirstName(options: { firstName: string; appId: string; }): Promise<void>; /** * Set user's last name * * @param lastName last name of the user * @param appId Account Identifier */ setLastName(options: { lastName: string; appId: string; }): Promise<void>; /** * Set user's email id * @param emailId email id * @param appId Account Identifier * * @since 2.0.0 */ setEmailId(options: { emailId: string; appId: string; }): Promise<void>; /** * Set user's mobile number * @param mobileNumber mobile number * @param appId Account Identifier */ setMobileNumber(options: { mobileNumber: string; appId: string; }): Promise<void>; /** * Set user's birthdate. * @param birthdate birthdate to be set in ISO8601 format [yyyy-MM-dd'T'HH:mm:ss'Z']. * @param appId Account Identifier * * @since 1.0.0 */ setBirthDate(options: { birthdate: string; appId: string; }): Promise<void>; /** * Set user's gender. * @param gender {MoEUserGender} value * @param appId Account Identifier * * @since 2.0.0 */ setGender(options: { gender: MoEUserGender; appId: string; }): Promise<void>; /** * Set user's location * @param location {MoEGeoLocation} of the user * @param appId Account Identifier * * @since 2.0.0 */ setUserLocation(options: { location: MoEGeoLocation; appId: string; }): Promise<void>; /** * Set the user defined attribute with value. * @param name user attribute name * @param value user attribute value * @param appId Account Identifier * * @since 2.0.0 */ setUserAttribute(options: { name: string; value: string | number | boolean | Array<string> | Array<number>; appId: string; }): Promise<void>; /** * Set a user attribute timestamp for the current user * @param name attribute name * @param value User attribute value in ISO8601 format [yyyy-MM-dd'T'HH:mm:ss'Z']. * @param appId Account Identifier * * @since 2.0.0 */ setUserAttributeDate(options: { name: string; value: string; appId: string; }): Promise<void>; /** * Set the user attribute location * @param name attribute name * @param location {MoEGeoLocation} * @param appId Account Identifier * * @since 2.0.0 */ setUserAttributeLocation(options: { name: string; location: MoEGeoLocation; appId: string; }): Promise<void>; /** * This API tells the SDK whether it is a fresh install or an existing application was updated. * @param appStatus {MoEAppStatus} if it is an existing user set "update" else set "install" * @param appId Account Identifier * * @since 2.0.0 */ setAppStatus(options: { appStatus: MoEAppStatus; appId: string; }): Promise<void>; /** * Notify the SDK that the user has logged out of the application * * @param appId Account Identifier * * @since 2.0.0 */ logoutUser(options: { appId: string; }): Promise<void>; /** * API to enable SDK usage. * * @param appId Account Identifier * * @remarks By default the SDK is enabled, this API should only be called if you have called * `disableSdk()` at some point. * * @since 2.0.0 */ enableSdk(options: { appId: string; }): Promise<void>; /** * API to disable all features of the SDK. * * @param appId Account Identifier * * @since 2.0.0 */ disableSdk(options: { appId: string; }): Promise<void>; /** * Call this method wherever InApp message has to be shown, if available. * * @param appId Account Identifier * * @since 2.0.0 */ showInApp(options: { appId: string; }): Promise<void>; /** * Triggers fetching self handled in-app, the result is returned in the `inAppCampaignSelfHandled` listener * * @param appId Account Identifier * * @since 2.0.0 */ getSelfHandledInApp(options: { appId: string; }): Promise<void>; /** * API to track self handled in-app shown event. * @param campaignData {MoEInAppSelfHandledCampaignData} in-app campaign * * @since 2.0.0 */ selfHandledShown(campaignData: MoEInAppSelfHandledCampaignData): Promise<void>; /** * API to track click event of any other widget apart from primary widget in the self handled in-app. * @param campaignData {MoEInAppSelfHandledCampaignData} in-app campaign * * @since 2.0.0 */ selfHandledClicked(campaignData: MoEInAppSelfHandledCampaignData): Promise<void>; /** * API to track self handled in-app's dismiss event. * @param campaignData {MoEInAppSelfHandledCampaignData} in-app campaign * * @since 2.0.0 */ selfHandledDismissed(campaignData: MoEInAppSelfHandledCampaignData): Promise<void>; /** * Set current context for in-app module. * @param contexts array of contexts * @param appId Account Identifier * * @since 2.0.0 */ setInAppContext(options: { contexts: Array<string>; appId: string; }): Promise<void>; /** * Resets/Clears the previously set context for in-app module. * * @param appId Account Identifier * * @since 2.0.0 */ resetInAppContext(options: { appId: string; }): Promise<void>; /** * Optionally opt-in data tracking. * * @param appId Account Identifier * * @since 2.0.0 */ enableDataTracking(options: { appId: string; }): Promise<void>; /** * Optionally opt-out of data tracking. When data tracking is opted no event or user * attribute is tracked on MoEngage Platform. * * @param appId Account Identifier * * @since 2.0.0 */ disableDataTracking(options: { appId: string; }): Promise<void>; /** * Pass FCM Push Token to the MoEngage SDK * @remarks This API is only for `Android` * * @param token FCM token * * @since 2.0.0 */ passFcmPushToken(options: { token: string; appId: string; }): Promise<void>; /** * Pass FCM payload to MoEngage SDK * @remarks This API is only for `Android` * * @param payload Push payload * * @since 2.0.0 */ passFcmPushPayload(options: { payload: object; appId: string; }): Promise<void>; /** * Register For Push Notification for iOS * @remarks This API is only for `iOS` * * @since 2.0.0 */ registerForPush(): Promise<void>; /** * Notifies MoEngage SDK of device orientation change * @remarks This API is only for `Android` * * @since 2.0.0 */ onOrientationChanged(): Promise<void>; /** * Pass JWT authentication details to the native SDK (after login / token refresh). * * @since 7.1.0 */ passAuthenticationDetails(options: { authenticationData: MoEAuthenticationData; appId: string; }): Promise<void>; /** * Listen for push token generated event * * @since 2.0.0 */ addListener(eventName: 'pushTokenGenerated', listenerFunc: MoEPushTokenListener): Promise<PluginListenerHandle> & PluginListenerHandle; /** * Listen for push clicked event * * @since 1.0.0 */ addListener(eventName: 'pushClicked', listenerFunc: MoEPushClickListener): Promise<PluginListenerHandle> & PluginListenerHandle; /** * Listen for in-app campaign shown event * * @since 1.0.0 */ addListener(eventName: 'inAppCampaignShown', listenerFunc: MoEInAppShownListener): Promise<PluginListenerHandle> & PluginListenerHandle; /** * Listen for in-app campaign clicked event * * @since 1.0.0 */ addListener(eventName: 'inAppCampaignClicked', listenerFunc: MoEInAppClickedListener): Promise<PluginListenerHandle> & PluginListenerHandle; addListener(eventName: 'inAppCampaignDismissed', listenerFunc: MoEInAppDismissedListener): Promise<PluginListenerHandle> & PluginListenerHandle; /** * Listen for in-app campaign custom action event * * @since 1.0.0 */ addListener(eventName: 'inAppCampaignCustomAction', listenerFunc: MoEInAppCustomActionListener): Promise<PluginListenerHandle> & PluginListenerHandle; /** * Listen for in-app campaign self handled available event * * `getSelfHandledInApp()` api call returns the available self handled in-app via this listener. * * @since 1.0.0 */ addListener(eventName: 'inAppCampaignSelfHandled', listenerFunc: MoEInAppSelfHandledListener): Promise<PluginListenerHandle> & PluginListenerHandle; /** * Listen for logout complete event * * @since 7.0.0 */ addListener(eventName: 'logoutCompleted', listenerFunc: MoELogoutCompleteListener): Promise<PluginListenerHandle> & PluginListenerHandle; /** * Listen for authentication errors from the MoEngage SDK (e.g. JWT validation failures). * * @since 7.1.0 */ addListener(eventName: 'authenticationError', listenerFunc: MoEAuthenticationErrorListener): Promise<PluginListenerHandle> & PluginListenerHandle; /** * Enables GAID tracking, by default GAID tracking is disabled. * @remarks This API is only for `Android` * * @since 2.0.0 */ enableAdIdTracking(options: { appId: string; }): Promise<void>; /** * Disables GAID tracking. * @remarks This API is only for `Android` * * @since 2.0.0 */ disableAdIdTracking(options: { appId: string; }): Promise<void>; /** * Enables Android ID tracking, by default ANdroid ID tracking is disabled. * @remarks This API is only for `Android` * * @since 2.0.0 */ enableAndroidIdTracking(options: { appId: string; }): Promise<void>; /** * Disables Android ID tracking. * @remarks This API is only for `Android` * * @since 2.0.0 */ disableAndroidIdTracking(options: { appId: string; }): Promise<void>; /** * API to create notification channels on Android. * @remarks This API is only for `Android` * * @since 2.0.0 */ setupNotificationChannelsAndroid(): Promise<void>; /** * Notify the SDK on notification permission granted to the application. * @remarks This API is only for `Android` * * @param isGranted true if the permission is granted else false * * @since 2.0.0 */ pushPermissionResponseAndroid(options: { isGranted: boolean; }): Promise<void>; /** * Navigates the user to the Notification settings on Android 8 or above, * on older versions the user is navigated the application settings or * application info screen. * @remarks This API is only for `Android` */ navigateToSettingsAndroid(): Promise<void>; /** * Requests the push permission on Android 13 and above. * @remarks This API is only for `Android` */ requestPushPermissionAndroid(): Promise<void>; /** * Listen for permission response * @remarks This API is only for `Android` * * `requestPushPermissionAndroid()` api call returns the state of permission via this listener. * * @since 2.0.0 */ addListener(eventName: 'onPermissionResult', listenerFunc: MoEPermissionListener): Promise<PluginListenerHandle> & PluginListenerHandle; /** * Enable Device-id tracking. It is enabled by default and should be called only if tracking is disabled at some point. * */ enableDeviceIdTracking(options: { appId: string; }): Promise<void>; /** * Disables Device-id tracking. */ disableDeviceIdTracking(options: { appId: string; }): Promise<void>; /** * Updates the Notification request attempt count, the request attempt count will be * incremented by the passed fresh count. * * NOTE: Call this API only when the Application is handling the Notification request * permission. * @remarks This API is only for `Android` * * @param appId Account Identifier * @param count - Number of fresh request attempts. * */ updatePushPermissionRequestCountAndroid(options: { appId: string; count: number; }): Promise<void>; /** * Delete Current User Data From MoEngage Server * * @remarks This API is only for `Android` * @param appId Account Identifier * @param callback instance of {@link MoEUserDeleteCallback} to get the API response */ deleteUser(options: { appId: string; }, callback: MoEUserDeleteCallback): Promise<void>; /** * Show Nudge * * @param position Place on the screen to show the Nudge. * @param appId Account Identifier */ showNudge(options: { position: MoENudgePosition; appId: string; }): Promise<void>; /** * Identify User * @param identity Supported types: [String] and [Map<String, String>] * @param appId Account Identifier * * @since 7.0.0 */ identifyUser(options: { identity: string | { [key: string]: string; }; appId: string; }): Promise<void>; /** * Get User Identities * * @param appId Account Identifier * @returns A Promise that resolves to an object containing user identities as key-value pairs * Returns an empty object if no user identities are found. * Returns null if an error occurred while fetching the user identities. * @since 7.0.0 */ getUserIdentities(options: { appId: string; }): Promise<Map<String, String> | null>; /** * Get Multiple self handled in-app campaigns * * @param appId Account Identifier * @returns Promise with campaigns data * * @since 7.0.0 */ getSelfHandledInApps(options: { appId: string; }): Promise<MoEInAppSelfHandledCampaignsData>; /** * Register For Provisional Push Notifications for iOS * @remarks This API is only for `iOS` * @since 7.0.0 */ registerForProvisionalPush(): Promise<void>; }