### Report App Install or Update Status Source: https://context7.com/moengage/react-native/llms.txt Inform the SDK whether the current app launch is a fresh install or an update. This is crucial for triggering install-related campaigns and should be called immediately after initialization. ```typescript import ReactMoE, { MoEAppStatus } from 'react-native-moengage'; // On first launch (fresh install) ReactMoE.setAppStatus(MoEAppStatus.Install); // On subsequent launches after an app update ReactMoE.setAppStatus(MoEAppStatus.Update); ``` -------------------------------- ### Install React Native Expo MoEngage Source: https://github.com/moengage/react-native/blob/master/sdk/expo/README.md Install the MoEngage Expo plugin using npm. This command should be run in your React Native project directory. ```bash npm install react-native-expo-moengage ``` -------------------------------- ### ReactMoE.setAppStatus Source: https://context7.com/moengage/react-native/llms.txt Informs the SDK whether this is a fresh install or an update. Required for install-campaign triggers. Call immediately after initialize. ```APIDOC ## ReactMoE.setAppStatus — Report Install vs Update ### Description Informs the SDK whether this is a fresh install or an update. **Required** for install-campaign triggers. Call immediately after `initialize`. ### Method Signature ```typescript ReactMoE.setAppStatus(status: MoEAppStatus) ``` ### Parameters * **status** (MoEAppStatus) - Required - Indicates if the app is a new install or an update. * `MoEAppStatus.Install`: For a fresh installation. * `MoEAppStatus.Update`: For an app update. ### Request Example ```typescript import ReactMoE, { MoEAppStatus } from 'react-native-moengage'; // On first launch (fresh install) ReactMoE.setAppStatus(MoEAppStatus.Install); // On subsequent launches after an app update ReactMoE.setAppStatus(MoEAppStatus.Update); ``` ``` -------------------------------- ### ReactMoEGeofence - Location-Based Campaigns Source: https://context7.com/moengage/react-native/llms.txt Starts or stops geofence monitoring. On iOS this also triggers the location permission request. ```APIDOC ## ReactMoEGeofence ### Description Starts or stops geofence monitoring. On iOS this also triggers the location permission request. ### Methods - **startGeofenceMonitoring(appId)**: Starts geofence monitoring for the specified MoEngage App ID. This also requests location permissions on iOS. - **stopGeofenceMonitoring(appId)**: Stops geofence monitoring. This is effective on Android and is a no-op on iOS. ``` -------------------------------- ### Start and Stop Geofence Monitoring Source: https://context7.com/moengage/react-native/llms.txt Initiate geofence monitoring for location-based campaigns. On iOS, this action also triggers the location permission request. This function is Android-only. ```typescript import ReactMoEGeofence from 'react-native-moengage-geofence'; const APP_ID = 'YOUR_MOENGAGE_APP_ID'; // Start monitoring (also requests location permission on iOS) ReactMoEGeofence.startGeofenceMonitoring(APP_ID); // Stop monitoring (Android only; no-op on iOS) ReactMoEGeofence.stopGeofenceMonitoring(APP_ID); ``` -------------------------------- ### Get Unclicked Message Count Source: https://context7.com/moengage/react-native/llms.txt Retrieve the count of unread (unclicked) messages in the user's inbox. This is useful for displaying badge counts. ```typescript import MoEReactInbox from 'react-native-moengage-inbox'; // Badge count of unclicked messages const unclickedCount = await MoEReactInbox.getUnClickedCount(); console.log('Unread:', unclickedCount); // e.g. 3 ``` -------------------------------- ### Create and Prebuild Expo TV Project Source: https://github.com/moengage/react-native/blob/master/ExpoTVSampleApp/README.md Use these commands to create a new Expo project configured for TV and then prebuild it for native TV targets. Setting EXPO_TV=1 is crucial for enabling TV-specific configurations during the prebuild process. ```sh export EXPO_TV=1 npx expo prebuild yarn ios # Build for Apple TV yarn android # Build for Android TV ``` -------------------------------- ### Initialize and Manage Content Cards Feed Source: https://context7.com/moengage/react-native/llms.txt Set up the sync listener, initialize the SDK, and manage card categories, impressions, clicks, and delivery tracking. Ensure sync listener is registered before initialization. ```typescript import ReactMoEngageCards from 'react-native-moengage-cards'; import type { CardsData, Card } from 'react-native-moengage-cards'; // 1. Register sync callback BEFORE initialize ReactMoEngageCards.setSyncCompleteListener((syncData) => { console.log('Cards synced:', syncData); }); // 2. Initialize ReactMoEngageCards.initialize('YOUR_MOENGAGE_APP_ID'); // 3. Signal that the cards section is visible ReactMoEngageCards.onCardSectionLoaded((syncData) => { console.log('Section loaded sync:', syncData); }); // 4. Fetch all categories and cards const categories: string[] = await ReactMoEngageCards.getCardsCategories(); console.log('Categories:', categories); // e.g. ["All", "Offers", "News"] const isAllEnabled = await ReactMoEngageCards.isAllCategoryEnabled(); const allCards: CardsData = await ReactMoEngageCards.getCardsForCategory('All'); // Or fetch all regardless of category: const allCardsData: CardsData = await ReactMoEngageCards.fetchCards(); // 5. Card shown impression const card: Card = allCards.cards[0]; ReactMoEngageCards.cardShown(card); // 6. Card clicked (widgetId identifies which widget inside the card) ReactMoEngageCards.cardClicked(card, 0); // 7. Badge counts const newCount = await ReactMoEngageCards.getNewCardsCount(); const unclickedCount = await ReactMoEngageCards.getUnClickedCardsCount(); console.log(`New: ${newCount}, Unclicked: ${unclickedCount}`); // 8. Delete cards ReactMoEngageCards.deleteCard(card); ReactMoEngageCards.deleteCards([card, allCards.cards[1]]); // 9. Manual refresh ReactMoEngageCards.refreshCards((syncData) => { console.log('Manual refresh complete:', syncData); }); // 10. Signal cards section is hidden ReactMoEngageCards.onCardSectionUnLoaded(); // 11. Track delivery ReactMoEngageCards.cardDelivered(); ``` -------------------------------- ### Fetch and Track Personalization Experiences Source: https://context7.com/moengage/react-native/llms.txt Instantiate the Personalize SDK to fetch A/B test and personalization campaigns. Report impression and click events back to MoEngage. Use the `offeringShown` and `offeringClicked` methods for slot-level analytics. ```typescript import ReactMoEngagePersonalize, { ExperienceStatus, ExperienceFailureReason, } from 'react-native-moengage-personalize'; import type { ExperienceCampaignsResult, ExperienceCampaign, ExperienceCampaignsMetadata, } from 'react-native-moengage-personalize'; // Instantiate once per workspace const personalize = new ReactMoEngagePersonalize('YOUR_MOENGAGE_APP_ID'); // Fetch metadata for active campaigns const meta: ExperienceCampaignsMetadata = await personalize.fetchExperiencesMeta([ ExperienceStatus.ACTIVE, ExperienceStatus.SCHEDULED, ]); console.log('Active experiences meta:', meta); // Fetch a single experience (with optional personalization attributes) const result: ExperienceCampaignsResult = await personalize.fetchExperience( 'homepage_banner', { user_tier: 'gold', locale: 'en-US' } ); if (result.experiences.length > 0) { const campaign: ExperienceCampaign = result.experiences[0]; console.log('Payload:', campaign.payload); console.log('Source:', campaign.source); // "cache" | "network" // Report impression when shown to user personalize.experienceShown(campaign); // Later, report click personalize.experienceClicked(campaign); } // Log failures result.failures.forEach((failure) => { console.warn('Failed keys:', failure.experienceKeys, 'Reason:', failure.reason); }); // Fetch multiple experiences in one call const multiResult = await personalize.fetchExperiences( ['hero_banner', 'promo_strip'], { segment: 'vip' } ); // Offerings tracking (for slot-level analytics inside a campaign) const offeringPayload = campaign.payload['slots'][0]; personalize.offeringShown(offeringPayload); personalize.offeringClicked(campaign, offeringPayload); ``` -------------------------------- ### ReactMoE.initialize Source: https://context7.com/moengage/react-native/llms.txt Initializes the MoEngage SDK with the workspace App ID. Must be called once after the hybrid component mounts. Accepts an optional MoEInitConfig to configure push behavior, logging, and analytics on Android. ```APIDOC ## ReactMoE.initialize — Initialize the SDK ### Description Initializes the MoEngage SDK with the workspace App ID. Must be called once after the hybrid component mounts. Accepts an optional `MoEInitConfig` to configure push behavior, logging, and analytics on Android. ### Method Signature ```typescript ReactMoE.initialize(appId: string, initConfig?: MoEInitConfig) ``` ### Parameters * **appId** (string) - Required - Your MoEngage workspace App ID. * **initConfig** (MoEInitConfig) - Optional - Configuration object for push, logging, and analytics. ### Request Example ```typescript import ReactMoE, { MoEInitConfig, MoEPushConfig, MoEngageLogConfig, MoEngageLogLevel, MoEAnalyticsConfig, } from 'react-native-moengage'; // Minimal initialization ReactMoE.initialize('YOUR_MOENGAGE_APP_ID'); // Full initialization with custom config (Android-effective options) const pushConfig = new MoEPushConfig( true // deliver push-click callback even when app is in foreground ); const logConfig = new MoEngageLogConfig( MoEngageLogLevel.DEBUG, false // disable logs in release builds ); const analyticsConfig = new MoEAnalyticsConfig( true // track boolean user attributes as 0/1 on iOS ); const initConfig = new MoEInitConfig(pushConfig, logConfig, analyticsConfig); ReactMoE.initialize('YOUR_MOENGAGE_APP_ID', initConfig); ``` ``` -------------------------------- ### Configure MoEngage SDK Initialization in iOS Source: https://github.com/moengage/react-native/blob/master/README.md Update the MoEngage App ID in the AppDelegate.m file for the iOS sample app. Replace YOUR_APP_ID with your actual MoEngage App ID. ```objectivec MoEngageSDKConfig *config = [[MoEngageSDKConfig alloc] initWithAppID:@"YOUR_APP_ID"]; ``` -------------------------------- ### Initialize MoEngage SDK Source: https://context7.com/moengage/react-native/llms.txt Initialize the MoEngage SDK with your App ID. An optional configuration object can be provided for custom push, logging, and analytics settings, primarily effective on Android. ```typescript import ReactMoE, { MoEInitConfig, MoEPushConfig, MoEngageLogConfig, MoEngageLogLevel, MoEAnalyticsConfig, } from 'react-native-moengage'; // Minimal initialization ReactMoE.initialize('YOUR_MOENGAGE_APP_ID'); // Full initialization with custom config (Android-effective options) const pushConfig = new MoEPushConfig( true // deliver push-click callback even when app is in foreground ); const logConfig = new MoEngageLogConfig( MoEngageLogLevel.DEBUG, false // disable logs in release builds ); const analyticsConfig = new MoEAnalyticsConfig( true // track boolean user attributes as 0/1 on iOS ); const initConfig = new MoEInitConfig(pushConfig, logConfig, analyticsConfig); ReactMoE.initialize('YOUR_MOENGAGE_APP_ID', initConfig); ``` -------------------------------- ### ReactMoEngagePersonalize - Experience & Personalization Campaigns Source: https://context7.com/moengage/react-native/llms.txt Fetches A/B test and personalization experience campaigns by key, then reports impression and click events back to MoEngage. ```APIDOC ## ReactMoEngagePersonalize ### Description Fetches A/B test and personalization experience campaigns by key, then reports impression and click events back to MoEngage. ### Methods - **constructor(appId)**: Instantiates the Personalize SDK with your MoEngage App ID. - **fetchExperiencesMeta(statuses)**: Fetches metadata for active and/or scheduled campaigns. - `statuses` (Array): An array of statuses to fetch metadata for (e.g., `ExperienceStatus.ACTIVE`, `ExperienceStatus.SCHEDULED`). - **fetchExperience(experienceKey, attributes)**: Fetches a single experience campaign by its key, with optional personalization attributes. - `experienceKey` (string): The key of the experience campaign to fetch. - `attributes` (object, optional): Key-value pairs for personalization attributes (e.g., `{ user_tier: 'gold', locale: 'en-US' }`). - **fetchExperiences(experienceKeys, attributes)**: Fetches multiple experience campaigns in a single call. - `experienceKeys` (Array): An array of experience campaign keys to fetch. - `attributes` (object, optional): Key-value pairs for personalization attributes. - **experienceShown(campaign)**: Reports that an experience campaign has been shown to the user (impression). - `campaign` (ExperienceCampaign): The campaign object that was shown. - **experienceClicked(campaign)**: Reports that an experience campaign has been clicked. - `campaign` (ExperienceCampaign): The campaign object that was clicked. - **offeringShown(offeringPayload)**: Tracks that a specific offering within a campaign payload has been shown. - `offeringPayload` (object): The payload of the offering that was shown. - **offeringClicked(campaign, offeringPayload)**: Tracks that a specific offering within a campaign payload has been clicked. - `campaign` (ExperienceCampaign): The campaign object containing the offering. - `offeringPayload` (object): The payload of the offering that was clicked. ``` -------------------------------- ### Initialize and Fetch Inbox Messages Source: https://context7.com/moengage/react-native/llms.txt Initialize the Inbox SDK with your MoEngage App ID and fetch all available inbox messages. The fetched data includes message details, click status, and timestamps. ```typescript import MoEReactInbox from 'react-native-moengage-inbox'; import type { MoEInboxMessage } from 'react-native-moengage-inbox'; // Initialize MoEReactInbox.initialize('YOUR_MOENGAGE_APP_ID'); // Fetch all inbox messages const inboxData = await MoEReactInbox.fetchAllMessages(); console.log('Messages:', inboxData.messages); // inboxData.messages: MoEInboxMessage[] // Each MoEInboxMessage has: id, campaignId, text (MoETextContent), isClicked, // media (MoEMedia), action (MoEAction[]), receivedTime, expiry, payload ``` -------------------------------- ### Expo Prebuild Configuration for MoEngage Source: https://context7.com/moengage/react-native/llms.txt Configure MoEngage native settings for Android and iOS within your app.json for Expo projects. This plugin automates native configuration during `expo prebuild`. ```json // app.json { "expo": { "plugins": [ [ "react-native-expo-moengage", { "android": { "configFilePath": "assets/moengage/android_initilisation_config.xml", "smallIconPath": "assets/moengage/small_icon.png", "largeIconPath": "assets/moengage/large_icon.png", "shouldIncludeMoEngageFirebaseMessagingService": true, "includeFirebaseMessagingDependencies": true, "isExpoNotificationIntegration": false, "disableMoEngageDefaultBackupFile": false }, "apple": { "configFilePath": "assets/moengage/MoEngage-Config.plist", "pushNotificationImpressionTrackingEnabled": true, "richPushNotificationEnabled": true, "pushTemplatesEnabled": false, "deviceTriggerEnabled": false, "liveActivityTargetPath": "assets/moengage/LiveActivity" } } ] ] } } ``` -------------------------------- ### Runtime Initialization for MoEngage SDK Source: https://context7.com/moengage/react-native/llms.txt Initialize the MoEngage SDK, Inbox, and Cards modules in your React Native application. Ensure this is called early in the app lifecycle. ```typescript // ExpoSampleApp/app/index.tsx — runtime initialization (same as bare RN) import { useEffect } from 'react'; import ReactMoE, { MoEAppStatus, MoEInitConfig } from 'react-native-moengage'; import MoEReactInbox from 'react-native-moengage-inbox'; import ReactMoEngageCards from 'react-native-moengage-cards'; const APP_ID = 'YOUR_MOENGAGE_APP_ID'; export default function App() { useEffect(() => { ReactMoE.initialize(APP_ID, MoEInitConfig.defaultConfig()); ReactMoE.setAppStatus(MoEAppStatus.Install); MoEReactInbox.initialize(APP_ID); ReactMoEngageCards.initialize(APP_ID); }, []); // ... } ``` -------------------------------- ### Configure MoEngage App ID in JavaScript/TypeScript Source: https://github.com/moengage/react-native/blob/master/README.md Update the MoEngage App ID in the key.js file for the sample application. Replace YOUR_APP_ID with your actual MoEngage App ID. ```javascript export const MOENGAGE_APP_ID = "YOUR_APP_ID" ``` -------------------------------- ### Navigate to App Notification Settings (Android) Source: https://context7.com/moengage/react-native/llms.txt Provide a direct link for users to navigate to the app's notification settings on Android. This is useful for users who wish to change permissions after initial denial. ```typescript import ReactMoE from 'react-native-moengage'; // Android: open app notification settings ReactMoE.navigateToSettingsAndroid(); ``` -------------------------------- ### Subscribe to MoEngage SDK Events Source: https://context7.com/moengage/react-native/llms.txt Register typed callbacks for various SDK events including push token generation, push clicks, in-app campaign lifecycle events, and permission results. Remember to remove listeners when they are no longer needed to prevent memory leaks. ```typescript import ReactMoE, { MoESelfHandledCampaignData, } from 'react-native-moengage'; import type { MoEPushToken, MoEPushPayload, MoEInAppData } from 'react-native-moengage'; // Push token generated ReactMoE.setEventListener('pushTokenGenerated', (tokenData: MoEPushToken) => { console.log('FCM/APNs token:', tokenData); }); // Push notification clicked ReactMoE.setEventListener('pushClicked', (payload: MoEPushPayload) => { console.log('Push clicked payload:', payload); }); // In-app shown ReactMoE.setEventListener('inAppCampaignShown', (data: MoEInAppData) => { console.log('In-app shown for campaign:', data.campaignData); }); // In-app custom action button pressed ReactMoE.setEventListener('inAppCampaignCustomAction', (data: MoEInAppData) => { console.log('Custom action:', data.campaignData); }); // Self-handled in-app: your UI renders the payload ReactMoE.setEventListener('inAppCampaignSelfHandled', (data: MoESelfHandledCampaignData) => { console.log('Self-handled campaign:', data.campaign); // render your own UI, then report impression ReactMoE.selfHandledShown(data); }); // Clean up listeners when component unmounts ReactMoE.removeEventListener('pushClicked'); ``` -------------------------------- ### Register for Push Notifications (iOS) Source: https://context7.com/moengage/react-native/llms.txt Use these methods to request push notification permissions on iOS. `registerForPush` requests standard authorization, while `registerForProvisionalPush` requests quiet authorization. ```typescript import ReactMoE from 'react-native-moengage'; // iOS: request APNs permission ReactMoE.registerForPush(); // iOS: request provisional (quiet) push authorization ReactMoE.registerForProvisionalPush(); ``` -------------------------------- ### Configure MoEngage App ID for Android Source: https://github.com/moengage/react-native/blob/master/README.md Add the MoEngage App ID to the local.properties file in the Android sample app. Ensure you replace YOUR_APP_ID with your actual MoEngage App ID. ```properties moengageAppId=YOUR_APP_ID ``` -------------------------------- ### Configure MoEngage Plugin in app.json Source: https://github.com/moengage/react-native/blob/master/sdk/expo/README.md Add the MoEngage plugin to your Expo project's configuration file. This enables the SDK and allows for custom Android-specific settings. ```json { "expo": { "plugins": [ [ "react-native-expo-moengage", { "android": { "configFilePath": "", "smallIconPath": "", "largeIconPath": "", "includeFirebaseMessagingDependencies": false, "_comment1": "enable includeFirebaseMessagingDependencies to include firebase messaging library while prebuilding moengage expo plugin", "isExpoNotificationIntegration": false, "_comment2": "enable includeFirebaseMessagingDependencies to include moengage firebase service class for receiving notification while supporting expo notification", "shouldIncludeMoEngageFirebaseMessagingService": false, "_comment3": "enable includeFirebaseMessagingDependencies to include moengage firebase service class for receiving notification" } } ] ] } } ``` -------------------------------- ### Handle Huawei PushKit Token (Android) Source: https://context7.com/moengage/react-native/llms.txt Forward Huawei PushKit tokens to the MoEngage SDK on Android when using Huawei devices. ```typescript import ReactMoE from 'react-native-moengage'; // Android: Huawei PushKit token ReactMoE.passPushKitPushToken(hmsToken); ``` -------------------------------- ### Push Notification APIs Source: https://context7.com/moengage/react-native/llms.txt Platform-specific APIs for registering push tokens, forwarding FCM/PushKit payloads, and requesting OS permissions. ```APIDOC ## Push Notification APIs Platform-specific APIs for registering push tokens, forwarding FCM/PushKit payloads, and requesting OS permissions. ### iOS: Request APNs Permission **Description**: Requests authorization for receiving push notifications on iOS. **Method**: `ReactMoE.registerForPush()` ### iOS: Request Provisional Push Authorization **Description**: Requests provisional (quiet) push authorization on iOS, allowing notifications to be delivered silently. **Method**: `ReactMoE.registerForProvisionalPush()` ### Android: Forward FCM Token **Description**: Passes the FCM token to the MoEngage SDK when it is refreshed. **Method**: `ReactMoE.passFcmPushToken(token: string)` **Parameters**: - **token** (string) - Required - The FCM push token. ### Android: Forward Incoming FCM Data Message Payload **Description**: Handles incoming FCM data messages when the app is in the background. **Method**: `ReactMoE.passFcmPushPayload(payload: object)` **Parameters**: - **payload** (object) - Required - The data payload of the FCM message. ### Android: Pass PushKit Push Token **Description**: Passes the Huawei PushKit token to the MoEngage SDK. **Method**: `ReactMoE.passPushKitPushToken(hmsToken: string)` **Parameters**: - **hmsToken** (string) - Required - The PushKit token. ### Android: Request Notification Permission (Android 13+) **Description**: Requests notification permission from the user on Android 13 and above. **Method**: `ReactMoE.requestPushPermissionAndroid()` ### Android: Push Permission Response **Description**: Informs the SDK about the user's response to the notification permission request. **Method**: `ReactMoE.pushPermissionResponseAndroid(isGranted: boolean)` **Parameters**: - **isGranted** (boolean) - Required - True if the permission was granted, false otherwise. ### Android: Update Push Permission Request Count **Description**: Tracks the number of times the push notification permission has been requested. **Method**: `ReactMoE.updatePushPermissionRequestCountAndroid(count: number)` **Parameters**: - **count** (number) - Required - The current request count. ### Android: Setup Notification Channels **Description**: Sets up default notification channels for the application on Android. **Method**: `ReactMoE.setupNotificationChannelsAndroid()` ### Android: Navigate to Settings **Description**: Opens the app's notification settings screen on Android. **Method**: `ReactMoE.navigateToSettingsAndroid()` ``` -------------------------------- ### Configure Android Notification Channels Source: https://context7.com/moengage/react-native/llms.txt Set up default notification channels for the MoEngage SDK on Android. This is essential for categorizing and managing notifications effectively. ```typescript import ReactMoE from 'react-native-moengage'; // Android: setup default notification channels ReactMoE.setupNotificationChannelsAndroid(); ``` -------------------------------- ### In-App Messaging Control Source: https://context7.com/moengage/react-native/llms.txt APIs to control in-app campaign display, set contextual filters, and manage self-handled campaigns. Use `showInApp()` to trigger campaigns, `showNudge()` for lightweight overlays, and context setters for filtering. ```typescript import ReactMoE, { MoEngageNudgePosition } from 'react-native-moengage'; // Trigger in-app display at a logical checkpoint (e.g., screen load) ReactMoE.showInApp(); // Show nudge (lightweight overlay) at a specific position ReactMoE.showNudge(MoEngageNudgePosition.Bottom); // Positions: Top | Bottom | BottomLeft | BottomRight | Any // Apply context filters so only matching campaigns show ReactMoE.setCurrentContext(['HomeScreen', 'PremiumUser']); // Reset context on screen exit ReactMoE.resetCurrentContext(); // Fetch a single self-handled campaign (response via 'inAppCampaignSelfHandled' event) ReactMoE.getSelfHandledInApp(); // Fetch all self-handled campaigns at once const campaigns = await ReactMoE.getSelfHandledInApps(); console.log('Self-handled campaigns:', campaigns); // Report self-handled campaign lifecycle ReactMoE.selfHandledShown(campaignData); // impression ReactMoE.selfHandledClicked(campaignData); // widget click ReactMoE.selfHandledDismissed(campaignData); // dismissed ``` -------------------------------- ### ReactMoE.setEventListener Source: https://context7.com/moengage/react-native/llms.txt Registers typed callbacks for push and in-app lifecycle events. Covers: pushTokenGenerated, pushClicked, inAppCampaignShown, inAppCampaignClicked, inAppCampaignDismissed, inAppCampaignCustomAction, inAppCampaignSelfHandled, permissionResult. ```APIDOC ## ReactMoE.setEventListener — Subscribe to SDK Events ### Description Registers typed callbacks for push and in-app lifecycle events. Covers: `pushTokenGenerated`, `pushClicked`, `inAppCampaignShown`, `inAppCampaignClicked`, `inAppCampaignDismissed`, `inAppCampaignCustomAction`, `inAppCampaignSelfHandled`, `permissionResult`. ### Method Signature ```typescript ReactMoE.setEventListener(eventType: string, callback: Function) ``` ### Parameters * **eventType** (string) - Required - The type of event to listen for. Supported types include: * `pushTokenGenerated` * `pushClicked` * `inAppCampaignShown` * `inAppCampaignClicked` * `inAppCampaignDismissed` * `inAppCampaignCustomAction` * `inAppCampaignSelfHandled` * `permissionResult` * **callback** (Function) - Required - The function to execute when the event occurs. ### Request Example ```typescript import ReactMoE, MoESelfHandledCampaignData, } from 'react-native-moengage'; import type { MoEPushToken, MoEPushPayload, MoEInAppData } from 'react-native-moengage'; // Push token generated ReactMoE.setEventListener('pushTokenGenerated', (tokenData: MoEPushToken) => { console.log('FCM/APNs token:', tokenData); }); // Push notification clicked ReactMoE.setEventListener('pushClicked', (payload: MoEPushPayload) => { console.log('Push clicked payload:', payload); }); // In-app shown ReactMoE.setEventListener('inAppCampaignShown', (data: MoEInAppData) => { console.log('In-app shown for campaign:', data.campaignData); }); // In-app custom action button pressed ReactMoE.setEventListener('inAppCampaignCustomAction', (data: MoEInAppData) => { console.log('Custom action:', data.campaignData); }); // Self-handled in-app: your UI renders the payload ReactMoE.setEventListener('inAppCampaignSelfHandled', (data: MoESelfHandledCampaignData) => { console.log('Self-handled campaign:', data.campaign); // render your own UI, then report impression ReactMoE.selfHandledShown(data); }); // Clean up listeners when component unmounts ReactMoE.removeEventListener('pushClicked'); ``` ``` -------------------------------- ### Set User Profile Properties Source: https://context7.com/moengage/react-native/llms.txt Provides built-in setters for standard user profile fields and a generic setter for custom attributes. Supports string, number, boolean, date (ISO 8601), and location attributes. ```typescript import ReactMoE, { MoEGeoLocation } from 'react-native-moengage'; // Standard fields ReactMoE.setUserName('Jane Doe'); ReactMoE.setUserFirstName('Jane'); ReactMoE.setUserLastName('Doe'); ReactMoE.setUserEmailID('jane.doe@example.com'); ReactMoE.setUserContactNumber('+14155551234'); ReactMoE.setUserGender('female'); ReactMoE.setUserBirthday('1990-05-20T00:00:00Z'); // ISO 8601 // Custom attribute (string, number, boolean, etc.) ReactMoE.setUserAttribute('subscription_tier', 'gold'); ReactMoE.setUserAttribute('loyalty_points', 850); // Custom date attribute (ISO 8601) ReactMoE.setUserAttributeISODateString('last_purchase', '2024-06-01T12:00:00Z'); // Custom location attribute ReactMoE.setUserAttributeLocation( 'home_address', new MoEGeoLocation(40.7128, -74.0060) ); // Built-in location shorthand ReactMoE.setUserLocation(new MoEGeoLocation(37.7749, -122.4194)); ``` -------------------------------- ### User Attribute Setters Source: https://context7.com/moengage/react-native/llms.txt A collection of built-in setters for standard user profile fields plus a generic setter for custom attributes. ```APIDOC ## User Attribute Setters ### Description Provides methods to set standard user profile fields and custom attributes. ### Methods - **setUserName(name: string)** - **setUserFirstName(firstName: string)** - **setUserLastName(lastName: string)** - **setUserEmailID(email: string)** - **setUserContactNumber(phone: string)** - **setUserGender(gender: string)** - **setUserBirthday(birthday: string)** (ISO 8601 format) - **setUserAttribute(key: string, value: any)** - **setUserAttributeISODateString(key: string, value: string)** (ISO 8601 format) - **setUserAttributeLocation(key: string, location: MoEGeoLocation)** - **setUserLocation(location: MoEGeoLocation)** ### Parameters Refer to individual method signatures above. ### Request Example ```typescript import ReactMoE, { MoEGeoLocation } from 'react-native-moengage'; // Standard fields ReactMoE.setUserName('Jane Doe'); ReactMoE.setUserFirstName('Jane'); ReactMoE.setUserLastName('Doe'); ReactMoE.setUserEmailID('jane.doe@example.com'); ReactMoE.setUserContactNumber('+14155551234'); ReactMoE.setUserGender('female'); ReactMoE.setUserBirthday('1990-05-20T00:00:00Z'); // ISO 8601 // Custom attribute (string, number, boolean, etc.) ReactMoE.setUserAttribute('subscription_tier', 'gold'); ReactMoE.setUserAttribute('loyalty_points', 850); // Custom date attribute (ISO 8601) ReactMoE.setUserAttributeISODateString('last_purchase', '2024-06-01T12:00:00Z'); // Custom location attribute ReactMoE.setUserAttributeLocation( 'home_address', new MoEGeoLocation(40.7128, -74.0060) ); // Built-in location shorthand ReactMoE.setUserLocation(new MoEGeoLocation(37.7749, -122.4194)); ``` ### Response None ``` -------------------------------- ### Enable/Disable MoEngage SDK Source: https://context7.com/moengage/react-native/llms.txt Completely enable or disable the MoEngage SDK. This provides a way to turn off all SDK functionalities, including tracking and communication. ```typescript import ReactMoE from 'react-native-moengage'; // Enable/disable the entire SDK ReactMoE.disableSdk(); ReactMoE.enableSdk(); ``` -------------------------------- ### Inbox SDK (`react-native-moengage-inbox`) Source: https://context7.com/moengage/react-native/llms.txt Provides CRUD and analytics operations on the user's persistent notification inbox. ```APIDOC ## Inbox SDK (`react-native-moengage-inbox`) ### `MoEReactInbox` — Notification Inbox Provides CRUD and analytics operations on the user's persistent notification inbox. Initialize with the same App ID as the core SDK. ### Initialize Inbox SDK **Description**: Initializes the Inbox SDK with your MoEngage App ID. **Method**: `MoEReactInbox.initialize(appId: string)` **Parameters**: - **appId** (string) - Required - Your MoEngage App ID. ### Fetch All Inbox Messages **Description**: Fetches all messages from the user's notification inbox. **Method**: `await MoEReactInbox.fetchAllMessages()` **Returns**: - An object containing a `messages` array of `MoEInboxMessage` objects. - Each `MoEInboxMessage` has properties: `id`, `campaignId`, `text` (MoETextContent), `isClicked`, `media` (MoEMedia), `action` (MoEAction[]), `receivedTime`, `expiry`, `payload`. ### Get Unclicked Message Count **Description**: Retrieves the count of unread (unclicked) messages in the inbox. **Method**: `await MoEReactInbox.getUnClickedCount()` **Returns**: - (number) - The number of unread messages. ### Track Message Clicked **Description**: Marks a specific inbox message as clicked and updates the unread count. **Method**: `MoEReactInbox.trackMessageClicked(message: MoEInboxMessage)` **Parameters**: - **message** (MoEInboxMessage) - Required - The message object to track as clicked. ### Delete Message **Description**: Deletes a specific message from the user's inbox. **Method**: `MoEReactInbox.deleteMessage(message: MoEInboxMessage)` **Parameters**: - **message** (MoEInboxMessage) - Required - The message object to delete. ``` -------------------------------- ### In-App Messaging APIs Source: https://context7.com/moengage/react-native/llms.txt APIs to control in-app campaign display, set contextual filters, and manage self-handled campaigns. ```APIDOC ## In-App Messaging APIs ### Description Control when in-app campaigns are shown, set contextual filters, and manage self-handled (custom-rendered) campaigns. ### Methods - **showInApp()**: Triggers in-app display at a logical checkpoint. - **showNudge(position: MoEngageNudgePosition)**: Shows a nudge (lightweight overlay) at a specific position. - **setCurrentContext(context: string[])**: Applies context filters so only matching campaigns show. - **resetCurrentContext()**: Resets the current context filters. - **getSelfHandledInApp()**: Fetches a single self-handled campaign. - **getSelfHandledInApps()**: Fetches all self-handled campaigns. - **selfHandledShown(campaignData)**: Reports an impression for a self-handled campaign. - **selfHandledClicked(campaignData)**: Reports a click for a self-handled campaign. - **selfHandledDismissed(campaignData)**: Reports a dismissal for a self-handled campaign. ### Parameters - **position** (MoEngageNudgePosition) - Required for `showNudge`. Possible values: `Top`, `Bottom`, `BottomLeft`, `BottomRight`, `Any`. - **context** (string[]) - Required for `setCurrentContext`. An array of strings representing context identifiers. - **campaignData** - Required for reporting methods (`selfHandledShown`, `selfHandledClicked`, `selfHandledDismissed`). Data associated with the self-handled campaign. ### Request Example ```typescript import ReactMoE, { MoEngageNudgePosition } from 'react-native-moengage'; // Trigger in-app display ReactMoE.showInApp(); // Show nudge at bottom ReactMoE.showNudge(MoEngageNudgePosition.Bottom); // Apply context filters ReactMoE.setCurrentContext(['HomeScreen', 'PremiumUser']); // Reset context on screen exit ReactMoE.resetCurrentContext(); // Fetch self-handled campaigns ReactMoE.getSelfHandledInApp(); const campaigns = await ReactMoE.getSelfHandledInApps(); console.log('Self-handled campaigns:', campaigns); // Report self-handled campaign lifecycle (assuming campaignData is available) // ReactMoE.selfHandledShown(campaignData); // ReactMoE.selfHandledClicked(campaignData); // ReactMoE.selfHandledDismissed(campaignData); ``` ### Response - `getSelfHandledInApps()` returns an array of campaign data objects. - Other methods do not return explicit values but trigger SDK actions or event callbacks. ``` -------------------------------- ### Notify SDK of Device Rotation (Android) Source: https://context7.com/moengage/react-native/llms.txt Inform the MoEngage SDK when a device orientation change occurs on Android. This helps in re-rendering in-app messages correctly. ```typescript import ReactMoE from 'react-native-moengage'; // Android: notify SDK of device rotation (in-app re-render) ReactMoE.onOrientationChanged(); ``` -------------------------------- ### Control Data Tracking Source: https://context7.com/moengage/react-native/llms.txt Globally enable or disable data tracking for the MoEngage SDK. When disabled, no events or user attributes are tracked. Use `enableDataTracking` to re-enable. ```typescript import ReactMoE from 'react-native-moengage'; // Global data tracking opt-out (no events or attributes tracked when disabled) ReactMoE.disableDataTracking(); ReactMoE.enableDataTracking(); // re-enable ``` -------------------------------- ### Identify User with Unique ID or Attributes Source: https://context7.com/moengage/react-native/llms.txt Associates the current device session with a user identity. Can accept a simple unique ID string or a dictionary of identity key-value pairs. Use `getUserIdentities()` to retrieve current identities. ```typescript import ReactMoE from 'react-native-moengage'; // Simple unique ID ReactMoE.identifyUser('user_abc_123'); // Multiple identity attributes ReactMoE.identifyUser({ email: 'jane.doe@example.com', phone: '+14155551234', customer_id: 'CUST-7890', }); // Retrieve current identities const identities = await ReactMoE.getUserIdentities(); console.log(identities); // Expected output: { email: "jane.doe@example.com", customer_id: "CUST-7890", ... } ``` -------------------------------- ### ReactMoE.identifyUser Source: https://context7.com/moengage/react-native/llms.txt Associates the current device session with a user identity. Accepts either a plain unique ID string or a dictionary of identity key-value pairs. ```APIDOC ## ReactMoE.identifyUser ### Description Associates the current device session with a user identity. Accepts either a plain unique ID string or a dictionary of identity key-value pairs. Replaces the deprecated `setUserUniqueID`. ### Method ```typescript ReactMoE.identifyUser(userIdentity: string | { [key: string]: string }) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **userIdentity** (string | object) - Required - A unique user ID string or an object containing identity key-value pairs (e.g., `{ email: '...', phone: '...' }`). ### Request Example ```typescript import ReactMoE from 'react-native-moengage'; // Simple unique ID ReactMoE.identifyUser('user_abc_123'); // Multiple identity attributes ReactMoE.identifyUser({ email: 'jane.doe@example.com', phone: '+14155551234', customer_id: 'CUST-7890', }); ``` ### Response None. Use `ReactMoE.getUserIdentities()` to retrieve current identities. ``` -------------------------------- ### Request Notification Permission (Android 13+) Source: https://context7.com/moengage/react-native/llms.txt Request notification permission on Android 13 and above. Use `pushPermissionResponseAndroid` to pass the user's OS-level decision and `updatePushPermissionRequestCountAndroid` to track request attempts. ```typescript import ReactMoE from 'react-native-moengage'; // Android: request notification permission (Android 13+) ReactMoE.requestPushPermissionAndroid(); ReactMoE.pushPermissionResponseAndroid(true); // pass OS result ReactMoE.updatePushPermissionRequestCountAndroid(3); // track request count ``` -------------------------------- ### ReactMoE.logout Source: https://context7.com/moengage/react-native/llms.txt Notifies the SDK that the user has logged out, clearing the association between the device and the previously identified user. ```APIDOC ## ReactMoE.logout ### Description Notifies the SDK that the user has logged out. Clears the association between the device and the previously identified user. ### Method ```typescript ReactMoE.logout() ``` ### Parameters None ### Request Example ```typescript import ReactMoE from 'react-native-moengage'; const handleLogout = () => { ReactMoE.logout(); // Navigate to login screen }; ``` ### Response None ``` -------------------------------- ### ReactMoEngageCards - Content Cards Feed Source: https://context7.com/moengage/react-native/llms.txt Manages a persistent cards feed with lifecycle, category filtering, click/impression tracking, and deletion. ```APIDOC ## ReactMoEngageCards ### Description Manages a persistent cards feed with lifecycle, category filtering, click/impression tracking, and deletion. ### Methods - **setSyncCompleteListener(callback)**: Registers a callback to be invoked when cards are synced. - **initialize(appId)**: Initializes the Content Cards SDK with your MoEngage App ID. - **onCardSectionLoaded(callback)**: Signals that the cards section is visible and triggers a sync callback. - **getCardsCategories()**: Fetches all available card categories. - **isAllCategoryEnabled()**: Checks if the 'All' category is enabled. - **getCardsForCategory(category)**: Fetches cards for a specific category. - **fetchCards()**: Fetches all cards regardless of category. - **cardShown(card)**: Tracks that a card has been shown to the user (impression). - **cardClicked(card, widgetId)**: Tracks that a card has been clicked, with an optional widget identifier. - **getNewCardsCount()**: Retrieves the count of new cards. - **getUnClickedCardsCount()**: Retrieves the count of unclicked cards. - **deleteCard(card)**: Deletes a specific card. - **deleteCards(cards)**: Deletes multiple cards. - **refreshCards(callback)**: Manually refreshes the cards and invokes a callback upon completion. - **onCardSectionUnLoaded()**: Signals that the cards section is hidden. - **cardDelivered()**: Tracks the delivery of a card. ``` -------------------------------- ### Data Tracking & Privacy Controls Source: https://context7.com/moengage/react-native/llms.txt APIs to enable or disable data tracking and specific device identifier tracking for compliance purposes. ```APIDOC ## Data Tracking & Privacy Controls Enable or disable data tracking and specific device identifier tracking for compliance use cases. ### Disable Data Tracking **Description**: Globally disables all event and attribute tracking by the MoEngage SDK. **Method**: `ReactMoE.disableDataTracking()` ### Enable Data Tracking **Description**: Re-enables data tracking after it has been disabled. **Method**: `ReactMoE.enableDataTracking()` ### Disable SDK **Description**: Disables the entire MoEngage SDK, stopping all functionality. **Method**: `ReactMoE.disableSdk()` ### Enable SDK **Description**: Re-enables the MoEngage SDK after it has been disabled. **Method**: `ReactMoE.enableSdk()` ### Android: Enable Advertising ID Tracking **Description**: Enables tracking of the Advertising ID on Android. This is disabled by default. **Method**: `ReactMoE.enableAdIdTracking()` ### Android: Disable Advertising ID Tracking **Description**: Disables tracking of the Advertising ID on Android. **Method**: `ReactMoE.disableAdIdTracking()` ### Android: Enable Android ID Tracking **Description**: Enables tracking of the Android ID on Android. This is disabled by default. **Method**: `ReactMoE.enableAndroidIdTracking()` ### Android: Disable Android ID Tracking **Description**: Disables tracking of the Android ID on Android. **Method**: `ReactMoE.disableAndroidIdTracking()` ### Android: Disable Device ID Tracking **Description**: Disables tracking of the Device ID on Android. This is enabled by default. **Method**: `ReactMoE.disableDeviceIdTracking()` ### Android: Enable Device ID Tracking **Description**: Enables tracking of the Device ID on Android. **Method**: `ReactMoE.enableDeviceIdTracking()` ### Android: Notify Orientation Changed **Description**: Notifies the MoEngage SDK of a device orientation change, which may trigger an in-app re-render. **Method**: `ReactMoE.onOrientationChanged()` ``` -------------------------------- ### Delete User Data (Android Only) Source: https://context7.com/moengage/react-native/llms.txt Requests deletion of all user data from MoEngage servers. This is an Android-only feature and returns a `UserDeletionData` object indicating success or failure. ```typescript import ReactMoE from 'react-native-moengage'; import type { UserDeletionData } from 'react-native-moengage'; const handleDeleteAccount = async () => { const result: UserDeletionData = await ReactMoE.deleteUser(); if (result.isSuccess) { console.log('User data deleted for workspace:', result.accountMeta.appId); } else { console.warn('Deletion failed for workspace:', result.accountMeta.appId); } }; ``` -------------------------------- ### User Logout Source: https://context7.com/moengage/react-native/llms.txt Notifies the SDK that the user has logged out, clearing the association between the device and the previously identified user. Typically followed by navigation to a login screen. ```typescript import ReactMoE from 'react-native-moengage'; const handleLogout = () => { ReactMoE.logout(); // Navigate to login screen }; ```