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.

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

Make sure you start Batch before or after tracking your events. Otherwise, they will not be sent!