This method takes in 2 parameters the event name and the JSON object having event parameters.
track(final String action, final JSONObject data);
When your event parameters involve items:
We first define a parent JSON object. We then define JSONArray to hold individual items.
Next, add individual Items JSON to this array and finally add the complete Items JSON Array to the parent JSON object with key `items`.
The RSClient expects the above format whenever you are transmitting a List/array of items. The parent JSON Key should be `items` and its value should be JSONArray. You can then track this event by calling the "track" method and giving the appropriate action name like `shopping_cart`.
- Tracking registration events
- Tracking view events
- Tracking view item events
- Tracking click events
- Tracking category view events
- Tracking add to cart events
- Tracking checkout success events
- Tracking deep-linked email click events
Tracking registration events
Define the registration parameters, give the event name as `registration_complete` and call the "track" method.
JSONObject parameters = new JSONObject();
parameters.put("registration_source", "google ads");
track("registration_complete", parameters);
Tracking view events
Define the view event parameters, give the event name as `view` and call the "track" method.
JSONObject parameters = new JSONObject();
parameters.put("page_title", "All Products");
track("view", parameters);
Tracking view item events
Define the view item event parameters, give the event name as `view` and call the "track" method.
JSONObject parameters = new JSONObject();
parameters.put("page_title", "Item XYZ Page");
// 1.) Define a Json Array to put the item viewed parameters.
JSONArray itemsArray = new JSONArray();
// 2.) Define a nested JSON to hold individual item name, price, id
JSONObject item1 = new JSONObject();
try {
item1.put("id", "123");
item1.put("name", "item1 name");
item1.put("price", "50.00");
itemsArray.put(item1);
// 2.) Put items array in the parent json with key="items"
parameters.put("items", itemsArray);
} catch(JSONException e) {
Log.v(TAG, e.getMessage());
}
track("view", parameters);
Tracking click events
Define the click event parameters, give the event name as `click` and call the "track" method.
JSONObject parameters = new JSONObject();
parameters.put("clicked_href", "/items/name-of-item");
track("click", parameters);
Tracking category view events
Define the category view event parameters, give the event name as `category_view` and call the "track" method.
JSONObject parameters = new JSONObject();
parameters.put("page_title", "Category Page Name");
// 1.) Define a Json Array to put the category viewed parameters.
JSONArray categoryArray = new JSONArray();
// 2.) Define a nested JSON to hold individual category name, id
JSONObject category1 = new JSONObject();
try {
category1.put("id", "123");
category1.put("name", "category name");
categoryArray.put(category1);
// 2.) Put category array in the parent json with key="items"
// Keep the parent key as items only
parameters.put("items", categoryArray);
} catch(JSONException e) {
Log.v(TAG, e.getMessage());
}
track("category_view", parameters);
Tracking add to cart events
Define the shopping cart event parameters, give the event name as `shopping_cart` and call the "track" method.
// Button to send event and test shopping cart action. An app can mimic the same logic if they want
// to track shopping cart action.
final Button button2 = (Button) findViewById(R.id.sendEventWithJsonButton);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v(TAG, "Sample App Shopping cart items Send Event");
// Steps
// 1.) Define a Json object to put custom event parameters. For eg to hold items.
JSONObject itemsParent = new JSONObject();
JSONArray itemsArray = new JSONArray();
// 2.) Define a nested JSON to hold individual item name, price, id
JSONObject item1 = new JSONObject();
JSONObject item2 = new JSONObject();
try {
item1.put("id", "123");
item1.put("name", "item1 name");
item1.put("price", "50.00");
item2.put("id", "124");
item2.put("name", "item2 name");
item2.put("price", "100.00");
itemsArray.put(item1);
itemsArray.put(item2);
// 2.) Put items array in the parent json with key="items"
itemsParent.put("items", itemsArray);
} catch(JSONException e) {
Log.v(TAG, e.getMessage());
}
// 3.) Track the click event by calling the RSClient track method.
// RSClient supports different flavours of track method. Since here we have the
// event parameters as Json object so call the track method which expects action name
// and JSON as arguments
RSClient.track("shopping_cart", itemsParent);
// The above call will transmit the event to Retention Science endpoint.
// If setStagingEnvironment is called then the event will be transmitted
// to the Retention Science staging endpoint. By default if these methods are not called
// every event is transmitted to production endpoint.
}
});
Tracking checkout success events
Define the checkout success event parameters, give the event name as `checkout_success` and call the "track" method.
JSONObject checkoutJson = new JSONObject();
// 1.) add custom parameters
checkoutJson.put("order_id", "12345678910");
checkoutJson.put("order_total", "150.0");
// 2.) Define a JSON array to hold individual item name, price, id
JSONArray itemsArray = new JSONArray();
JSONObject item1 = new JSONObject();
JSONObject item2 = new JSONObject();
try {
item1.put("id", "123");
item1.put("name", "item1 name");
item1.put("price", "50.00");
item2.put("id", "124");
item2.put("name", "item2 name");
item2.put("price", "100.00");
itemsArray.put(item1);
itemsArray.put(item2);
checkoutJson.put("items", itemsArray);
} catch(JSONException e) {
Log.v(TAG, e.getMessage());
}
// 3.) track 'checkout_success' event
RSClient.track("checkout_success", checkoutJson);
Tracking deep-linked email_click events
If you are using deep-links and a user has clicked through from an email, you can track the email_click action by extracting the rs_oid GET parameter from the deep-link URL. This "track" method should be called as follows:
// Extract the GET param rs_oid from the deep-linked URL
// eg. http://example.com/deep-link?rs_oid=12345678910
JSONObject emailClickJson = new JSONObject();
emailClickJson.put("offer_id", 12345678910L);
RSClient.track("email_click", emailClickJson);
Comments
0 comments
Please sign in to leave a comment.