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:
-
How to Integrate the Device Data Collector XCFramework Package into an iOS Application
-
How to Integrate the 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 solution by integrating the iOS SDK into your Objective-C iOS application. This allows you to use our service without having to create separate API calls. Software for this integration can be found in GitHub.
-
Go to the Project Navigator view.
-
Right-click the app project name, and then 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. -
Select Copy items if needed, Create groups, and then select one or more target destinations for the analytics.
-
Select Add.
-
Add the folder for touch event related files (for reference) under Project target.
-
Add the View Controller to your project. You can add header files or import the SDK directly into the Objective-C file.
-
Add a header file
For iOS 13 and above:
Under
SceneDelegate.h
, add:#import “KountAnalyticsViewController.h” #import “KDataCollector.h”
Under
SceneDelegate.m
, in thesceneDidEnterBackground
method, add:KountAnalyticsViewController *backgroundTaskObject = [[KountAnalyticsViewController alloc] init]; [backgroundTaskObject registerBackgroundTask];]
For iOS 12 and below:
Under
AppDelegate.h
, add:#import "KountAnalyticsViewController.h" #import "KDataCollector.h”
Under
AppDelegate.m
, in theApplicationDidEnterBackground
method, add:KountAnalyticsViewController *backgroundTaskObject = [[KountAnalyticsViewController alloc] init]; [backgroundTaskObject registerBackgroundTask];
Note
For each view in which you want to send Analytics data, you must add:
#import “KountAnalyticsViewController.h”
in the.h
file. -
Import the SDK file for Universal Library, XCFramework, and Swift
Import the iOS SDK directly into the Objective-C file.
@import KountDataCollector;
Note
For each view in which you want to send Analytics data, you must add:
@import KountDataCollector;
in the.h
file. -
Import the SDK file for CocoaPods
Import the iOS SDK directly into the Objective-C file.
#import "KountUmbrella.h"
Note
For each view in which you want to send Analytics data, you must add:
#import "KountUmbrella.h";
in the.h
file.
-
-
In
m
, write the following code snippet:NSString *sessionID = nil; [[KDataCollector sharedCollector] setDebug:YES]; // Set your Merchant ID [[KDataCollector sharedCollector] setMerchantID:@"900900"]; // 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 Device Data Collector, add the following to your code:
[KountAnalyticsViewController getKDataCollectionStatus]; [KountAnalyticsViewController getKDataCollectionError];
-
Add the following code In the view controller
.h
file:-
For Universal Library, XCFramework, and Swift Package Manager:
@import KountDataCollector;
-
For CocoaPods:
#import "KountUmbrella.h"
Replace the
UIViewController
inheritance withKountAnalyticsViewController
, and then remove instances ofUITextFieldDelegate
.Note
If your view controller does not inherit directly from
UIViewController
, perform this step on the controller that does inherit fromUIViewController
, and make sure the controller callssuper.init()
. -
-
The following code must be added for all textfields on the page. In the view controllers where you want to capture analytics data, under the
ViewDidLoad method
, add:<textfield_Name>.delegate = self
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. -
API calls require your assigned merchantID and a sessionID (
getAppSessionID
). Send theKountAnalyticsViewController.getAppSessionID
back to your servers before sending the API calls. For example, if you are using our services 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.