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 Kount iOS SDK into your Swift iOS (version 11 or later) application. This allows you to use Kount's service without having to create API calls. Software for this integration can be found in GitHub.
Note: This integration document is for iOS versions 13 or later. If the application is using segues, then the analytics data only captures for that view controller if the modal is presented using
UIModalPresentation.fullScreen
. For iOS versions 12 or earlier, the default presentation style is already full screen, meaning that analytics data already captures for those screens.Invoking the Kount iOS SDK into a Swift App
- If you are using Universal Static Library, add
.h
files fromKountDataCollectorUniversalLibrary
inside the iOS project:- Go to the Project Navigator view.
- Right-click your app’s project name, and then select Add files to “{Project}”.
- From the Finder window, select
KountDataCollectorUniversalLibrary
. - Under
KountDataCollectorUniversalLibrary
, selectkDataCollector.h
andKountAnalyticsViewController.h
, and then click Add. - Xcode asks to create a bridging header. Click the option to create the header.
- To manually add the bridging header:
- For the Bridging header name, use
<Target-name>-Bridging-Header.h
.
- For the Bridging header name, use
- Add following import statements in the bridging header file:
#import "KDataCollector.h" #import "KountAnalyticsViewController.h"
- 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.
-
For iOS 13 and later
UnderScenedelegate.swift
, insceneDidEnterBackground method
, add:
KountAnalyticsViewController().registerBackgroundTask()
For versions iOS 12 and earlier
UnderAppDelegate.swift
, inApplicationDidEnterBackground
method, add:
KountAnalyticsViewController().registerBackgroundTask()
- In
Appdelegate.swift
, write the following code example:
The// Global Variable var sessionID : String = "" // In method didFinishLaunchingWithOptions, replace their old Kount configuration related code with following code: KDataCollector.shared().debug = true // Set your Merchant ID KDataCollector.shared().merchantID = 99999 // Insert your valid merchant ID // Set the location collection configuration KDataCollector.shared().locationCollectorConfig = KLocationCollectorConfig.requestPermission // For a released app, you'll want to set this to KEnvironment.Production KDataCollector.shared().environment = KEnvironment.test KountAnalyticsViewController().setEnvironmentForAnalytics(KDataCollector.shared().environment) // To collect Analytics Data, set Boolean flag - analyticsData to true. let analyticsData = true KountAnalyticsViewController().collect(sessionID, analyticsSwitch: analyticsData) { (sessionID, success, error) in //Completion block to know whether device data collection is successful/failed with error/failed without error. if (success) { print("Collection Successful") } else { if ((error) != nil) { print("Collection failed with error: ",error!.localizedDescription) } else { print("Collection failed without error") } } }
KountAnalyticsViewController
keeps the Session ID in a global variable to be retrieved at any time, named asKountAnalyticsViewController.getAppSessionID
.
Optional:
If you want to see the status of the DDC, add the following to your code:
getKDataCollectionStatus() getKDataCollectionError()
- In the view controllers where you want to detect events, inherit the view controller from
KountAnalyticsViewController
and removeUITextFieldDelegate
(if any).
Note: If your view controller does not inherit directly fromUIViewController
, you must perform this step on the controller that does inherit fromUIViewController
, and ensure that the controller callssuper.init()
. - In the view controller where you want to capture analytics data, under
ViewDidLoad()
, add:<textfield_Name>.delegate = self.
It must be added for all textfields on that page. - In the login view controller, inside the login action method, add:
Inside code for Successful login, add:KountAnalyticsViewController().storeLog(inEvents: true)
Inside code for Unsuccessful login, add:KountAnalyicsViewController().storeLog(inEvents: false)
- If a ViewController in application is overriding the method that we are already using for capturing analytics data, then call super
<MethodName>
in theViewController method
. This step involves some client-side coding if there are multiple methods, but these will only be one line of code for such methods. - Almost all Kount API calls require your Kount assigned merchantID and a sessionID (
KountAnalyticsViewController.getAppSessionID
). You must send thegetAppSessionID
you created earlier back to your servers. This can be done at any time prior to the Kount API calls being made (from your servers to ours). For example, if you are using Kount Control and plan to evaluate logins, you could include the sessionID along with the users login credentials to your servers. This sessionID is accessible as a global variable. Refer to the Kount Support website for further documentation. - Build and Run.