iOS > Custom data


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.

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("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!

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

User location

Starting with Batch 1.8, you can now natively track a user location. This uses CoreLocation's standard CLLocation object, which you usually get from the CoreLocation itself. You can also instanciate one manually from a latitude/longitude.

Here's an example:

// CLLocation *location = [...];
[BatchUser trackLocation:location];
// let location: CLLocation = [...]

Note: 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.