Android tagging
Track your user's activity in your Android app
Xtremepush has two methods for tagging activity in your app, and with them it is possible to tag interactions and page impressions.
Tagging interactions
To tag interactions call the hitTag(String tag)
method of the PushConnector
class where that interaction occurs. For example, to tag a button press:
mPushConnector.hitTag("Checkout_Button_Pressed");
The hitTag
method requires the PushConnector
object you created when initialising XtremePush so if your app has a single base activity, you can create a public wrapper method to use it throughout your project , for example:
public void sendTag(String tag){
mPushConnector.hitTag(tag);
}
To tag interactions that capture a value and grab the value, the hitTag
method takes an extra argument for data hitTag(String tag, String data)
, for example to capture a form submission:
mPushConnector.hitTag("form_1_field_1", "form_data");
Page tagging for tracking page impressions
To tag page impressions call the hitImpression(String impression)
method where your page loads:
mPushConnector.hitImpression("your_impression_name");
The tag used to record a page impression should uniquely identify a page and it should be set programatically in apps with content that updates dynamically from a feed, for example:
public void sendImpression(String impression){
mPushConnector.hitImpression(impression);
}
Setting user attributes
To associate custom attributes against your user's profile you can use the following SDK method:
// You can send any available attribute
mPushConnector.hitTag("user_attribute", ATTRIBUTE);
// like a users first name
mPushConnector.hitTag("first_name", "Joe");
// or their loyalty points balance
mPushConnector.hitTag("xp_points", "500");
Attributes can be used in both for segmentation and for personalisation.
Batching of tags
The default behaviour for tags is that they are sent immediately. if you want to control how chatty your app is you can enable batching.
To turn on batching you can call the following methods when initialising XtremePush in your Main Activity:
Tags batching
For batching of tags call setTagsBatchingEnabled(true)
when initialising XtremePush:
mPushConnector = new PushConnector.Builder("XTREME_PUSH_APP_KEY", "GOOGLE_PROJECT_NUMBER")
.setTagsBatchingEnabled(true)
.create(this);
Impressions batching
For batching of impressions call setImpressionsBatchingEnabled(true)
when initialising XtremePush:
mPushConnector = new PushConnector.Builder("XTREME_PUSH_APP_KEY", "GOOGLE_PROJECT_NUMBER")
.setImpressionsBatchingEnabled(true)
.create(this);
Alternatively, batching for tags and impressions can be toggled during runtime as follows:
- For batching of tags call
mPushConnector.setTagsBatchingEnabled(true);
- For batching of impressions call
mPushConnector.setTagsBatchingEnabled(true);
With batching turned on, tags or impressions will be cached when you call hitTag
or hitImpression
and released when you exit your app or when you call the sendTags
or sendImpressions
methods, as shown below:
To manually release tags:
mPushConnector.sendTags();
To manually release impressions:
mPushConnector.sendImpressions();
Updated about 3 years ago