Use Leanplum Plugin in Cordova projects
- start
- setAppIdForDevelopmentMode
- setAppIdForProductionMode
- setUserId
- track
- setVariables
- getVariable
- getVariables
- setUserAttributes
- advance
- pauseState
- resumeState
- trackAllAppScreens
- setDeviceId
- inbox
- onStartResponse
- onValueChanged
- onVariablesChanged
- onFileReady
- onVariablesChangedAndNoDownloadsPending
$ cordova plugin add https://github.com/monoku/cordova-plugin-leanplum.git --save
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.setAppIdForDevelopmentMode(<appId>, <setAppIdForProductionMode>, success, error);
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.setAppIdForProductionMode(<appId>, <setAppIdForProductionMode>, success, error);
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.setVariables({
stringVar: 'Some string variable',
numVar: 1,
boolVar: true,
mapVar: {
stringVal: 'some string val',
'numVal:': 5,
},
listVar: [1, 2, 3],
});
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.start();
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.setUserId(id, success, error);
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.setUserAttributes({
name: 'My name',
email: 'foo@example.com',
age: 20,
});
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.track('Purchase', {itemCategory: 'Apparel', itemName: 'Shoes'});
Get a specific variable
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.getVariable('variable_name', (data) => {
console.log(data.value) // variable_value
});
Get list of variables
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.getVariables((variables) => {
console.log(variables) // { stringVar: 'Some string variable', numVar: 1, ... }
});
Because Leanplum variables and resources are retrieved from the server asynchronously after start
, you need to wait for the values to be downloaded before using them in your code. The proper way to do this is to use one of these callbacks.
This callback is executed only when the start call finishes and all variables and files are returned from the Leanplum server.
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.onStartResponse(() => {
console.log('start finished');
});
This callback is executed after start every time, but only after forceContentUpdate
if a specific variable has changed.
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.onValueChanged('variable_name', (data) => {
console.log(data.value) // new_variable_value
});
This callback is executed after start every time, but only after forceContentUpdate
if any variable has changed.
const { NSLeanplum } = window.cordova.plugins;
NSLeanplum.onVariablesChanged((variables) => {
console.log(variables) // { stringVar: 'Some string variable', numVar: 1, ... }
});