LogoLogo
DocsCreator GuideIntegration Guide
  • Introduction
  • Why Monterosa?
  • Platform Buyer FAQ
  • Engagement Use Cases
    • Event Centres
    • Prediction Games
    • Voting
    • Trivia Challenges
    • Competitions & Sweepstakes
    • Sports Data Visualisation
    • Native Apps
    • Global Replication
  • Core Platform Concepts
    • Platform Components
    • App Settings
    • Schedule & Events
    • Timeline
    • Elements
    • Extensions
    • EnMasse Mesh
  • 🎨Creator Guide
    • Welcome
      • Getting an Account
    • Spaces
      • Projects
        • Events
          • Event Templates
          • Event Settings
          • Timeline
            • Elements
            • OpenAI Integration
            • Live Stats
            • Preview
            • Embedding
              • Embedding an Element
          • Analytics
        • Project Settings
          • Localisation
          • Experience URL
          • Content Creation Limits
        • App Settings
        • Activity Log
      • Content
        • Asset Library
        • Automation
          • 🔃Bulk Content Uploader
          • ⚡Live Data Connector
      • Setup
        • Space Settings
        • Apps
        • Integrations
          • Opta Graphics
          • Tagboard
        • Extensions
          • Identify
          • Gamify
          • Forms
          • Geo-Verify
          • Content Bridge
          • Vote Verification
    • Experiences
      • Experience Creator
        • Customising your UI
        • Retrieving Event URLs
    • Team
      • Two-Factor Authentication
      • Setting Up SSO to log in the Monterosa platform
      • User Roles
    • Scaling & Capacity
    • Creator FAQs
  • 🚀Integration Guide
    • Overview
    • Standalone Pages
    • Web Page Embedding
      • Hosting an Experience on your domain
      • Auto-resizing embedded Experiences
    • Native App Embedding
    • Embed using the SDK
    • Discovering Events Programmatically
    • Audience Profiles
      • Audience Profiles Dataset Reference
        • Users dataset
        • Projects dataset
        • Events dataset
        • Elements dataset
        • Interactions dataset
        • Leaderboard (Event) dataset
        • Leagues dataset
        • Form entries dataset
      • Monterosa Identifiers
    • Integrating Identity with your site or app
      • Set up identity using the SDK & JWT
      • Using JWT without the SDK
      • Custom Identity Adaptors
    • Consent Management integration
      • Client-Side Data Storage Explained
    • Analytics integration
    • Integration FAQs
  • 📱FanKit
    • Overview
    • How it works
    • Elements
      • Polls & Voting
        • Brand Survey
        • Poll
        • Reaction Rater
        • Ladder Poll
        • Swing Poll
        • Smash Rater
        • Category Wrapper
        • Category Vote
        • Standalone Vote
        • Team Selector
      • Predictors
        • Predictor
        • Sweepstake
        • Number Predictor
        • Podium Predictor
        • Score Predictor
        • Score Predictor (High)
        • Player Predictor
      • Trivia
        • Trivia
        • Free Type Trivia
        • Ladder Trivia
        • Sorting Trivia
        • Word Trivia
        • Video Trivia
        • Number Trivia
      • Editorial & Media
        • Article
        • External Article
        • Commentary
        • Gallery
        • Image
        • Video
        • Video Carousel
        • Shareable URL
        • Social Embed
        • Form
        • Element Carousel
        • Match Event
        • Substitution
        • Goal
        • Time Event
        • Topic
      • Quiz
        • Quiz Wrapper
        • Quiz Question
      • Series Prediction
        • Series Wrapper
        • Series Score Predictor
        • Series Predictor
        • Series Number Predictor
        • Series Player Predictor
      • Multi Rater
        • Ratings Wrapper
        • Ratings Slider
      • Sports Statistics
        • Opta Widget
        • Stat Callout
        • Stat Comparison
      • Gamification
        • Scoreboard (Event)
        • Scoreboard (Round)
        • Leaderboard (Project)
        • Leaderboard (Event)
        • Leaderboard (Round)
        • Leaderboard (Group)
    • Tips, tricks, tutorials & guides
      • Advanced CSS Overrides
      • Using points and leaderboards
      • Content containers
    • Display Modes
    • Converters
      • Access Gate
      • Form
      • Cards
      • Share Image
      • Featured Links
      • Sponsors
      • Promo Banner
      • Google Ads
    • Localisation
    • Supported Browsers
    • Release Notes
  • 👣DEVELOPER GUIDE
    • Overview
    • Platform Terminology
    • Interaction SDK
      • Download & Initialise the SDK
      • Supported Devices & Operating Systems
      • Roadmap
      • Release Notes
        • React Native
          • v0.2.2
        • JavaScript
          • v0.17.0
          • v0.16.16
          • v0.16.15
          • v0.16.14
          • v0.16.13
          • v0.16.12
          • v0.16.11
        • iOS
          • v0.16.12
          • v0.16.11
        • Android
          • v0.16.13
      • SDK FAQs
    • Embedding Apps
      • Static Embedding
      • Dynamic Embedding
        • Web Behaviours
        • iOS Behaviours
        • Android Behaviours
        • Preloading
        • Caching Content
        • Shared Storage
      • Configure your app
      • Communicate with embedded apps
      • Video Stream Sync
      • React Native
        • Events in React Native SDK
      • Integrate with Flutter
    • Building Apps
      • Quick Start Guide
      • How to build your first app
        • Getting started
        • Get your app running locally
        • Install the Interaction SDK
        • Define your App
        • Set up Studio
        • Develop your App
        • Enable Dynamic Configuration
      • Core SDK Functions
        • Getting and displaying Events
        • Managing Elements
        • Reacting to live updates
        • Dynamic runtime configuration
        • Time
        • Localisation
    • Content Automation
      • Discovering Events
      • Connecting to Google Sheets
      • Connecting to Zapier
      • Connecting to Sports Feeds
    • App Specs
      • App Spec Reference
        • Root Spec
        • Elements Spec
        • Project Settings Spec
        • Event Settings Spec
        • Expressions (beta)
        • Data Sources (beta)
        • External data source
        • Field Types
          • Boolean
          • Collection
          • Colour
          • Datetime
          • External
          • File
          • Freetext
          • Image
          • List
          • Number
          • WYSIWYG
        • Field, Field set, Field section
      • Customising App Specs
    • Available APIs
    • Integrating TV Graphics
    • Advanced Topics
      • Listings
      • Accesssing user concurrency values from your app
      • Custom analytics Extension
      • Front-end app communication protocols
      • Multi Vote
      • Reveal answer on vote
  • ⚙️CONTROL API
    • Overview
    • Objects Definitions
    • Element Reference
    • Organisations
      • Get Organisations
      • Get Organisation
      • Create Organisation
      • Update Organisation
      • Delete Organisation
    • Spaces
      • Get Spaces
      • Get Space
      • Create Space
      • Update Space
      • Delete Space
    • Apps
      • Get Apps
      • Get App
      • Create App
      • Reload App
    • App Settings
    • Projects
      • Get Projects
      • Get Project
      • Create Project
      • Update Project
      • Delete Project
    • Events
      • Get Events
      • Get Event
      • Get Event Service Feeds
      • Create Event
      • Create Event From Template
      • Update Event
      • Delete Event
    • Event Templates
      • Get Event Templates
      • Get Event Template
      • Create Event Template
      • Update Event Template
      • Delete Event Template
    • Elements
      • Get Elements
      • Get Element
      • Get Event Template Elements
      • Create Element
      • Update Element
      • Delete Element
    • Assets
      • Get Assets
      • Upload Assets
      • Update Asset
      • Delete Asset
      • Get Asset Media Types
      • Get Asset Uploaders
      • Asset Tags
        • Add Tag to Asset
        • Remove Tag from Asset
    • Tags
      • Get Tags
      • Get Tag
      • Create Tag
      • Update Tag
      • Delete Tag
  • ⚙️REFERENCE
    • Public Feeds
      • Graphics Feed
    • Listings
    • Elements
    • Event History
    • Demographics
    • Identify
    • Gamify
      • Gamification Mechanics
      • Public API
      • Private API
    • Geo-Verify
    • Browser Support
    • Audience API (Preview)
      • Authentication
        • Monterosa Access Token
        • Public client authentication
      • Batched operations
      • Loyalty API
      • Connections API
    • Image Resizing API
  • ⛓️Extensions
    • Overview
    • Instance handshake
    • Project handshake
    • Project delete
    • Tabs
    • Event Tabs
    • Setup
    • Listings notification
    • Elements notification
    • Analytics
    • Assets
    • Event-level feed
    • Webhooks
  • ⚖️COMPLIANCE
    • Data Requests
    • Data Sub-processors
    • Hosting Locations
    • Third party software
    • ISO27001
  • 🗒️RELEASE NOTES
    • Studio
      • v30.0
      • v29.0
      • v28.0
      • v27.0
      • v26.0
      • v25.0
    • FanKit
      • v24.41.0
      • 24.42.0 Preview
    • Archive
      • v24 releases 2022-23
Powered by GitBook
On this page
  • Sending parameters to the Experience initialisation
  • Sending and receiving messages
  • Awaiting for the Experience to be ready
  • Sending a message
  • Receiving messages from the Experience
  • Responding to a message
  • Awaiting a response
  • Enable Logging

Was this helpful?

  1. DEVELOPER GUIDE
  2. Embedding Apps

Communicate with embedded apps

The SDK allows you to pass parameters, as well as send and receive custom messages to the embedded Experience so as to assist in developing more complex integrations.

This enables us to share information, such as authentication or user preferences (such as language), between the app and Experience, or to react to user interactions in either, such as notifying your app that the user requested to log in.

Sending parameters to the Experience initialisation

The first and simplest way to provide data to the Experience is via embed parameters. This allows the parent application to pass a dictionary of strings to the embedded Experience at the time the Experience is being initialised.

This approach is specially useful for data you want to seed the Experience with from its very inception, such as the language the user prefers, or a parameter that will customise the Experience from start to finish.

The following snippet outlines how this is achieved on each platform:

let config = ExperienceConfiguration(
  parameters: ["customKey" : "customValue"]
)

let experience = Launcher.getExperience(config: config)
<yourView>.addSubview(experience)

// You need to ensure the experiences are laid out however you see fit.
// For instance, could use autolayout constraints, or setting 
// their frame
class MyActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        val config = ExperienceConfiguration(
            parameters = hashMapOf("custom_key" to "custom_value")
        )
        
        val experienceView = Launcher.default.getExperience(this, config))
    }
}
import { 
    embed,
    getExperience,
} from '@monterosa-sdk/launcher-kit';

const exp = getExperience({
  parameters: {
    myCustomParameter: 'myCustomValue',
    anotherParameter: 'true'
  }
})

await embed(experience, 'container-id');

Please note that some parameters are reserved by the SDK. If you were to pass a parameter that overlaps one of the ones we use, we will print a warning on the console, and ignore the value you provided in favour of the value the SDK needs to provide.

The protected parameters are:

  • h, p, and e.

  • Parameters prefixed with mic.

Sending and receiving messages

The other way to exchange data to the Experience is via sending and receiving messages. This allows the parent application and the Experience to send and receive messags between each other.

This is useful for updating the state of the Experience during its runtime, such as notifying about changes in the user log in status, as well as to notify about events, such as a change in the preferred user language.

Awaiting for the Experience to be ready

Given that embedding the Experience on the page is an asynchronous process, we need to await for it to become ready before we can start sending messages, otherwise they wouldn't be received correctly.

If you don't await for the Experience to be ready, your message might be lost.

To identify that the Experience is ready, we can register to receive a notification. The following snippet showcases how to do so:

class MyClass: ExperienceViewDelegate {
    
    func didBecomeReady(from controller: ExperienceView) {
        // experience is ready to accept incoming messages
    }
    
    // Other methods of the delegate
}
class MyActivity : AppCompatActivity(), ExperienceViewListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        ....
        val experienceView = Launcher.default.getExperience(this, config)
        experienceView.listener = this
    }

    override fun onReady(experienceView: ExperienceView) {
        // experience is ready to accept incoming messages
    }
}
import { 
    embed,
    getExperience,
    onReady,
} from '@monterosa-sdk/launcher-kit';

const experience = getExperience();

onReady(experience, () => {
  // experience is ready to accept incoming messages
});

await embed(experience, 'container-id');

Sending a message

A message is an object composed of the following:

  • An action identifying its purpose.

  • A data payload to be exchanged.

It is important to wait before experience is fully embedded before sending messages.

We can send a message by using the following code:

let experience = Launcher.getExperience()
let encodable = ["my": "payload]
experience.sendMessage(action: "my_action", payload: ["my": "payload"])
....
val experience = Launcher.default.getExperience(this, config)
experience.sendMessage("my_action", mapOf("my" to "payload"))
import { 
    embed,
    getExperience,
    sendUserMessage,
    onReady,
} from '@monterosa-sdk/launcher-kit';

const experience = getExperience();

onReady(experience, () => {
    const payload = {}; // payload is a key-value object

    sendMessage(experience, 'my_action', payload);
});

await embed(experience, 'container-id');

Receiving messages from the Experience

Just as your application can send messages to the Experience, so can the Experience send you messages. Using a snippet similar to the next you'll be notified about messages sent by the Experience, and allow you to treat them as expected:

class MyClass: ExperienceViewDelegate {

    func embedExperience() -> ExperienceView {
        let experience = Launcher.getExperience()
        experience.delegate = self
        
        // We assume the caller sets the Experience in the UI
        return experience
    }
    
    func didReceiveMessage(experienceView: ExperienceView, message: MessageData) {
        switch message.action {
        case "my_action":
            let payload = message.payload
            // Do something with the payload received that relates to 
            // the action my_action
        default:
            return
        }
    }
    
    // Other methods of the delegate
}
class MyClass: ExperienceViewListener {
   fun embedExperience() : ExperienceView {
        ....
        val experience = Launcher.default.getExperience(this, config)
        experience.listener = this

        // We assume the caller sets the Experience in the UI
        return experience
    }

    override fun onMessage(experienceView: ExperienceView, message: Message) {
        when (message.action){
            "my_action" -> {
                handlePayload(message.payload)
            }
            else -> {}
        }
    }
}
import { 
  embed,
  getExperience,
  onMessage,
} from '@monterosa-sdk/launcher-kit';

const experience = getExperience();

await embed(experience, 'container-id');

onMessage(experience, (message) => {
  if (message.action === 'my_action') {
    const payload = message.payload;
    
    // Do something with the payload received that relates to 
    // the action my_action
  }
});

Responding to a message

In some scenarios, you'll want to have a request/response pattern when communicating with the Experience. To do so, you will need to first receive a message to respond to, and then respond to it using a snippet similar to the following:

func didReceiveMessage(experienceView: ExperienceView, message: MessageData) {
    switch message.action {
    case "my_action":
        experienceView.respondToRequest(message: message, payload: ["my": "payload"])
    default:
        return
    }
}
override fun onMessage(experienceView: ExperienceView, message: Message) {
    when (message.action){
        "my_action" -> {
            respondToRequest(message, mapOf("my" to "payload"))
        }
        else -> {}
    }
}
onMessage(experience, (message) => {
  if (message.action === 'my_action') {
    respondToMessage(experience, message, { my: "payload" });
  }
});

Awaiting a response

We also offer the possibility of sending a message, and await for a response from the Experience. The following snippet demonstrates how to do so in each of the supported platforms:

let experience = Launcher.getExperience()
let encodable = ["my": "payload]
experience.sendRequest(action: "my_action", payload: payload) { result in
    switch result {
    case .success(let message):
        print(message.action)
        print(message.payload)
    case .failure(let error):
        print(error)
    }
}
val experience = Launcher.default.getExperience(this, config)

experience.sendRequest("my_action", mapOf("my" to "payload")){    
    it.onSuccess { payload ->        
        Log.d("Launcher", "Response payload: $payload")
    }    
    it.onFailure { error ->        
        Log.e("Launcher", "Response payload: ${error.message}")
    }
}
import { 
    embed,
    getExperience,
    onReady,
    sendUserRequest,
} from '@monterosa-sdk/launcher-kit';

const experience = getExperience();

onReady(experience, async () => {
    const payload = {}; // payload is a key-value object

    try {
        const response = await sendRequest(experience, 'my_action', payload);
    } catch (err) {
        console.error("Didn't obtain a response", err);
    }
});

await embed(experience, 'container-id');

Enable Logging

You can enable logging of the messages being sent between your app and Experience so as to help diagnose and fix potential issues in the integration. To do so, you can follow the next snippets:

By adjusting the logging level, you can choose to display only essential information while silencing less critical or verbose log messages.

import MonterosaSDKCommon

let logLevel: Log.Level = .debug
Log.setLogLevel(level: logLevel)

The available log levels are:

case silent
case error
case warning
case info
case debug
case verbose
Core.enableLogging(true)

After enabling logs, they will be shown in Logcat under the kit's corresponding tag, in this scenario, you'll need to filter using the tag LauncherKit.

import { enableLogging } from '@monterosa-sdk/launcher-kit';

enableLogging();

Was this helpful?

👣