Usage with Listeners

Using the npm package allows you to utilize listener functions which are invoked when an event occurs. These are similar to on-page JavaScript callback functions but are easier to implement.

👍

Event/Listener timing

If an event occurs before the listener is registered the event will be queued and available to the listener once the listener initializes.

Add listener

Register listener, function will be called when the corresponding event is triggered.

App Resumed Event

const listenerId = Median.appResumed.addListener(() => {
    console.log("App resumed listener");
});

OneSignal plugin

Documentation

const listenerId = Median.oneSignalPushOpened.addListener((data) => {
    console.log(JSON.stringify(data));
});

Share into app plugin

Documentation

const listenerId = Median.shareToApp.addListener((data) => {
    console.log(data.url, data.subject);
});

Haptics plugin

Documentation

const listenerId = Median.deviceShake.addListener(() => {
    console.log("Device shake listener");
});

AppsFlyer plugin

Documentation

const listenerId = Median.appsFlyerConversionData.addListener((conversionDataMap) => {
    console.log(conversionDataMap.af_status);
});

Remove listener

Remove a specific listener so that it will no longer be called when the corresponding event is triggered

Median.deviceShake.removeListener(listenerId);