Skip to main content
MoEngageChange your setup in the sidebar

Step 1: Install and initialize

Add the Digia Engage SDK and the MoEngage plugin to your React Native, Android, iOS and Flutter app, then initialize both in the right order.

Minimum Supported Versions​

Install​

Note: We assume the core MoEngage SDK is already installed and initialized as part of your standard app setup (see Before you start). The snippets below only cover adding the Digia plugin packages.

Install the Digia packages:

npm install @digia-engage/core@3.6.0 @digia-engage/moengage@2.0.0

Initialize Digia with MoEngage​

Register the Digia MoEngage plugin as soon as MoEngage starts, then initialize Digia. The plugin holds any campaign MoEngage sends until Digia is ready, so registering early means no campaign is missed. A campaign MoEngage sends before the plugin is registered can be lost.

import { useEffect } from 'react';
import ReactMoE from 'react-native-moengage';
import { Digia } from '@digia-engage/core';
import { DigiaMoEngagePlugin } from '@digia-engage/moengage';

export function RootApp() {
useEffect(() => {
(async () => {
// 1. MoEngage SDK — activate the JS bridge.
ReactMoE.initialize('YOUR_MOENGAGE_WORKSPACE_ID');

// 2. Register the Digia MoEngage plugin right away, so no campaign is missed.
// Pass the ReactMoE module directly.
await Digia.register(new DigiaMoEngagePlugin({ moEngage: ReactMoE }));

// 3. Start Digia. Waiting for it is optional (see "Wait for Digia, or not" below).
await Digia.initialize({
apiKey: 'YOUR_ACCESS_KEY',
});
})().catch(console.error);
}, []);

return <AppNavigator />;
}

Wait for Digia, or not​

Digia.initialize returns once campaigns have loaded, or after 2 seconds, whichever comes first. You choose whether your app waits for it:

  • Wait when campaigns at app start matter most. Campaigns are ready before your first screen, but startup can take up to 2 seconds longer.
  • Don't wait when startup speed matters most. Your app starts at once, and campaigns load in the background.
// Wait
await Digia.initialize({ apiKey: 'YOUR_API_KEY' });

// Don't wait
Digia.initialize({ apiKey: 'YOUR_API_KEY' }).catch(console.error);

Either way, campaigns MoEngage sends before Digia is ready aren't lost: the plugin holds them for up to 5 minutes and shows them once Digia is ready.

Optional settings​

Pass these alongside your API key when you initialize. All four are optional: leave any of them out and the SDK uses its default.

await Digia.initialize({
apiKey: 'YOUR_API_KEY',
logLevel: __DEV__ ? 'verbose' : 'error', // 'none' | 'error' | 'verbose'. Default: 'error'
fontFamily: 'Poppins', // a font your app bundles (see Font below)
themeMode: 'auto', // 'auto' | 'light' | 'dark'. Default: 'auto'
// actionHandlers: { ... } // see Campaign Actions
});

Log level (logLevel)​

Sets how much the SDK writes to your app's logs. Every line starts with [DIGIA (plugin lines add the plugin's name, for example [DIGIA-CT]), so search your logs for DIGIA.

LevelWhat it logs
noneNothing, not even errors.
errorOnly failures: a campaign was dropped, an action failed.
warnErrors, plus problems the SDK recovered from, such as a setting that fell back to its default.
infoWarnings, plus milestones: SDK ready, campaigns loaded, a campaign triggered.
debugEverything, including why each campaign showed or didn't. Use this when debugging.
verboseThe same as debug. It's the older name and still works.

Default on Android, iOS and Flutter: if you leave logLevel out, the SDK uses debug in debug builds and error in release builds, so you get full logs while developing without changing anything. iOS treats simulator, development-signed and TestFlight builds as debug builds, and App Store installs as release builds. Flutter treats anything not built in release mode as a debug build. Set a level only to override this, for example debug in a QA build to look into a problem. Take it out again before you ship.

React Native accepts only 'none', 'error' and 'verbose', and defaults to 'error' in every build. Set 'verbose' while debugging: __DEV__ ? 'verbose' : 'error', as in the example above, does that only in development builds.

Action handlers (actionHandlers)​

Lets your app handle deep links, web links and Custom KV commands from campaigns, instead of the SDK's default behavior. See Campaign Actions for the three handlers and how to register them.

Theme (themeMode)​

Colors from your project's design system have a light value and a dark value. themeMode picks which one campaigns use:

ValueCampaigns use
auto (default)The device's light or dark setting. Campaigns on screen switch straight away when the user changes it.
lightAlways the light colors.
darkAlways the dark colors.

Colors set directly on a campaign, rather than picked from the design system, look the same in both themes.

Leave it on auto if your app follows the device setting. If your app supports only one theme, set light or dark so campaigns match it. If your app has its own theme switch, pass the current choice at initialize, then call Digia.setThemeMode whenever the user changes it. Campaigns already on screen update without reloading.

Digia.setThemeMode('dark'); // 'auto' | 'light' | 'dark'

Font (fontFamily)​

Makes campaign text use one of your app's fonts instead of the font set in the dashboard. Bold, medium and other weights from the campaign design are kept: the SDK picks the matching weight from the family, so include every weight your campaigns use. If the SDK can't find the font, it uses the system font instead, so campaigns still show.

Pass one name, and make the font available under that name in both native projects. Most campaigns are drawn by the native SDK, so a font that only lives in your JavaScript assets isn't enough.

  • iOS: add the font files to your app target and list them under UIAppFonts (Fonts provided by application) in Info.plist. The name is the font's family name, for example Poppins.

  • Android: add a font family file at android/app/src/main/res/font/poppins.xml that lists each weight (see the Android tab). Then register it in MainApplication.onCreate, so guides drawn by React Native use it too:

    import com.facebook.react.common.assets.ReactFontManager

    ReactFontManager.getInstance().addCustomFont(this, "Poppins", R.font.poppins)