Event Tracking
Introduction
Events are all the actions performed by the user on the mobile application. Smartech SDK enables you to record user events and later learn more about your app’s usage patterns and to segment your users, target, and personalize messaging based on the events performed by them.
Track App Update And Install Event
If you want Smartech to handle App Update and Install events then you can add method trackAppInstallUpdateBySmartech in didFinishLaunchingWithOptions in AppDelegate class.
[[Smartech sharedInstance] trackAppInstallUpdateBySmartech];
//Implementation of method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[Smartech sharedInstance] initSDKWithDelegate:self];
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
[[Smartech sharedInstance] trackAppInstallUpdateBySmartech];
return YES;
}
Smartech.sharedInstance().trackAppInstallUpdateBySmartech()
//Implementation of method
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Smartech.sharedInstance().initSDK(with: self)
UNUserNotificationCenter.current().delegate = self
Smartech.sharedInstance().trackAppInstallUpdateBySmartech()
return true
}
After implementing the above method whenever the user will launch the app after launching the app with Smartech SDK for the first time, the event for that user will be sent to Smartech panel as the app installed.
If you have a logic implemented in your code to track App Install and Update then you can use two methods trackAppInstall and trackAppUpdate.
//To send App Install event
[[Smartech sharedInstance] trackAppInstall];
//To send App Update event
[[Smartech sharedInstance] trackAppUpdate];
//To send App Install event
Smartech.sharedInstance().trackAppInstall()
//To send App Update event
Smartech.sharedInstance().trackAppUpdate()
Predefined Events on Smartech Panel
Following is the list of Predefined events that are created on the panel which you can use if you want to:
- Page Browse
- Add To Cart
- Checkout
- Expiry Cart
- Remove From Cart
- Page Exit
- Product Search
- Product View
- Lead Submitted
- Product Purchase
- Add to Wishlist
- Remove from Wishlist
Tracking Custom Events
This method is used to track custom events which are defined by the client, to which you can analyze users usage pattern of the product. Each event must have a name and a set of attributes describing more about the event in detail. You can send only event name also if you don't have any attributes by nil/null in andPayload parameter.
// Example
NSMutableDictionary *payloadDictionary = [NSMutableDictionary new];
[payloadDictionary setObject:@"1329" forKey:@"product_id"];
[payloadDictionary setObject:@"T-shirt" forKey:@"product_name"];
[payloadDictionary setObject:@"Polo" forKey:@"brand"];
[[Smartech sharedInstance] trackEvent:@"Product Viewed" andPayload:payloadDictionary];
// Example
let payloadDictionary = [
"product_id" : "1329",
"product_name" : "T-shirt",
"brand" : "Polo"]
Smartech.sharedInstance().trackEvent("Product Viewed", andPayload:payloadDictionary)
Note:
- Smartech will automatically discover new activity by activity name along with payload parameters and data types.
- Smartech supports the following data types - String, Integer, Float, Date, Array, Dictionary.
- The bool data type in the payload is not supported by Smartech.
- Please provide the value of the date in YYYY-MM-dd HH:mm:ss format.
- All the payload keys must be in lower cases.
Complex event attributes
You can send complex event attributes with the combination of NSArray and NSDictionary data types. This complex event attributes will be auto-discovered on the Smartech panel and can be used to send campaigns.
NSMutableDictionary *payloadDictWithArray = [NSMutableDictionary new];
[payloadDictWithArray setObject:@"36899.74" forKey:@"amount"];
[payloadDictWithArray setObject:@"UATX123454" forKey:@"txid"];
[payloadDictWithArray setObject:@"INR" forKey:@"currency"];
[payloadDictWithArray setObject:@"2017-01-09T00:00:00.000Z" forKey:@"delivery_date"];
NSMutableDictionary *item1Dictionary = [NSMutableDictionary new];
[item1Dictionary setObject:@"ACNF2425FDRWQRHW" forKey:@"sku_code"];
[item1Dictionary setObject:@"13456" forKey:@"prid"];
[item1Dictionary setObject:@"Voltas" forKey:@"brand"];
[item1Dictionary setObject:@"1.5 Ton 3 Star BEE Rating 2018 Inverter AC" forKey:@"prname"];
[item1Dictionary setObject:@"35999.75" forKey:@"price"];
[item1Dictionary setObject:@"1" forKey:@"prqt"];
NSMutableDictionary *item2Dictionary = [NSMutableDictionary new];
[item2Dictionary setObject:@"TSHFFZTHF96HSW2X" forKey:@"sku_code"];
[item2Dictionary setObject:@"Men V-neck Multicolor T-Shirt" forKey:@"prname"];
[item2Dictionary setObject:@"US POLO ASSN" forKey:@"brand"];
[item2Dictionary setObject:@"899.99" forKey:@"price"];
[item2Dictionary setObject:@"2" forKey:@"prqt"];
NSArray *itemsArray = [[NSArray alloc] initWithObjects:item1Dictionary, item2Dictionary,nil];
[payloadDictWithArray setObject:itemsArray forKey:@"items"];
[[Smartech sharedInstance] trackEvent:@"Add to cart" andPayload:payloadDictWithArray];
let item1Dictionary = ["sku_code" : "ACNF2425FDRWQRHW",
"prid" : "13456",
"brand" : "Voltas",
"prname" : "1.5 Ton 3 Star BEE Rating 2018 Inverter AC",
"price" : "35999.75",
"prqt" : "1"]
let item2Dictionary = ["sku_code" : "TSHFFZTHF96HSW2X",
"prname" : "Men V-neck Multicolor T-Shirt",
"brand" : "US POLO ASSN",
"price" : "899.99",
"prqt" : "2"]
let payloadDictWithArray = ["amount" : "36899.74",
"txid" : "UATX123454",
"currency" : "INR",
"delivery_date" : "2017-01-09T00:00:00.000Z",
"items" : [item1Dictionary, item2Dictionary]] as [String : Any]
Smartech.sharedInstance().trackEvent("Add to cart", andPayload:payloadDictWithArray)
Native to web view stitching of users
- A developer should be able to get values from SDK which can be GUID, os, token, platform, etc.
- It should pass through a Javascript Method. A developer can send additional parameters with GUID.
- A call from javascript to SDK. Where a developer wants to track events from the web to SDK.
- A Developer can auto-track events by either passing true or false values. If false then a callback will be given to the App where a developer can handle the events.
How to pass parameters to WKWebview
This method creates javascript which includes developer provided app info and Smartech SDK info to WKWebview.
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
WKUserContentController *controller = WKUserContentController.new;
controller = self.webView.configuration.userContentController;
[controller addUserScript:[[Smartech sharedInstance] getSmartechAppWebScript:dict]];
let dict = [
"key1" : "value1",
"key2" : "value2"
]
var controller = WKUserContentController()
if let userContentController = webView?.configuration.userContentController {
controller = userContentController
}
controller.addUserScript(Smartech.sharedInstance().getSmartechAppWebScript(dict))
This method gets a messageHandler string used in app webview callback.
[controller addScriptMessageHandler:self name:[[Smartech sharedInstance] getSmartechAppWebMessageHandler]];
- (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message {
[[Smartech sharedInstance] appWebDidReceiveScriptMessage:message];
}
controller.addScriptMessageHandler(self, name: Smartech.sharedInstance().getSmartechAppWebMessageHandler())
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
Smartech.sharedInstance().appWebDidReceiveScriptMessage(message)
}
This delegate method will be triggered when the auto-track is not enabled from the web app page.
//Set delegate
[Smartech sharedInstance].smtAppWebViewDelegate = self;
- (void)handleAppWebViewEvent:(nonnull WKScriptMessage *)message {
NSLog(@"Handle webView event = %@", message.body);
}
Updated over 3 years ago