Overview
Starting with v12.0.0, the React Native SDK supports file-based initialization.
Alternatively, the SDK can be initialized manually. If you require this approach, please refer to the guide on Framework Initialization.
Script-based Initialization
Follow these steps to generate your initialization script:1
Visit the Config Generator
Navigate to the Initialization Website.
2
3
Generate
Click Generate Code at the bottom of the form.
Android Configuration (XML)
For Android, initialization is handled by placing an XML configuration file in the application’s resource directory.Android Configuration Reference
Below is the comprehensive list of keys available formoengage.xml.
Android Configuration Details
Android Configuration Details
Add Configuration File
Place the generated file inandroid/app/src/main/res/values/.
iOS Configuration (Info.plist)
For iOS, initialization is handled by adding a configuration dictionary to yourInfo.plist.
iOS Configuration Reference
Below is the comprehensive list of keys available for theMoEngage dictionary.
iOS Configuration Details
iOS Configuration Details
Data Center Values
Configure the integer corresponding to your region. Incorrect values will result in data loss.Update Info.plist
1
Open Plist
Open your project’s
Info.plist (found in ios/ProjectName/).2
Create MoEngage Dictionary
Create a new Top-Level Key named
MoEngage of type Dictionary.3
Configure
Add the configuration file content generated in the Initialization Website.
- XML
Framework Level Initialization
After you configure the native files, the initialization code in your hybrid framework is simplified.Android Native Setup
Add the following code toandroid/app/src/main/java/com/your_app/MainApplication.java (or .kt) inside the onCreate() method.
- Kotlin
- Java
iOS Native Setup
Add the following code to yourAppDelegate class inside the didFinishLaunchingWithOptions method.
- Swift
- Objective-C
Initialize React-Native Component
Initialize the MoEngage Plugin in the App.js or App.ts of your application once the component is mounted.- TypeScript
If you have a class-based component, you can initialize in the
render() or componentDidMount().Migration and Precedence
To migrate from manual code-based initialization to file-based approach, refer here.Environments (Test vs. Live)
You can configure Test/Live environments within these files:- Android: Use
<string name="com_moengage_core_environment">test</string>. - iOS: Use
<key>IsTestEnvironment</key> <true/>.