fusedeck-mobile-sdk-react-native
v1.0.5
Published
## Getting started
Downloads
81
Readme
fusedeck-mobile-sdk-react-native
Getting started
Create an instance of the Fusedeck
class.
import { Fusedeck, Event } from "fusedeck-mobile-sdk-react-native";
const propertyId = 'propXYZ123'; // public id of the property
const endpoint = 'wss://.....'; // Web socket endpoint to send events to
const fusedeck = new Fusedeck(propertyId, endpoint);
You need to specify the propertyId and a WebSocket endpoint. This information will be given to you by your fusedeck consultant.
It is advisable to only instanciate this object once in your application and make it globally available, i.e. by wrapping it into a service. However, if this is not possible you may also create multiple instances wherever they are needed.
Fusedeck will automatically open a WebSocket connection to the specified endpoint. If you have multiple instances of Fusedeck
they will share a WebSocket connection if the property ID is the same.
Handling app lifecycle
Each open WebSocket connection uses server side resources even if it is idle. Therefore it is very important that fusedeck is considered in your app's lifecycle events.
Fusedeck
exposes methods, allowing you to pause and resume the connection. If your app is minimized and running the the background we recommend to pause tracking until the user is opening the app again.
AppState.addEventListener('change', nextAppState => {
switch(nextAppState) {
case 'active':
fusedeck.resume();
break;
case 'background':
case 'inactive':
fusedeck.pause();
break;
}
});
Sending events
Your fusedeck consultant will set up a universal event inside the property. The resulting eventId
needs to be used to identify the event.
The values
field can be any (nested) object. The structure of values
will be defined in the tracking concept and varies from case to case.
import { Fusedeck, Event } from "fusedeck-mobile-sdk-react-native";
const eventId = 12345678;
const event: Event = {
eventId: eventId,
values: {
one: 123,
two: 'test',
three: {
value: 'nested'
}
}
}
fusedeck.sendEvent(event);