In order to collect app events and use that data to create behavioral segments in dEngage 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 dEngage. 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. dEngage SDK has only two functions for sending events: sendDeviceEvent and sendCustomEvent. Most of the time you will just need the sendDeviceEvent function. For ecommerce accounts there is predefined event tables. And you can feed these tables by usern ecommerce event functions.
If the user loggs 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 browser. There are two functions for getting and setting contact_key.
If user logged in set user id. This is important for identifying your users. You can put this function call in every page. It will not send unnecessary events.
Dengage.setContactKey(contactKey: "userId")
If you need to get current user information from SDK use this function.
var userId = Dengage.getContactKey()
There are standart ecommerce events in dEngage SDK.
For there event there is related tables in your account.
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 DengageEvent.shared.pageView(params: [ "page_type":"home" // ... extra columns in page_view_events table, can be added here ]) // Category page view DengageEvent.shared.pageView(params: [ "page_type":"category", "category_id":"1" // ... extra columns in page_view_events table, can be added here ]) // Product page view DengageEvent.shared.pageView(params: [ "page_type":"product", "product_id":"1" // ... extra columns in page_view_events table, can be added here ]) //promotion page view DengageEvent.shared.pageView(params: [ "page_type":"promotion", "promotion_id":"1" // ... extra columns in page_view_events table, can be added here ]) //custom page view DengageEvent.shared.pageView(params: [ "page_type":"custom" // ... extra columns in page_view_events table, can be added here ]) // For other pages you can send anything as page_type
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 must be added to an array var cartItem = [:] as NSMutableDictionary cartItem["product_id"] = 1 cartItem["product_variant_id"] = 1 cartItem["quantity"] = 1 cartItem["unit_price"] = 10.00 cartItem["discounted_price"] = 9.99 // ... extra columns in shopping_cart_events_detail table, can be added in cartItem let cartItems = [] as [NSMutableDictionary] cartItems.append(cartItem) cartItems.append(cartItem2) // ... shopping cart items must be added // Add to cart action var params = [ "product_id":1, "product_variant_id":1, "quantity":1, "unit_price":10.00, "discounted_price":9.99, // ... extra columns in shopping_cart_events table, can be added here "cartItems":cartItems // all items in cart ] DengageEvent.shared.addToCart(params : params) // Remove from cart action var params = [ "product_id":1, "product_variant_id":1, "quantity":1, "unit_price":10.00, "discounted_price":9.99, // ... extra columns in shopping_cart_events table, can be added here "cartItems":cartItems // all items in cart ] DengageEvent.shared.removeFromCart(params : params) // view cart action var params = [ // ... extra columns in shopping_cart_events table, can be added here "cartItems":cartItems ] DengageEvent.shared.viewCart(params : params) // begin checkout action var params = [ // ... extra columns in shopping_cart_events table, can be added here "cartItems":cartItems ] DengageEvent.shared.beginCheckout(params : params)
Orders events will be sent to order_events and order_events_detail tables.
// Ordered items or canceled items must be added to an array var cartItem = [:] as NSMutableDictionary cartItem["product_id"] = 1 cartItem["product_variant_id"] = 1 cartItem["quantity"] = 1 cartItem["unit_price"] = 10.00 cartItem["discounted_price"] = 9.99 // ... extra columns in order_events_detail table, can be added in cartItem let cartItems = [] as [NSMutableDictionary] cartItems.append(cartItem) cartItems.append(cartItem2) // ... ordered or canceled items must be added // Place order action var params = [ "order_id":1, "item_count":1, // total ordered item count "total_amount":1, // total price "discounted_price":9.99, // use total price if there is no discount "payment_method":"card", "shipping":5, "coupon_code":"", // ... extra columns in order_events table, can be added here "cartItems":cartItems //ordered items ] DengageEvent.shared.order(params : params) // Cancel order action var params = [ "order_id":1, // canceled order id "item_count":1, // canceled total item count "total_amount":1, // canceled item's total price "discounted_price":9.99, // use total price if there is no discount // ... extra columns in order_events table, can be added here "cartItems":cartItems // // canceled items ] DengageEvent.shared.cancelOrder(params : params)
Search events will be stored in search_events table.
var params = [ "keywords":"some product name", // text in the searchbox "result_count":12, "filters":"" //you can send extra filters selected by user here. Formating is not specified // ... extra columns in search_events table, can be added here ] DengageEvent.shared.search(params : params)
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.
// Current items in wishlist var wishListItem = [:] as NSMutableDictionary wishListItem["product_id"] = 1 let wishListItems = [] as [NSMutableDictionary] wishListItems.append(wishListItem) // Add to wishlist action var params = [ "product_id":1, // ... extra columns in wishlist_events table, can be added here "items":wishlistItems // current items ] DengageEvent.shared.addToWishList(params : params) // Remove from wishlist action var params = [ "product_id":1, // ... extra columns in wishlist_events table, can be added here "items":wishlistItems // current items ] DengageEvent.shared.removeFromWishList(params : params)
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.
dengage(‘sendDeviceEvent’, tableName, dataObject [, callback]);
// 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
let params = [
"event_name": "page_view",
"product_id": "1234",
]
Dengage.SendDeviceEvent(toEventTable: 'events', andWithEventDetails: params)
If you want to send events to a table that is not related to master_device, you can use sendCustomEvent function. This function is similar to sendDeviceEvent, but extra you have to send a key for the event. The key can be anything. For example contact_key can be used as key.
dengage(‘sendCustomEvent’, tableName, key, dataObject [, callback]);
var contact_key = "user_123456"; var eventDetails:NSDictionary = [ "param2":"...", "param2":"...", ... ] Dengage.SendCustomEvent(toEventTable: EVENT_TABLE_NAME, withKey:contact_key, andWithEventDetails: eventDetails)