Cordova > Custom data

Events

Batch allows you to track events that happen in your application. They automatically keep track of their count, the last time it happened and their value.

Important
- Please read our guide on custom data before tagging your app.
- Newly tracked events are hidden by default. You will need to manually display them from the dashboard settings > "Custom data" tab.

Tracking events

Events are easy to use, but have some rules:

  • Event names are strings. They should be made of letters, numbers or underscores ([a-z0-9_]) and can't be longer than 30 characters.
  • They can have a label, which is a string with no limitations (optional).
  • A custom data object can be attached. It must be an object. Though it will be collected by Batch, it cannot be used for targeting purposes at the moment (optional).

Here's an example:

batch.user.trackEvent("ad_seen");
batch.user.trackEvent("tab_clicked", "activity");

batch.user.trackEvent("ad_seen", null, {
  "utm_campaign": "thanksgiving_promo"
});

Tracking transactions

We also have a specialized kind of events: Transactions.

They let you track a transaction of a certain amount, but also allow you to specify the currency.

They also have some rules:

  • Amount should be a number.
  • A custom data object is supported, just like standard events (optional).

Here's an example:

batch.user.trackTransaction(20.5);

batch.user.trackTransaction(20.5, {
  "item": "100gold"
});

Tracking user location

Starting with Batch 2.0.0, you can now natively track a user location.

You will have to wrap the location in a plain object defining:

  • latitude (number)
  • longitude (number)
  • date (Date, optional)
  • precision (number, optional) precision radius in meters

Here it's typescript definition of the object:

/**
 * Represents a locations, using lat/lng coordinates
 */
interface Location {
  /**
   * Latitude
   */
  latitude: number;

  /**
   * Longitude
   */
  longitude: number;

  /**
   * Date of the tracked location
   */
  date?: Date;

  /**
   * Precision radius in meters
   */
  precision?: number;
}

And some examples:

batch.user.trackLocation({ latitude: 2.5, longitude: 4 });

batch.user.trackLocation({
  date: new Date(1520352788000),
  latitude: 2,
  longitude: 4.5
});

batch.user.trackLocation({
  date: new Date(1520352788000),
  latitude: 2,
  longitude: 4.5,
  precision: 10
});

This data will allow you to send geotargeted push notifications from the dashboard or the Campaigns API.

The SDK will throttle location tracking to optimize network and battery usage. You can track one location event every 30 seconds, any attempt at updating the location sooner will be ignored by the SDK.