# In\-app messages


In-app messages are shown in the mobile app as a layer over the content (overlay) or as view component injected (added as a subview) into the app (inline).

The guides in this section cover the implementation on the application side. To learn more about in-app messages, their types, and creating the content, see [the User Guide](/docs/campaign/in-app-messages/introduction-to-inapp-messages).


<div class="admonition admonition-warning"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z" /></svg></div><div class="admonition-body"><div class="admonition-content">

Due to operating system differences and web engines, in-app message appearance may differ between systems or not be as expected. You should test your in-app messages.

</div></div></div>


## Requirements
---



The minimum SDK version depends on the feature you use:

| Feature | Android | iOS | React Native | Flutter |
|---|---|---|---|---|
| Overlay in-app messages and listener callbacks | 5.3.0 | 4.12.0 | 0.12.0 | 0.5.0 |
| Closing a message from the app (`closeInAppMessage`) | 6.7.0 | 5.8.0 | 1.5.0 | 2.5.0 |
| Safe area option in the campaign | 6.1.0 | 5.1.0 | bundled native version | bundled native version |
| Context from the app and custom methods | 6.14.0 | 5.14.0 | 1.10.0 | 2.11.0 |
| Inline in-app messages | 6.15.0 (6.16.0 or newer recommended) | 6.0.0 | 2.0.1 | 3.0.0 |

- If your in-app content (such as JavaScript, CSS, images, or fonts) is being loaded from your own server via HTTP and you have configured **CORS policies**, you need to set the **contentBaseUrl** to your server's address. For example, if you're loading resources from `https://www.synerise.com/example/font.woff`, you should configure **contentBaseUrl** to `https://www.synerise.com` (check this option in the [Settings](/developers/mobile-sdk/settings#content-base-url-for-in-app-message)). The value must be a valid absolute URL. An invalid value is ignored and only reported in the SDK log.
- Enable the `IN_APP_DEFINITIONS_COMMUNICATION_READ` (**Experience Hub**) permission in the Profile (formerly Client) [API key](/docs/settings/tool/api) used by the mobile application so the mobile application can fetch in-app messages.  
    <figure><img src="/api/docs/image/219f337699cf7b17198d03b7a7c7f148886e25a1/docs/campaign/_gfx/permission-for-in-app.png" class="full" alt="The API key permission matrix with the in-app permission"><figcaption>The API key permission matrix with the in-app permission</figcaption></figure>
- **Inline** in-apps: embed a placement component in your UI (`InlineInAppView` created with `Injector.createInlineInAppView` on Android and iOS, the `InlineInAppView` React component in React Native). The placement key used in the app must match the one configured in the campaign. See [Inline in-app](/developers/mobile-sdk/campaigns/in-app-message/inline-in-app)
- **Flutter 2.11.0**: configure the SDK's reverse method channel in `MainActivity.configureFlutterEngine`. Without it, the application crashes with a `NullPointerException` on the first in-app callback. iOS needs no extra steps. Starting with Flutter 3.0.0 SDK, this is no longer required.


  <div class="content-tabs code-tabs" data-tab-group="tabgrp-25">
  <div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-25-0" data-tab-group="tabgrp-25" data-tab-active="true">Java</button><button class="tab-button" data-tab-id="tabgrp-25-1" data-tab-group="tabgrp-25">Kotlin</button></div>

  <div class="tab-panel" data-tab-id="tabgrp-25-0" data-tab-group="tabgrp-25" data-tab-active="true">

  ```Java
  @Override
  public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
      super.configureFlutterEngine(flutterEngine);
      SyneriseMethodChannel.configureChannel(flutterEngine);
  }
  ```

  </div>

  <div class="tab-panel" data-tab-id="tabgrp-25-1" data-tab-group="tabgrp-25">

  ```Kotlin
  override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
      super.configureFlutterEngine(flutterEngine)
      SyneriseMethodChannel.configureChannel(flutterEngine)
  }
  ```

  </div>
  </div>


- **React Native**: use `Synerise.Injector` only inside `Synerise.onReady(...)`. Before initialization finishes, the module is `undefined`. `onReady` keeps one callback (the last registration wins), so register in-app listeners once, at the application root.



## Good practices
---

### Campaign planning recommendations

Using a large number of in-app messages in your application can impact rendering time, message delivery, and battery usage.

To maintain optimal application performance when using in-app campaigns:
- Avoid assigning more than 10 in-app messages to the same trigger event.
- Avoid adding more than 10 inline in-app messages to the same placement key.
- Avoid having more than 20 in-app messages active at the same time in your application.
- Review and archive in-app campaigns that you no longer need.  
- In-app tests should be made in a test environment instead of test segmentation in the production environment.

### Template construction

When creating or editing in-app message content:

- Define the close handler (`SRInApp.close()`) at the beginning of the JS script so it works even if later code fails. `SRInApp.hide()` and `SRInApp.resize()` work only in overlay messages; in inline messages they do nothing. `hide()` sends [`inApp.hide`](/docs/assets/events/event-reference/inapp#inapphide), not [`inApp.discard`](/docs/assets/events/event-reference/inapp#inappdiscard), and does not trigger the dismiss callback.
- Use try/catch to handle possible fatal errors in the JS script.
- Handle situations where Jinjava inserts return empty data.
- When adding external links to your message:
    - Only link to sites you trust.
    - Don't link to large images that may negatively affect performance.
    - Don't link to resources whose CSS/HTML may be blocked. If you have resources loaded from your own URLs, set `Synerise.settings.inAppMessaging.contentBaseUrl` and use relative paths in HTML/CSS.
-

## Configuration
---
In-app message campaigns are served by the Synerise backend.
  
Check possible available configuration options in the [Settings](/developers/mobile-sdk/settings#in-app-messaging).

## JavaScript methods in in-app messages
---

See ["Using in-app template builder" in the User Guide](/docs/campaign/in-app-messages/creating-inapp-templates/creating-inapp-template#javascript-methods-in-in-app-messages).

Some methods are only available in one in-app type:

| Method | Overlay | Inline |
|---|---|---|
| `close()`, `closeAndTrigger()`, `openUrl()`, `openDeeplink()`, `handleCustomAction()`, `trackCustomEvent()`, `customMethod()`, `getContextFromApp()`, `internalMethod()`, `getDeviceData()`, `storage.*` | yes | yes |
| `hide()`, `hideAndTrigger()`, `resize()` | yes | no effect |
| `getComponentSize()`, `setComponentSize()`, `onComponentSizeChanged` callback | returns zeros / no effect | yes |


<div class="admonition admonition-note"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

The size-change callback is named `SRInApp.onComponentSizeChanged` on Android and `SRInApp.onComponentSizeChange` on iOS. Templates that use it must define both.

</div></div></div>


## Events generated by in-app messaging
---
For information about events generated by in-app messaging, see the [event reference](/docs/assets/events/event-reference/inapp).


<div class="admonition admonition-note"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

You can disable sending the `inApp.capping` event in the SDK Settings - [Enable/disable sending in-app capping event](/developers/mobile-sdk/settings#enabledisable-sending-inappcapping-event).

</div></div></div>


## Setting up a global control group for in-app message
---
For information about global control groups in in-app messages, see the [global control group](/docs/settings/configuration/global-control-group) article.

## Handling actions from in-app messages
---
Handling main actions from campaigns depends on the campaign type and operating system and it is described [here](/developers/mobile-sdk/campaigns/action-handling).

## Implementing in-app messages in the application
---
See [Overlay in-apps](/developers/mobile-sdk/campaigns/in-app-message/overlay-in-app) and [Inline in-apps](/developers/mobile-sdk/campaigns/in-app-message/inline-in-app)
