Leanplum automatically logs session and user information for you. If you want more detailed information, such as how much ad revenue you made, or how long your users played each level of your game, you can set that up with Events and States.

An event is anything that can occur in your app. Events include clicking on a link, sharing, purchasing, killing enemies, etc. All events are timestamped according to when they occur. Thus, it is not advisable to log too many (thousands) of events, as each one will have to be sent to our server.

A parameter is a piece of data associated with an event or state. You can supply parameters as a dictionary along with events and states. Here are some reports you can run with parameters:

  • Filter reports by event parameter values

  • Group metrics by distinct event parameter values (creates a bar graph + table).

    Example: Show me my top purchased items.

  • Group metrics by ranges of event parameter values (creates a histogram + table).

    Example: Show me the distribution of purchase prices.

    Example: Show me the distribution of points scored.

  • Create custom metrics for numeric parameter values, like totals and averages.

    Example: For a purchase event, track the average revenue and the amount of currency bought per user.

Parameters are not available in Developer activity analytics, but you can verify your parameters are being tracked correctly in the Debugger console.

Events and states accumulate over time, and we send events in batches periodically to minimize network usage and maximize battery life.

Tracking an Event

// User killed an enemy.

// User completed a challenge.
Leanplum.track("Score", challengeValue);

// User liked a post.

// Or, you can supply a dictionary with up to 200 numerical or string parameters.
Map<String, Object> params = new HashMap<String, Object>();
Leanplum.track("Likes", params);

Tracking Purchase or Monetization Events

You can track purchases or other monetization events in Leanplum, which will provide you with revenue metrics in your reports.

In-App Purchases

If your app uses Google Play In-App Billing, Leanplum can automatically track those purchases and validate receipts with the Google Play store. First, provide us with your Google Play license key. Next, add the following code sample in your class that implements

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;


import com.leanplum.Leanplum;
public void onIabPurchaseFinished(IabResult result, Purchase info) {
  final Purchase purchase = info;
  billingHelper.queryInventoryAsync(new QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inv) {
      // Track in-app purchase.
      SkuDetails skuDetails = inv.getSkuDetails(purchase.getSku());
      try {
        JSONObject skuData = new JSONObject(skuDetails.toString()
            .substring(skuDetails.toString().indexOf(":") + 1));
            skuData.getString("title"), // Alternatively, skuData.getString("productId"), if you like.
            purchase.getOriginalJson(), purchase.getSignature()
            /* optionally supply event parameters as an additional argument */);
      } catch (JSONException e) {
        Log.e("Leanplum", "Cannot get purchase price from improperly formatted SKU");

      // Code to consume purchase.
      // It's important that you do not consume while querying inventory, or you'll receive
      // an IllegalStateException.
      // billingHelper.consumeAsync(purchase, null);

Leanplum will also convert all purchases to USD. To require valid receipts upon purchase or change your preferred currency, update your app settings.

Other Monetization Events

If you are not using in-app purchases, you can manually track your monetization event. It works like any other event, except you use "Purchase" as the event name. For your convenience, you can also use the constant LP_PURCHASE_EVENT which is "Purchase". For example:

Leanplum.track(Leanplum.PURCHASE_EVENT_NAME, 19.99, item);

The value should be the revenue for the transaction in a common currency.

If you prefer to use a different event name than "Purchase", you can select a new name. Simply go to the metric chooser by clicking the + tile on the Analytics page, go to the Monetization category, and edit the purchase event. The changes will be applied retroactively.