SDKs
iOS SDK
Overview
Welcome to the official Datasenses iOS SDK Library
This section shows how to track custom events with the DataSenses SDK in your iOS app. The quick start guide shows how to install the DataSenses SDK, track your first user event, and refer to this information within the DataSenses dashboard.
Prerequisites
Language: Swift 5.
Install the following: Xcode 14.1 or later
Your project must target these platform versions or later: iOS 13
Step 1: Install the SDK
Installation Option 1: CocoaPods
The recommended way to install Datasenses SDK for iOS is using Cocoapods, since it means you can create a build with specific destinations, and because it makes it simple to install and upgrade.
First, add the Datasenses_iOS SDK dependency to your Podfile, like so:
pod 'Datasenses-iOS' , :git => '[email protected]:datasenses/datasenses-ios.git', :tag => '0.3.7'
pod 'FirebaseAnalytics', '~> 11.1.0'
pod 'FBSDKCoreKit', '~> 17.1.0'
Step 2: Initialize Datasenses SDK
Get api key and configuration file
Goto https://growth.datasenses.io to get your api key.
Click Download GoogleService-Info.plist to obtain your Firebase Apple platforms config file (GoogleService-Info.plist).
Move your config file into the root of your Xcode project. If prompted, select to add the config file to all targets.
Facebook integration
Then add the following to Info.plist. If your app is not running advertising on Facebook or already integrated with facebook-ios-sdk to run ads, then no need to add the following
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fbAPP-ID</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>APP-ID</string>
<key>FacebookClientToken</key>
<string>CLIENT-TOKEN</string>
<key>FacebookDisplayName</key>
<string>APP-NAME</string>
<key>SKAdNetworkItems</key>
<array>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>v9wttpbfk9.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>n38lu8286q.skadnetwork</string>
</dict>
</array>
<key>FacebookAutoLogAppEventsEnabled</key>
<true />
<key>FacebookAdvertiserIDCollectionEnabled</key>
<true />
Config SKAdNetwork postback URL
Config value of NSAdvertisingAttributionReportEndpoint to https://datasenses.one in Info.plist file. See more
Tracking User Description
To run the advertising campaign more efficiently. We suggest you should ask user's consent to track the advertising ID for iOS
requestIDFAPermission
Make sure you added NSUserTrackingUsageDescription to Info.plist
<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>
Initialize Datasenses SDK in your app
Then in your application delegate's - application:didFinishLaunchingWithOptions: method, set up the SDK like so:
import Datasenses_iOS
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
Datasenses.initialize(apiKey: "N4qTG9jDHM_d9kTGSpo--FujKVtZFpolmv-OJiFzYLKf2DlJSX3lY9mnye6zZdbCQKNolp3Ox7MP5veTvFbAfba8pOABCw", launchOptions: launchOptions)
Datasenses.shared().isTrackFirebaseEvent = true //if you want to send event to firebase by our sdk
Datasenses.shared().isTrackFacebookEvent = true //if you want to send event to facebook by our sdk
return Datasenses.shared().application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Step 3: Handle Deeplink
To allow DataSenses to handle deeplink, you can call handleUrl(url:).
import Datasenses_iOS
func application(_ application: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
Datasenses.shared().handleUrl(application, url: url, options: options)
return true
}
- We supported few custom events. Checkout this link for more details.
Step 4: Integrate the notification system
Read here for more details
Step 5: Send Events
5.1. Send Login Event
We use login event to identify the customer. Naming convention of fields need to be followed by our format.
import Datasenses_iOS
Datasenses.shared().track(event: "login",
properties: [
"customer_id": "123456", // String - We use customer_id field as customer's id,
"email": "[email protected]", // String - We use email field as customer's email
"phone": "84999999999", // String - We use phone field as customer's phone
]
)
5.2. Send Charged Event
We use charged event to calculate the revenue, ROI, Marketing performance of your project.
Note:
- If you want to monitor revenue of your product. You need to add the items filed with item_id as product's id for us to proceed this event
import Datasenses_iOS
Datasenses.shared().track(event: "charged",
properties: [
"items": [
["category":"Phone","name":"Iphone X","price":119000000,"item_id": "2", "qty": 1],
["category":"Phone","name":"Samsung Galaxy","price":119000000,"item_id": "3", "qty": 1],
], // Array - We use items field as list of items of the conversion event, must have item_id, name, price, qty of each item
"charged_id": "123", // String - Use charged_id field as a conversion's id
"amount": 238000000 // Number - We use amount field as a conversion's value
]
)
5.3. Send Customized Events
You can add any additional events
import Datasenses_iOS
Datasenses.shared().track(event: "add_to_cart",
properties: [
"category":"Phone", // String, To analyze more efficiently, please don't change name of the field
"name":"Iphone X", // String, To analyze more efficiently, please don't change name of the field
"price":119000000, // Number, To analyze more efficiently, please don't change name of the field
"item_id":"2", // String , To analyze more efficiently, please don't change name of the field
"qty": 1 // Number, To analyze more efficiently, please don't change name of the field
]
)
Let's get started by sending event data. You can send an event from anywhere in your application. Better understand user behavior by storing details that are specific to the event (properties).
import Datasenses_iOS
Datasenses.shared().track(event: "add_to_cart",
properties: ["currency": "VND",
"items":["1234", "5678"]])
5.4 Manual flush
Datasenses SDK doesn't send the events you record immediately. Instead, it sends batches to the Datasenses servers every 60 seconds while your application is running, as well as when the application transitions to the background. You can call flush()
manually if you want to force a flush at a particular moment.
Datasenses.shared().flush()