Track Message View States

Track when in-app messages are opened and closed by implementing delegate methods. These methods notify your app when an in-app message appears or closes. Use this information to manage the view hierarchy for your app and to respond to lifecycle events.

In-app messages are shown as the top view controller in the hierarchy of your app. Use these delegate methods to:

  • Pause or resume animations when messages appear or disappear
  • Update UI state when the view hierarchy changes
  • Track analytics about message display
  • Manage app behavior based on message visibility

Use this code to track message view states in version 11 of the SDK for iOS.

The SDK supports the didShow and didClose methods.

1func didShow(inAppMessage message: InAppMessageDetails) {
2    // message shown
3}
4
5func didClose(inAppMessage message: InAppMessageDetails, action: InAppMessageCloseAction) {
6    // message closed
7}

Use this code to track message view states in version 10 or lower of the SDK for iOS.

1func sfmc_didShow(inAppMessage message: [AnyHashable : Any]) {
2  // message shown
3}
4
5func sfmc_didClose(inAppMessage message: [AnyHashable : Any]) {
6  // message closed
7}