Overview
Starting with v7.0.0., the MoEngage Capacitor SDK supports file-based initialization.
Script-based Initialization
This approach outlines how to use the form-based interface to generate a validated code snippet for initialization and to access module-specific configurations. Follow these steps to generate your initialization script:- Navigate to the Initialization Website.
- Configure the values based on your application requirements. Refer to the Configuration Parameters tables below.
- 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
Android Configuration
Add Configuration File
Place the generatedmoengage.xml file in your Capacitor Android project at android/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 Configurations
iOS Configurations
Data Center Values
Configure the integer corresponding to your region. Incorrect values will result in data loss.Update Info.plist
- Open your project’s
Info.plist(found inios/App/App/Info.plist). - Create a new Top-Level Key named
MoEngageof typeDictionary. - Add the configuration file content generated in the Initialization Website.
Framework Level Initialization
After you configure the native files, you need to trigger the initialization in both your native wrappers and your Capacitor framework.Android Native Setup
Before initializing the SDK from JavaScript, initialise the native module in your Android Application class. Add the following toandroid/app/src/main/java\<your\_package\>/MainApplication.java (or .kt) inside onCreate().
File-based init (reads configuration from res/values/ XML, e.g. moengage.xml):
iOS Native Setup
Ensure yourAppDelegate.swift triggers the SDK initialization using the default instance method, allowing it to read from your Info.plist.
Initialize Capacitor Component
After native Android setup, initialize the plugin from your app entry or root component (e.g.,app.component.ts, main.ts, or index.ts/js) o the bridge and initConfig are registered before you call other MoEngage Capacitor APIs.
Migration and Precedence
To migrate from manual code-based initialization to the file-based approach, refer here.Environments (Test vs. Live)
You can configure Test/Live environments within these files.- Android: Use the key
<string name="com_moengage_core_environment">test</string>. - iOS: Use
<key>IsTestEnvironment</key> <true/>