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.
- Newly tracked events are hidden by default. You will need to manually display them from the dashboard settings > "Custom data" tab.
Events are easy to use, but have some rules:
Here's are some examples:
[BatchUser trackEvent:@"ad_seen"]; [BatchUser trackEvent:@"tab_clicked" withLabel:@"activity"];
BatchUser.trackEvent("ad_seen") BatchUser.trackEvent("tab_clicked", withLabel: "activity")
Please test your implementation using our debug tool before releasing your app on the store.
Starting with Batch SDK 1.13.0, you can attach custom data to events using
BatchEventData. You will then use this event when calling
It is very similar to
It supports setting the following data:
An event supports at most 10 tags and 10 attributes.
Any attempt to add an invalid tag or attribute will fail. Setting a value for an existing key will overwrite it.
BatchEventData *data = [BatchEventData new]; [data addTag:@"sports"]; [data addTag:@"squash"]; [data addTag:@"daily_digest"]; [data putBool:@(YES) forKey:@"premium"]; [data putString:@"123456" forKey:@"id"]; [BatchUser trackEvent:@"read_article" withLabel:nil associatedData:data];
let data = BatchEventData() data.add(tag: "sports") data.add(tag: "squash") data.add(tag: "daily_digest") data.put(true, forKey: "premium") data.put("123456", forKey: "id") BatchUser.trackEvent("read_article", withLabel: nil, data: data)
Note: Event data was available before Batch SDK 1.13.0, and worked with a plain NSDictionary object.
This method has been deprecated:
BatchEventDatamust now be used to describe your custom data. See the Batch 1.13 migration guide for more info.
We also have a specialized kind of events: Transactions.
They let you track a transaction of a certain amount, without any currency attached: You will need to make sure you only track comparable values.
They also have some rules:
Here's an example:
Make sure you start Batch before or after tracking your events. Otherwise, they will not be sent!
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 = [...] BatchUser.trackLocation(location)
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.