Skip to content

monoku/cordova-plugin-leanplum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

cordova-plugin-leanplum

Use Leanplum Plugin in Cordova projects

Table of contents

The SDK methods implemented

The SDK callbacks implemented

Installation

$ cordova plugin add https://github.com/monoku/cordova-plugin-leanplum.git --save

Usage

Set Leanplum credentials for development

const { NSLeanplum } = window.cordova.plugins;

NSLeanplum.setAppIdForDevelopmentMode(<appId>, <setAppIdForProductionMode>, success, error);

Set leanplum credentials for production

const { NSLeanplum } = window.cordova.plugins;

NSLeanplum.setAppIdForProductionMode(<appId>, <setAppIdForProductionMode>, success, error);

Set variables

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],
});

Start

const { NSLeanplum } = window.cordova.plugins;

NSLeanplum.start();

Set userId

const { NSLeanplum } = window.cordova.plugins;

NSLeanplum.setUserId(id, success, error);

Set user attributes

const { NSLeanplum } = window.cordova.plugins;

NSLeanplum.setUserAttributes({
  name: 'My name',
  email: 'foo@example.com',
  age: 20,
});

Track events

const { NSLeanplum } = window.cordova.plugins;

NSLeanplum.track('Purchase', {itemCategory: 'Apparel', itemName: 'Shoes'});

Get a variable

Get a specific variable

const { NSLeanplum } = window.cordova.plugins;

NSLeanplum.getVariable('variable_name', (data) => {
  console.log(data.value) // variable_value
});

Get variables

Get list of variables

const { NSLeanplum } = window.cordova.plugins;

NSLeanplum.getVariables((variables) => {
  console.log(variables) // { stringVar: 'Some string variable', numVar: 1, ... }
});

Callbacks

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.

onStartResponse

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');
});

onValueChanged

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
});

onVariablesChanged

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, ... }
});

Leanplum SDK

https://docs.leanplum.com/reference

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •