Implementing the Device Data Collector (DDC) is a two-step process. If you have not completed the first step of integration, refer to the following articles below:
- How to Integrate the Kount Device Data Collector XCFramework Package into an iOS Application
- How to Integrate the Kount Device Data Collector CocoaPods Package into an iOS Application
- How to Integrate the Device Data Collector into Mobile SDKs using iOS Universal Static Library
- How to Integrate the Device Data Collector Swift Package Manager into an iOS Application
Provide native support for your Kount solution by integrating the Kount iOS SDK into your Objective-C iOS application. This allows you to use Kount's service without having to create separate API calls. Software for this integration can be found in GitHub.
Invoking the Kount iOS SDK into Objective-C
- Add the folder for touch event related files (for reference) under Project target.
- Go to the Project Navigator view.
- Right-click the app’s project name and select Add files to “{Project}”or move the
TouchControls
folder to the root of the project in Xcode. - From the Finder window, select
KountDataCollectorUniversalLibrary
. - Under
KountDataCollectorUniversalLibrary
, select theTouchControls
folder, which contains touch event related files, and then click Add. - Select Copy items if needed, Create groups, and then select one or more target destinations for the analytics.
- Select Add.
- Add the View Controller to your project.
For iOS 13 and above:
UnderSceneDelegate.h
, add:#import “KountAnalyticsViewController.h” #import “KDataCollector.h”
UnderSceneDelegate.m
, in thesceneDidEnterBackground
method, add:KountAnalyticsViewController *backgroundTaskObject = [[KountAnalyticsViewController alloc] init]; [backgroundTaskObject registerBackgroundTask];]
For iOS 12 and below:
UnderAppDelegate.h
, add:#import "KountAnalyticsViewController.h" #import "KDataCollector.h”
UnderAppDelegate.m
, in theApplicationDidEnterBackground
method, add:KountAnalyticsViewController *backgroundTaskObject = [[KountAnalyticsViewController alloc] init]; [backgroundTaskObject registerBackgroundTask];
Note: For each view in which you want to send Analytics data, in the.h
file you must add:#import “KountAnalyticsViewController.h”
- In
m
, write the following code snippet:NSString *sessionID = nil;
[[KDataCollector sharedCollector] setDebug:YES];
// Set your Merchant ID
[[KDataCollector sharedCollector] setMerchantID:99999];
// Set the location collection configuration
[[KDataCollector sharedCollector] setLocationCollectorConfig:KLocationCollectorConfigRequestPermission];
// For a released app, you'll want to set this to KEnvironmentProduction
[[KDataCollector sharedCollector] setEnvironment:KEnvironmentTest];
[[KountAnalyticsViewController sharedInstance] setEnvironmentForAnalytics: [KDataCollector.sharedCollector environment]];
//To collect Analytics Data, set Boolean flag - analyticsData to YES.
BOOL analyticsData = YES;
[[KountAnalyticsViewController sharedInstance] collect:sessionID analyticsSwitch:analyticsData completion:^(NSString * _Nonnull sessionID, _Bool success, NSError * _Nullable error) {
//Completion block to know whether device data collection is successful/failed with error/failed without error.
if (success) {
NSLog(@"Collection Successful");
}
else {
if(error != nil) {
NSLog(@"Collection failed with error:%@",error.description);
}
else {
NSLog(@"Collection failed without error");
}
}
}];
Optional:
If you want to know the status of the DDC, add the following to your code:[KountAnalyticsViewController getKDataCollectionStatus] [KountAnalyticsViewController getKDataCollectionError]
- In the view controller
.h
file add:
#import KountAnalyticsViewController.h
Replace theUIViewController
inheritance withKountAnalyticsViewController
, and then remove instances ofUITextFieldDelegate
.
Note: If your view controller does not inherit directly fromUIViewController
, perform this step on the controller that does inherit fromUIViewController
, and make sure the controller callssuper.init()
. - In the view controllers where you want to capture analytics data, under the
ViewDidLoad method
, add:<textfield_Name>.delegate = self
Note: The code above must be added for all textfields on that page.In the login view controller’s.m
file, inside the code for Successful login, add:
[[KountAnalyticsViewController sharedInstance] storeLogInEvents:YES];
Inside the code for Unsuccessful login add:[[KountAnalyticsViewController sharedInstance] storeLogInEvents:NO];
Note: If a view controller in the application overrides the method that is being used for capturing analytics data, then call[super <MethodName>]
in theViewController
method. - Kount API calls require your Kount assigned merchantID and a sessionID (
getAppSessionID
). Send theKountAnalyticsViewController.getAppSessionID
back to your servers before sending the Kount API calls. For example, if you are using Kount Control to evaluate logins, include theKountAnalyticsViewController.getAppSessionID
along with the user’s login credentials to your servers. - Build and Run.
Note: In iOS 13 and above, if your application is using segues and has a modal displayed using
UIModalPresentationFullScreen
, then analytics data is captured for that view controller. For iOS 12 and below, no changes are required because the default presentation style is full screen.