Skip to main content

Overview

Starting with v7.0.0., the MoEngage Capacitor SDK supports file-based initialization.
To streamline the integration process and minimize initialization errors, MoEngage supports Script-Based Initialization. This approach allows you to manage App IDs and configuration settings directly within native configuration files, keeping them separate from your application logic.

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:
  1. Navigate to the Initialization Website.
  2. Configure the values based on your application requirements. Refer to the Configuration Parameters tables below.
  3. 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 for moengage.xml.
CategoryXML Key NameTypeDescription
Corecom_moengage_core_workspace_idStringSpecifies your App ID. This field is mandatory.
com_moengage_core_file_based_initialisation_enabledBooleanSet to true to enable this feature.
com_moengage_core_data_centerIntegerDefault: 1. For more info, refer Data Center values.
com_moengage_core_environmentStringSupported values are: default, live, or test.
com_moengage_core_custom_base_domainStringSpecifies the base custom proxy domain to route SDK network traffic through your own subdomain.
com_moengage_core_integration_partnerStringSpecifies the core integration partner. For example, segment or mparticle.
Pushcom_moengage_push_notification_small_iconDrawableResource ID for small icon.
com_moengage_push_notification_large_iconDrawableResource ID for large icon.
com_moengage_push_notification_colorColorNotification accent color.
com_moengage_push_notification_token_retry_intervalIntegerRetry interval (in seconds) for token registration.
com_moengage_push_kit_registration_enabledBooleanIf true, SDK registers for push token.
Logscom_moengage_core_log_levelInteger0 (No Log) to 5 (Verbose). Default: 3.
com_moengage_core_log_enabled_for_release_buildBooleanIf true, prints logs in release builds.
Securitycom_moengage_core_storage_encryption_enabledBooleanEnables local storage encryption.
com_moengage_core_network_encryption_enabledBooleanEnables payload encryption over the network.
Synccom_moengage_core_periodic_data_sync_enabledBooleanEnables periodic data sync in the foreground.
com_moengage_core_background_data_sync_enabledBooleanEnables periodic data sync in the background.
In-Appcom_moengage_inapp_show_in_new_activity_enabledBooleanRequired for specific TV/Android setups.
TroubleshootingIf the XML file is missing or the com_moengage_core_workspace_id is empty, the SDK will throw a ConfigurationMismatchError.

Add Configuration File

Place the generated moengage.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 your Info.plist.

iOS Configuration Reference

Below is the comprehensive list of keys available for the MoEngage dictionary.
CategoryPlist KeyTypeDescription
CoreWorkspaceIdStringSpecifies your App ID. It is a Mandatory field.
IsSdkAutoInitialisationEnabledBooleanSet to true to enable SDK auto initialisation.
DataCenterIntegerSpecifies the Data Center value. This is a Mandatory field. The default value is 1. For more info, refer to Data Center values.
IsTestEnvironmentString / BooleanCustomer selected option (true/false). Default value is: $(SWIFT_ACTIVE_COMPILATION_CONDITIONS).
CustomBaseDomainStringSpecifies the base custom proxy domain to route SDK network traffic through your own subdomain.
IntegrationPartnerStringSpecifies your integration partner. For example, segment or mparticle. Default value: none.
AppGroupNameStringSpecifies the App Group name used for sharing SDK data. Default value: "".
LogsIsLoggingEnabledBooleanSet to true to enable SDK logs.
LoglevelInteger0 to 5. Default: 2.
SecurityIsStorageEncryptionEnabledBooleanEnables local storage encryption. Default value: false.
KeychainGroupNameStringSpecifies the keychain group name used for storing encryption keys. This is a mandatory field if IsStorageEncryptionEnabled is true. Default value: "".
IsNetworkEncryptionEnabledBooleanEnables payload encryption. Default: false.
EncryptionEncodedTestKeyStringDashboard auto-populated string. Used if IsNetworkEncryptionEnabled is true.
EncryptionEncodedLiveKeyStringDashboard auto-populated string. Used if IsNetworkEncryptionEnabled is true.
SyncAnalyticsEnablePeriodicFlushBooleanEnables periodic data flush. Default: true.
AnalyticsPeriodicFlushDurationIntegerFlush interval in seconds. Default: 60.
In-AppInAppDisplaySafeAreaInsetRealDecimal value representing safe area padding. Default: 0.
InAppShouldProvideDeeplinkCallbackBooleanIf true, provides callback on deeplink. Default: false.

Data Center Values

Configure the integer corresponding to your region. Incorrect values will result in data loss.

Update Info.plist

  1. Open your project’s Info.plist (found in ios/App/App/Info.plist).
  2. Create a new Top-Level Key named MoEngage of type Dictionary.
  3. Add the configuration file content generated in the Initialization Website.
The key IsSdkAutoInitialisationEnabled uses the British spelling (‘s’). Ensure you use the exact key name shown below, or initialization will fail.
XML Snippet Representation:
<key>MoEngage</key>
<dict>
    <key>WorkspaceId</key>
    <string>YOUR_WORKSPACE_ID</string>
    <key>IsTestEnvironment</key>
    <string>$(SWIFT_ACTIVE_COMPILATION_CONDITIONS)|$(GCC_PREPROCESSOR_DEFINITIONS)</string>
    <key>DataCenter</key>
    <integer>1</integer>
    <key>CustomBaseDomain</key>
    <string>data.example.com</string>
    <key>IsLoggingEnabled</key>
    <true/>
</dict>

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 to android/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):
import com.moengage.capacitor.MoEInitializer;

@Override
public void onCreate() {
    super.onCreate();
    // ... existing code
    MoEInitializer.initialiseDefaultInstance(this);
}

iOS Native Setup

Ensure your AppDelegate.swift triggers the SDK initialization using the default instance method, allowing it to read from your Info.plist.

import UIKit
import Capacitor

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        MoECapacitorInitializer.sharedInstance.initializeDefaultInstance() 
        
        return true
    }
}

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.
import { MoECapacitorCore } from 'capacitor-moengage-core';

await MoECapacitorCore.initialize({
  appId: 'YOUR_WORKSPACE_ID',
  initConfig: {
    analyticsConfig: {
      shouldTrackUserAttributeBooleanAsNumber: true,
    },
    // Optional — omit if you do not need push click callbacks from JS
    pushConfig: {
      shouldDeliverCallbackOnForegroundClick: true,
    },
  },
  // Optional — queues some callbacks until app returns to foreground
  lifecycleAwareCallbackEnabled: false,
});

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/>