Communication between the Element and your app can be handled either by PostMessage communication or via HTTP redirects.

Listening to Events

We strongly recommend using one of the Element SDKs to make listening to events easy. They provide you with callback functions that are invoked every time a specific type of event occurs (such as open, success, exit, etc).

Each type of Element will emit its own events. See General Events and Element Specific Events for more information about the events that are emitted.

PostMessage without SDK

To recieve events via PostMessage, pass the query parameter event_channel=message to the Elements url. For example:

https://elements.production.methodfi.com
  ?token=pk_elem_4PpMTPcchb49VBjwP3bREKhMN93hrQHR
  &event_channel=message

To listen to the emitted events, add an event listener onto the window object:

window.addEventListener('message', function(event) {
  const { payload, type } = event.data;
  console.log('Received event!', type, payload);
});

Redirects

Redirects are the default way of listening to element events if you are not using one of the SDKs. Your webview / app should intercept the redirects in order to react accordingly to state changes. All redirect URLs will have the scheme (“prefix”) methodelements. The event source will be the URL host and the payload will be query strings.

HTTP redirects from Method Elements are in the following format:

methodelements://{event_source}?{event_data}