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 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 Swift iOS (version 11 or later) application. This allows you to use our 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.
There are two options for importing: create a bridging-header or import the SDK directly into the Swift file.
Create a bridging header
-
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 select Add. -
Xcode asks to create a bridging header. Select the option to create the header.
-
-
To manually add the bridging header, use
<Target-name>-Bridging-Header.h
. -
Add following import statements in the bridging header file:
#import "KDataCollector.h" #import "KountAnalyticsViewController.h"
Import the SDK
Import the SDK into the appropriate Swift file, such as AppDelegate
or SceneDelegate
.
import KountDataCollector
-
Add the folder for touch event related files (for reference) under Project target.
-
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.
-
-
For iOS 13 and later Under
Scenedelegate.swift
, insceneDidEnterBackground method
, add:KountAnalyticsViewController().registerBackgroundTask()
For versions iOS 12 and earlierUnder
AppDelegate.swift
, inApplicationDidEnterBackground
method, add:KountAnalyticsViewController().registerBackgroundTask()
-
In
Appdelegate.swift
, write the following code example:// 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 = "900900" // 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") } } }
The
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 from
UIViewController
, 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:
Inside the code for Successful login, add:
KountAnalyticsViewController().storeLog(inEvents: true)
Inside the code for Unsuccessful login, add:
KountAnalyicsViewController().storeLog(inEvents: false)
-
If a ViewController in the application is overriding the method you 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 API calls require your assigned merchantID and a sessionID (
KountAnalyticsViewController.getAppSessionID
). Send thegetAppSessionID
you created back to your servers. This can be done at any time prior to the API calls being made. For example, if you are using our services and plan to evaluate logins, you could include the sessionID along with the user's login credentials to your servers. This sessionID is accessible as a global variable. -
Build and run.