Events in React Native SDK

Events sent through onMessageReceived

The SDK offers a mechanism to communicate events occuring in the native module or in the Experience so your app can maintain control of its operations. This is achieved through a property onMessageReceived in the MonterosaSdkExperienceView.

The messages received will always contain a type string to act as a discriminator between event types, and a payload.

For instances, the following code prints the type and payload of events:

const onMessageReceived = (e) => {
  console.log('Type: ', e.nativeEvent.type);
  console.log('Payload: ', e.nativeEvent.payload);
};

return (
  <MonterosaSdkExperienceView
    style={{
      flex: 1
    }}
    onMessageReceived={onMessageReceived}
    configuration={config}
    ref={viewNode}
  />
);

Message catalog

This section outlines the potential messages you'll receive.

Debug messages

These messages are helpful to understand what's happening in the native module and the Experience itself.

{
    type: "debug"
    payload: {
        message: <Debug message>
    }
}

Experience messages:

These messages originate from the Experience itself. They can be used for a range of scenarios, such as reporting the size of the Experience, or responding to requests for data sent from the app.

{ 
    type: "experienceMessage",
    payload: {
        action: <The mesage action,
        payload: <A Payload sent from the Experience, usually a dictionary>,
        respondingTo: <The ID of the message its responding to>,
        source: <Either "sdk" or "user" depending on whether it's an internal message or not>,
    }
}

Identify Events

These messages are sent when an event has been triggered in Identify, an API service Monterosa offers to facilitate SSO between the parent app and the Experience.

There's multiple types of events being emitted here, looking like so:

Did update credentials

Called when the credentials are updated by either you or the Experience.

{ 
    type: "identifyEvent",
    payload: {
        event: "didUpdateCredentials",
        credentials: <token set>
    }
}

Did update user data

Called when the Experience requests the user data. This value will be expired in 10 seconds, the call will be repeated then with a null signature.

{ 
    type: "identifyEvent",
    payload: {
        event: "didUpdateUserData",
        userData: <A dictionary with the user data. This will depend on your SSO integration>
    }
}

Did update session signature

Received when the user is logged in by the Experience and a signature is generated. This value will be expired in 10 seconds, the call will be repeated then with a null signature.

{ 
    type: "identifyEvent",
    payload: {
        event: "didUpdateSessionSignature",
        signature: {
            sig: <The signature hash>,
            userId: <The ID of the user>,
            timestamp: <Timestamp in seconds>
        }
    }
}

Did request login

Requested by the Experience when the user interacts with gated content to drive sign ups.

{ 
    type: "identifyEvent",
    payload: {
        event: "didRequestLoginByExperience"
    }
}

Did fail to validate credentials

Called when there was a problem while validating the credentials or logging in the user.

{ 
    type: "identifyEvent",
    payload: {
        event: "didFailCredentialsValidation",
        error: {
            error: <toString of the error reported>,
            message: <A message explaining what happened in the SDK>
        }
    }
}

Experience Events

Did start loading

Called when the Experience starts loading

{ 
    type: "experienceEvent",
    payload: {
        event: "didStartLoading"
    }
}

Did end loading

Called when the Experience finishes loading

{ 
    type: "experienceEvent",
    payload: {
        event: "didEndLoading"
    }
}

Did fail loading

Called when the Experience fails to load

{ 
    type: "experienceEvent",
    payload: {
        event: "didFailLoading",
        error: {
            error: <toString of the error reported>,
            message: <A message explaining what happened in the SDK>
        }
    }
}

Did change intrinsic size

Called when the Experience content changes, requiring a new size to avoid using internal scroll bars.

{ 
    type: "experienceEvent",
    payload: {
        event: "didChangeIntrinsicSize",
        size: {
            "width": <Required width>,
            "height": <Required height>
        }

    }
}

Did become ready

Called when the Experience has completed parsing the HTML & JSS code used, and is ready to start sending and receiving messages.

{ 
    type: "experienceEvent",
    payload: {
        event: "didBecomeReady",
        size: {
            "width": <Required width>,
            "height": <Required height>
        }

    }
}

Errors

Sent when an error occurs in the SDK, for instance when a request is sent to the Experience and no response is received.

{ 
    type: "error",
    payload: {
        error: <toString of the error reported>,
        message: <A message explaining what happened in the SDK>
    }
}