Event tracking APIs

The methods below provide an easy way to track certain pre-defined events like Identify, Checkout, Add to Cart, Check-in, Buy, etc.

In addition the SDK supports tracking of certain events - App Open and Notification tracking natively. You can learn more about these events here.

Your application can also send custom JSON to Blueshift

 

 

1. Custom Events

The trackEvent() method helps the developer to track custom events created by them with custom attributes.

HashMap<String, Object> params = new HashMap<>();
params.put("name", "Ross Geller");
params.put("profession", "paleontologist");
//..add more values if required..//

Blueshift.getInstance(mContext).trackEvent("your_custom_event_name", params, true);
 

 

2. Identify

The identify event is used for identifying the end-user logged into the app. The primary identifier used to identify a user is device id(recommended to be the Android Ad id). The device id is set during the SDK initialization and is automatically sent to Blueshift. In addition to sending the device id, we recommend that you set the email and customer id where ever available. This would ensure that we a user resets the device id, we can still attribute events and generate recommendations.

The following example will help you call identify event.

// Identify event with device id as the primary identifier
Blueshift
        .getInstance(mContext)
        .identifyUserByDeviceId(deviceId, null, false);

Note: Use Android Advertising ID as device id.

 

 

3. Screen View

You may call the trackScreenView() method to send page_load event. The method has two implementations, one to take the instance of activity and the other one to take a custom screen name set by the developer.

// with instance of activity
Blueshift
        .getInstance(mContext)
        .trackScreenView(this, true);

// with custom screen name
Blueshift
        .getInstance(mContext)
        .trackScreenView("product page", true);
 

 

4. Product View

The trackProductView() method can be used to track views of a particular product. It also takes the common attributes like sku and category id. Developer is also allowed to pass additional parameters as HashMap.

String sku = product.getSku();
int categoryId = product.getCategoryId();

Blueshift
        .getInstance(mContext)
        .trackProductView(sku, categoryId, true);

If any additional parameters are to be sent along.

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackProductView(sku, categoryId, optionalAttr, true);
 

 

5. Add to Cart

The trackAddToCart() method can be used for tracking add to cart event. This can be called when the add to cart button is clicked. Or when the add to cart API call is complete.

Assume that the product object in the following code is an instance of host app's product model.

String sku = product.getSku();
int quantity = product.getQuantity();

Blueshift
        .getInstance(mContext)
        .trackAddToCart(sku, quantity, true);

If any additional parameters are to be sent along.

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackAddToCart(sku, quantity, optionalAttr, true);
 

 

6. Checkout Cart

The trackCheckoutCart() method tracks the cart checkout event. The first argument to the method is array of products. This product model is included in the SDK. You may create instances and set the values in it using your product instance.

Assume the cart object contains all the required values.

float revenue = cart.getRevenue();
float discount = cart.getDiscount();
String coupon = cart.AppliedCounpon();
// implements `buildProductArray()` to return required product array.
Product[] products = buildProductArray();

Blueshift
        .getInstance(mContext)
        .trackCheckoutCart(products, revenue, discount, coupon, true);

If any additional parameters are to be sent along.

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackCheckoutCart(
                products,
                revenue,
                discount,
                coupon,
                optionalAttr,
                true);
 

 

7. Products purchase

The trackProductsPurchase() allows the developer to track a completed product purchase.

Assume that the `order' object contains all the required values.

String orderId = order.getOrderId();
Product[] products = order.getProducts();
float revenue = order.getRevenue();
float shippingCost = order.getShippingCost();
float discount = order.getDiscount();
String coupon = order.getAppliedCoupon();

Blueshift
        .getInstance(mContext)
        .trackProductsPurchase(
                orderId,
                products,
                revenue,
                shippingCost,
                discount,
                coupon, 
                true);

If any additional parameters are to be sent along.

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackProductsPurchase(
                orderId,
                products,
                revenue,
                shippingCost,
                discount,
                coupon, 
                optionalAttr,
                true);
 

 

8. Purchase cancel

The trackPurchaseCancel() tracks the cancellation event for an completed order.

Assume the object order contains the required fields.

String orderId = order.getOrderId();

Blueshift
        .getInstance(mContext)
        .trackPurchaseCancel(orderId, true);

If any additional parameters are to be sent along.

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackPurchaseCancel(orderId, optionalAttr, true);
 

 

9. Purchase return

The trackPurchaseReturn() method tracks the purchase return. You may call this api once the purchase return Api call is complete.

Assume order is an order which is returned.

String orderId = order.getOrderId();
// implement `getReturnedProducts` to return required products array.
Product[] products = order.getReturnedProducts();

Blueshift
        .getInstance(mContext)
        .trackPurchaseReturn(orderId, products, true);

If any additional parameters are to be sent along.

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackPurchaseReturn(orderId, products, optionalAttr, true);

 

10. Product search

The trackProductSearch() helps tracking the search events inside host app. Call this method when a search is performed.

The method has 3 implementation, with optional filters and extra arguments.

Blueshift
        .getInstance(mContext)
        .trackProductSearch(
                skus,              // array of sku of products in result (String[])
                numberOfResults,   // number of results obtained (int)
                pageNumber,        // page number of the result (int)
                query,             // search query used (String)
                true);

With optional filters.

Blueshift
        .getInstance(mContext)
        .trackProductSearch(
                skus,              // array of sku of products in result (String[])
                numberOfResults,   // number of results obtained (int)
                pageNumber,        // page number of the result (int)
                query,             // search query used (String)
                filters,           // filters applied in this search (HashMap<String,Object>)
                true);

With optionalAttr values

Blueshift
        .getInstance(mContext)
        .trackProductSearch(
                skus,              // array of sku of products in result (String[])
                numberOfResults,   // number of results obtained (int)
                pageNumber,        // page number of the result (int)
                query,             // search query used (String)
                filters,           // filters applied in this search (HashMap<String,Object>)
                optionalAttr,      // optional additional parameters (HashMap<String,Object>)
                true);
 

 

11. Email List

i. Subscribe for email list

The trackEmailListSubscription() method can be used for tracking email subscription event.

Blueshift
        .getInstance(mContext)
        .trackEmailListSubscription(email, true);

With optional additional parameters

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackEmailListSubscription(email, optionalAttr, true);
 

 

ii. Unsubscribe from email list

The trackEmailListUnsubscription() method can be used for tracking email unsubscription event.

Blueshift
        .getInstance(mContext)
        .trackEmailListUnsubscription(email, true);

With optional additional parameters

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackEmailListUnsubscription(email, optionalAttr, true);
 

 

12. Subscriptions

The APIs under this section is used to track the events on a subscription.

  

i. Initialize

Initializes the subscription. If the subscription state is SubscriptionState.START or SubscriptionState.UPGRADEevent "subscription_upgrade" is fired, else if the state is SubscriptionState.DOWNGRADE, then event "subscription_downgrade" is fired.

Blueshift
        .getInstance(mContext)
        .trackSubscriptionInitialization(
                subscriptionState,   // subscription state
                cycleType,           // type of subscription period (Ex: weekly, yearly etc)
                cycleLength,         // length of subscription period
                subscriptionType,    // type of subscription (generally the title)
                price,               // cost of subscription for selected period
                startDate,           // subscription activation date (in millis)
                true);

With optional additional parameters

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackSubscriptionInitialization(
                subscriptionState,   // subscription state
                cycleType,           // type of subscription period (Ex: weekly, yearly etc)
                cycleLength,         // length of subscription period
                subscriptionType,    // type of subscription (generally the title)
                price,               // cost of subscription for selected period
                startDate,           // subscription activation date (in millis)
                optionalAttr,
                true);
 

 

ii. Pause

The trackSubscriptionPause() method will downgrade your currently active subscription.

Blueshift
        .getInstance(mContext)
        .trackSubscriptionPause(true)

With optional additional parameters

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackSubscriptionPause(optionalAttr, true)
 

 

iii. Resume/UnPause

The trackSubscriptionUnpause() method will downgrade your currently paused subscription.

Blueshift
        .getInstance(mContext)
        .trackSubscriptionUnpause(true)

With optional additional parameters

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackSubscriptionUnpause(optionalAttr, true)
 

 

iv. Cancel

The trackSubscriptionCancel() can be used for tracking the cancellation of currently running subscription.

Blueshift
        .getInstance(mContext)
        .trackSubscriptionCancel(true)

With optional additional parameters

HashMap optionalAttr = new HashMap<>();
// .. fill in optional attributes .. //

Blueshift
        .getInstance(mContext)
        .trackSubscriptionCancel(optionalAttr, true)
Was this article helpful?
0 out of 0 found this helpful