Event Collection in Android SDK

In order to collect android mobile events and use that data to create behavioral segments in D·engage you have to determine the type of events and data that needs to collected. Once you have determined that, you will need to create a “Big Data” table in D·engage. Collected events will be stored in this table. Multiple tables can be defined depending on your specific need.

Any type of event can be collected. The content and the structure of the events are completely flexible and can be changed according to unique business requirements. You will just need to define a table for events.

Once defined, all you have to do is to send the event data to these tables. D·engage SDK has only two functions for sending events: sendDeviceEvent and sendCustomEvent. Most of the time you will just need the sendDeviceEvent function.

1. Login / Logout Action

If the user logs in or you have user information, this means you have contact_key for that user. You can set contact_key in order to match user with the device. There are two functions for getting and setting contact_key.

setContactKey

If user logged in set user id. This is important for identifying your users.

DengageManager.getInstance(getApplicationContext()).setContactKey("use userId (contact_key) here");
//syncsubscription() method is deprecated after 3.2.1 version.
DengageManager.getInstance(getApplicationContext()).syncSubscription();

getSubscription

If you need to get current user information from SDK use this function.

DengageManager.getInstance(getApplicationContext()).getSubscription();

2. Event Collection

If your D·engage account is an ecommerce account, you should use standart ecommerce events in the SDK. If you need some custom events or your account is not standart ecommerce account, you should use custom event functions.

a) Events for Ecommerce Accounts

There are standart ecommerce events in D·engage SDK.

  • Page View Events
    • Home page view
    • Product page view
    • Category page view
    • Promotion page view
  • Shopping Cart Events
    • Add to cart
    • Remove from cart
    • View Cart
    • Begin Checkout
  • Order Events
    • Order
    • Cancel order
  • Wishlist Events
    • Add to wishlist
    • Remove from wishlist
  • Search Event

For there event there is related tables in your account.

Page View Events

Page view events will be sent to page_view_events table. If you add new columns to this table. You can send these in the event data.

// Home page view
HashMap<String, Object> data = new HashMap<>();  
data.put("page_type", "home");  
// ... extra columns in page_view_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).pageView(data);

// category page view
HashMap<String, Object> data = new HashMap<>();  
data.put("page_type", "category");  
data.put("category_id", 123); 
// ... extra columns in page_view_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).pageView(data);

// product page view
HashMap<String, Object> data = new HashMap<>();  
data.put("page_type", "product");  
data.put("product_id", 123); 
// ... extra columns in page_view_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).pageView(data);

// promotion page view
HashMap<String, Object> data = new HashMap<>();  
data.put("page_type", "promotion");  
data.put("promotion_id", 123); 
// ... extra columns in page_view_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).pageView(data);

// custom page view
HashMap<String, Object> data = new HashMap<>();  
data.put("page_type", "custom");  
// ... extra columns in page_view_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).pageView(data);

// For other pages you can send anything as page_type

Shopping Cart Events

These events will be stored in shopping_cart_events and shopping_cart_events_detail. There are 4 shopping cart event functions. addToCart, removeFromCart, viewCart, beginCheckout

Every shopping cart event function needs all items in cart as an array. You must send last version of the shopping cart.

For example: If there is one item in cart and item id is 5. And after that, an add to cart action is happened with the item id 10. You have to send 10 as product_id in event parameters and you must send current version of cart items. Meaning [5, 10]

// All items currently exists in shopping cart

ArrayList<HashMap<String,Object>> cartItems = new ArrayList<>();  

HashMap<String, Object> item1 = new HashMap<>();  
item1.put("product_id", "1234");  
item1.put("product_variant_id", "12224"); 
item1.put("quantity", 1); 
item1.put("unit_price", 9.99); 
item1.put("discounted_price", 9.99); 
// ... extra columns in shopping_cart_events_detail table, can be added here
cartItems.add(item1);

HashMap<String, Object> item2 = new HashMap<>();  
item2.put("product_id", "12345");  
item2.put("product_variant_id", "12225"); 
item2.put("quantity", 1); 
item2.put("unit_price", 9.99); 
item2.put("discounted_price", 9.99); 
// ... extra columns in shopping_cart_events_detail table, can be added here
cartItems.add(item2);

// Add To Cart
HashMap<String,Object> data = new HashMap<>();  
data.put("product_id", "123");  
data.put("product_variant_id", "1222");  
data.put("quantity", 1);  
data.put("unit_price", 9.99);  
data.put("shipping", 5);  ,
data.put("discounted_price", 9.99);
data.put("coupon_code", "");
data.put("cartItems", cartItems.toArray());
// ... extra columns in shopping_cart_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).addToCart(data); 
 
// Remove From Cart
HashMap<String,Object> data = new HashMap<>();  
data.put("product_id", "123");  
data.put("product_variant_id", "1222");  
data.put("quantity", 1);  
data.put("unit_price", 9.99);  
data.put("shipping", 5);  ,
data.put("discounted_price", 9.99);
data.put("coupon_code", "");
data.put("cartItems", cartItems.toArray());
// ... extra columns in shopping_cart_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).removeFromCart(data); 
 
// View Cart
HashMap<String,Object> data = new HashMap<>();  
data.put("cartItems", cartItems.toArray());
// ... extra columns in shopping_cart_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).viewCart(data); 
  
// Begin Checkout
HashMap<String,Object> data = new HashMap<>();  
data.put("cartItems", cartItems.toArray());
// ... extra columns in shopping_cart_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).beginCheckout(data); 

Order Events

Orders events will be sent to order_events and order_events_detail tables.

// Ordered items or canceled items

ArrayList<HashMap<String,Object>> cartItems = new ArrayList<>();  

HashMap<String, Object> item1 = new HashMap<>();  
item1.put("product_id", "1234");  
item1.put("product_variant_id", "12224"); 
item1.put("quantity", 1); 
item1.put("unit_price", 19.99); 
item1.put("discounted_price", 9.99); 
// ... extra columns in order_events_detail table, can be added here
cartItems.add(item1);

HashMap<String, Object> item2 = new HashMap<>();  
item2.put("product_id", "12345");  
item2.put("product_variant_id", "12225"); 
item2.put("quantity", 1); 
item2.put("unit_price", 19.99); 
item2.put("discounted_price", 9.99); 
// ... extra columns in order_events_detail table, can be added here
cartItems.add(item2);

// Paid Order
HashMap<String,Object> data = new HashMap<>();  
data.put("order_id", "123");  
data.put("item_count", 1);  
data.put("total_amount", 99.9);  
data.put("payment_method", "card");  
data.put("shipping", 5);  ,
data.put("discounted_price", 29.99);   // use total price if there is no discount
data.put("coupon_code", "");  // use if necessary
data.put("cartItems", cartItems.toArray());  // ordered items
// ... extra columns in order_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).order(data); 

// Order Cancel
HashMap<String,Object> data = new HashMap<>(); 
data.put("item_count", 1);  
data.put("total_amount", 99.9); 
data.put("discounted_price", 29.99);  // use total price if there is no discount 
data.put("cartItems", cartItems.toArray());  // canceled items
// ... extra columns in order_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).cancelOrder(data);

Search Event

Search events will be stored in search_events table.

HashMap<String, Object> data = new HashMap<>();  
data.put("keywords", "hello"); 
data.put("result_count", 123); 
data.put("filters", "q=keywords"); //you use can send extra filters selected by user here. Formating is not specified
// ... extra columns in search_events table, can be added here 
DengageEvent.getInstance(getApplicationContext()).search(data);

Wish List Events

These events will be stored in wishlist_events and wishlist_events_detail. There are 2 wishlist event functions. addToWishlist, removeFromWishlist. In every event call, you can send all items in wishlist. It makes it easy to track current items in wishlist.

ArrayList<HashMap<String,Object>> wishlistItems = new ArrayList<>();  

HashMap<String, Object> item = new HashMap<>();  
item.put("product_id", 1);  
 // ... extra columns in wishlist_events_detail table, can be added here
wishlistItems.add(item);

// Add To Wish List
HashMap<String,Object> data = new HashMap<>();  
data.put("product_id", 123); ,
data.put("items", wishlistItems.toArray()); 
// ... extra columns in wishlist_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).addToWishList(data);  

// Remove From Wish List
HashMap<String,Object> data = new HashMap<>();  
data.put("product_id", 123); ,
data.put("items", wishlistItems.toArray()); 
// ... extra columns in wishlist_events table, can be added here
DengageEvent.getInstance(getApplicationContext()).removeFromWishList(data);

b) Custom Events

Send Device Specific Events

You can use sendDeviceEvent function for sending events for the device. Events are sent to a big data table defined in your dEngage account. That table must have relation to the master_device table. If you set contact_key for that device. Collected events will be associated for that user.

DengageEvent.sendDeviceEvent(tableName, data);

// for example if you have a table named "events"
// and events table has "key", "event_date", "event_name", "product_id" columns
// you just have to send the columns except "key" and "event_date", because those columns sent by the SDK

HashMap<String,Object> data = new HashMap<>();  
data.put("event_name", "page_view");  
data.put("product_id", "12345"); 
// ... extra columns in events table, can be added here
DengageEvent.getInstance(getApplicationContext()).sendDeviceEvent("events", data);  

Changing Event Api Endpoint

<meta-data
    android:name="den_push_api_url"
    android:value="https://your_push_api_endpoint" />