Leanplum's user guides and developer documentation.

Leanplum Documentation

Leanplum's user guides, SDK setup, API docs, and more resources are here to help you get the most out of A/B testing, Campaigns, Messaging, and Analytics.

Built-in variables

Leanplum variables

Leanplum includes many predefined variables to access user profile data. New variables may be added over time. To preserve compatibility, any custom variables you declare have precedence over the built-in variables.

Behavioral data

Includes information about a user’s activity, such as what events and states they have triggered. These variables are contextual, and evaluated for each user.

Variable name

Type

Description

appVersion

String

Which version of your app the user is using.

firstOccurrenceOf['eventOrStateName']

Date

The time that the event or state first occurred. Dates can be formatted using the date filter.

lastOccurrenceOf['eventOrStateName']

Date

The time that the event or state last occurred.

occurrencesOf['eventOrStateName']

Integer

The number of times the user has tracked the event or state.

Recent occurrences "eventOrStateName" "X"

Number

The number of times the user has tracked the event or state in the last "X" days.

valueOf['eventName']

Number

The lifetime value of a particular event

lifetimeValue

Number

The user’s lifetime value designated by the purchase event.

A gaming app could, for example, include personalized information about a user's high scores in their message:

{{ userAttribute['Player name']}}, 
congrats on your level 14 score of {{valueOf['level14']}}!!

You now have {{lifetimeValue['totalCoins']}} total coins. 

Ready for level 15?

Lifecycle data

Includes information about when and how often a user is engaging with your app.

Variable name

Type

Description

numPriorSessions

Integer

The number of sessions recorded in the user’s lifetime.

firstRun

Date

The time that the user was first seen.

lastActive

Date

The time that the user was last active.

minutesSpentInApp

Number

The number of lifetime minutes spent in the app.

Localization data

Localization data include the user’s location and localization preferences.

Variable name

Type

Description

country

String

The user’s country code.

region

String

The user’s region (state, province, etc.)

city

String

The user’s city.

locale

String

The user’s locale code.

language

String

The user’s language code.

timezone

String

The user’s timezone code.

Technology data

Includes information about the user’s current device.

Variable name

Type

Description

deviceId

String

The user’s current device ID.

deviceModel

String

The user’s current device model.

osName

String

The user’s current OS name (e.g. iOS, Android)

osVersion

String

The user’s current OS version.

browserName

String

The user’s current browser name.

browserVersion

String

The user’s current browser version.

pushEnabled

Boolean

Whether the user can receive push notifications, including data-only notifications.

textPushEnabled

Boolean

Whether the user can receive push notifications that can display text.

Traffic Source data

Includes information about where your users came from when installing your app. To use these, you need to set up an integration with one of our attribution partners. See partners.

Variable name

Type

Description

sourcePublisherId

String

The publisher ID of the referrer.

sourcePublisher

String

The publisher name of the referrer.

sourceSubPublisher

String

The sub publisher name of the referrer.

sourceSite

String

The site name of the referrer.

sourceCampaign

String

The campaign name of the referrer.

sourceAdGroup

String

The ad group name of the referrer.

sourceAd

String

The ad name of the referrer.

User data

Includes the user’s ID and custom attributes.

Variable name

Type

Description

developerMode

Boolean

Whether the user is a developer.

userBucket

Integer

The user’s randomized bucket from 0-999, used for randomizing content to different groups of users.

userId

String

The user’s ID, which may be the device ID if no user ID was provided.

userAttribute['attributeName']

String

A custom user attribute value within the user’s profile.

Contextual data

For triggered messages, contextual variables are used to access information about the trigger that activated the message. For example, a shopping cart abandonment message could be triggered by an “Add to Cart” event. This event may contain parameters including the item, quantity, and price of the item that was added to the cart.

Messages sent via the sendMessage API

Variable name

Type

Description

value

Any

A custom value that may be provided when calling the sendMessage API programmatically.

🚧

Null values sent through the sendMessage API will insert the key as a string.

If values sent through the sendMessage API /Manual delivery evaluate to null or the key is missing in the sent JSON values, the value will equal the string of the key. Examples:

Jinja code used:
{{"value1"}} or {{value['value1']}}

Values sent:

  1. For a correct value passed in the API call
    {"value1": "some text"}
    The text "some text" will be inserted.

  2. For a null value
    {"value1": null}
    The text "value1" will be inserted.

  3. If no value is passed
    {}
    The text "value1" will be inserted.

To handle this behavior correctly, try the following condition:
{% set v = value['value1'] %}
{% if v and (v != "value1") %}
Value1 is not null. The value passed is: {{v}}
{%else%}
Value1 is null.
{% endif %}

Triggered server-side messages

Variable name

Type

Description

parameter['parameterName']

String

The value of a parameter of the event or state that triggered the message.

previousValue

String

The previous value of the user attribute change that triggered the message.

currentValue

String

The current value of the user attribute change that triggered the message.

triggerTime

Date

The time that the initial trigger occurred.

In-app messages

Variable name

Type

Description

parameter['parameterName']

String

The value of a parameter of the event or state that triggered the message.

previousValue

String

The previous value of the user attribute change that triggered the message.

currentValue

String

The current value of the user attribute change that triggered the message.

🚧

In-app message limitations for contextual values.

For in-app messages, the contextual values above cannot be used with advanced jinja features such as if-statements, for-loops, or filters. The values above can only be printed, e.g. {{previousValue}}.

Linked data variables

Linked data allows you to connect your user profile data with data stored in other sources, like in your own data warehouse or within another service provider. Some examples of linked data include real-time information such as whether an item is in stock, whether a flight is on time or delayed, weather forecasts, or inferred demographic data based on the current user’s attributes.

You can set up linked data sources in your app settings on the Leanplum dashboard. Linked data sources have a name and a URL of the source. The URL itself can be a Leanplum template, which can in turn include other information from a user’s profile. The URL may also include empty placeholders ({}) which must be filled in when accessing the data source.

All linked data is accessible from the linkedData variable:

Variable Name

Data Type

Description

linkedData['data source']

String, Array, or Dictionary

Data available from a particular named data source defined in your app settings. If possible, the data may be cached for several minutes to reduce repeated requests to the particular source. If the data source outputs JSON data, the data is parsed as a dictionary or array, which can be accessed further using loops or dot notation.

linkedData['data source'][arg1][arg2][...]

String, Array, or Dictionary

For parameterized data sources, specify the appropriate number of arguments using dot or subscript notation to fill in all of the missing placeholders.

Examples

Menu

You may have a “menu” data source which emits the following JSON:

{
  "date": "March 10, 2016",
  "items": [
    {
      "name": "Lasagna",
      "image": "http://mydomain.com/images/1001.jpg",
      "price": 11
    }, {
      "name": "Ravioli",
      "image": "http://mydomain.com/images/1002.jpg",
      "price": 12
    }, {
      "name": "Pizza",
      "image": "http://mydomain.com/images/1003.jpg",
      "price": 10
    }
  ]
}

To render the menu in a template, you may use the following markup:

{% for item in linkedData.menu.items %}
  <div>
    <h2>{{ item.name }}: ${{ item.price|round(2) }}</h2>
    <img src="{{ item.image }}" />
  </div>
{% endfor %}

Product pricing

You may have an “item” data source with a parameter for the item SKU, which looks up information about a particular product.

{
  "inStock": true,
  "price": 39.99
}

You can display the price of an item with this template:

The price of the item is 
{{ linkedData.item[parameter.itemSku].price|numberformat('$#,###.00') }}.

Handle missing Data

In the above example, if there was a problem retrieving the data, the price would be null. Leanplum will automatically skip sending the message if a null value is rendered within a message.

In the next example, we display if the item is in stock. Here, we are not rendering a null value, so we need to explicitly skip the message using skipmessage().

{% set item = linkedData.item[parameter.itemSku] %}
{% if item == null %}
 {{ skipmessage() }}
{% elif item.inStock %}
 Your item is in stock at {{ userAttribute.preferredStore }}!
{% else %}
  Your item is not in stock at this time. 
  We’ll notify you when it becomes available.
{% endif %}

Updated 8 months ago


Built-in variables


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.