iOS > 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.

Managing 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 NSString with no limitations (optional).
  • A custom data object can be attached. It must be a Foundation Dictionary, serializable by NSJSONSerialization. NSArrays as top level objects are not supported. Though it will be collected by Batch, it cannot be used for targeting purposes at the moment (optional).

Here's an example:

[BatchUser trackEvent:@"ad_seen"];
[BatchUser trackEvent:@"tab_clicked" withLabel:@"activity"];
[BatchUser trackEvent:@"ad_seen" withLabel:nil data:@{@"utm_campaign": @"thanksgiving_promo"}];
BatchUser.trackEvent("ad_seen")
BatchUser.trackEvent("tab_clicked", withLabel: "activity")
BatchUser.trackEvent("ad_seen", withLabel: nil, data: ["utm_campaign": "thanksgiving_promo"])

Managing transactions

We also have a specialized kind of events: Transactions.

They let you track a transaction of a certain amount, without any currency attached: you'll need to make sure you only track comparable values.

They also have some rules:

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

Here's an example:

[BatchUser trackTransactionWithAmount:@(20.5)];
[BatchUser trackTransactionWithAmount:@(70.5) data:@{@"item": @"100gold"}];
BatchUser.trackTransaction(withAmount: 20.5)
BatchUser.trackTransaction(withAmount: 20.5, data: ["item": "100gold"])

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

Important
Please test your implementation using our debug tool before releasing your app on the store.