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 Newly tracked events are hidden by default. You will need to manually display them from the dashboard settings.
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.
A custom data object can be attached. See the section "Event Attributes", right under this one.
Custom attributes have some reserved keys. See the section "Reserved event attributes" under "Event Attributes" for more info.
Here's an example:
Please test your implementation using our debug tool and profile view before releasing your app on the store.
Event attributes
Custom attributes can be attached to events using BatchEventAttributes
. You will then use them when calling Batch.Profile.trackEvent()
.
Attribute names are strings. They should be made of letters, numbers or underscores ([a-z0-9_]) and can't be longer than 30 characters (e.g. has_premium). They will be automatically lowercased, so trying to use the same key with different casing will overwrite the previously set value.
Values must be any of the following types:
String must not be longer than 200 characters and can't be empty. For better results, you should make them upper/lowercase and trim the whitespaces.
Float/Double.
Integer/Long.
Boolean
Date (using
java.util.Date
)URL (using
java.net.URI
) not longer than 2048 characters and must follow the formatscheme://[authority][path][?query][#fragment]
List<String | BatchEventAttributes>, You can set array of strings (max 200chars) and array of objects. Max 25 items. You cannot mix several attribute types in one array. Arrays can't be nested.
Object (using
BatchEventAttributes
, Objects cannot have more than 3 levels of nesting.
Reserved event attributes
Some event attributes have reserved keys, and are all prefixed by a $
sign. This is the list of currently reserved event attributes. You cannot set an event attribute starting by a $ sign.
$label
String - Optional
Event label. Must be a string, will automatically be bridged as label for application event compatibility. Max 200 chars.
$tags
NSArray - Optional
Event tags. Must be an array of string, will automatically be bridged as tags for application event compatibility. Max 10 items of type string, each no longer than 64chars. The SDK will automatically lowercase them, so two same strings with different casing do not count as two different tags
In Batch SDK v1 you were able to set a label and tags at the root of an event, with the limit of 1 label and 10 tags.
Batch SDK v2 introduced Object and Array types in event attributes. You can set more than one array on profiles events. This is only supported for profiles, and not on the install-centric data model, which currently powers push notification and In-App messages.
However, it's still possible to set a label and tags on events in the install-centric data model by using $label
and $tags
, and activate compatibility flows. This way, you will be able to use this data for your push and in-app communications.
Example
Tracking user location
You can natively track a user location. This uses Android's standard Location object, which you usually get from the Location Service or Fused Location API. You can also instanciate one manually from a latitude/longitude.
Here's an example:
This data will allow you to send geo-targeted push notifications from the dashboard or the Campaigns API.
Background events
Sending events from the background is supported on Android using a Service
.
To do so, call Batch.onServiceCreate()
and Batch.onServiceDestroy()
in your service's lifecycle methods. Standard Batch event tracking methods will automatically work.
Last updated
Was this helpful?