iOS Native
Initialization
To create ease for partners, we have divided the SDK into multiple modules. Each module represents a
specific app niche that partners can use based on their app category.For this step, we will only focus on the core
sdk
To use the SDK, Core is mandatory to include as it contains the elements regarding the basic app navigation and workflow including nudges. Moreover, all the modules require the core to be integrated to successfully log the events.
The easiest way to integrate Causal Foundry iOS SDK in your iOS project is with CocoaPods OR SPM (Swift Package Manager).
To use via CocoaPods, use the pod name as: CausalFoundrySDKCore
To use via SPM, head to the public repo on: GitHub
For ios initialization, you need to have a mac and Xcode installed and min deployment target as ios 13.0.
Once the Pods are successfully installed or the SPM is integrated, head to your info.plist file and add the following keys for
the Permitted background task scheduler identifiers
ai.causalfoundry.ingestAppEvents
ai.causalfoundry.fetchNudges
OR
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>ai.causalfoundry.ingestAppEvents</string>
<string>ai.causalfoundry.fetchNudges</string>
</array>
After adding the values in info.plist, head to the app Target project > Signing & Capabilities
> Background Modes
and select the following 2:
- Background fetch
- Background processing
Once the background tasks are selected, Head to your AppDelegate class and add the following as:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
CausalFoundry.shared.configure()
CFLogBuilder()
.updateImmediately(updateImmediately: false)
.allowAnonymousUsers()
// .setAutoShowInAppNudge(showInAppNudge: false)
.setSdkKey(sdkKey:"<SDK_KEY_HERE>")
.disableAutoPageTrack()
.build()
NudgeOnClickObject.nudgeOnClickInterface = { cta, itemType, itemID in
// Define your logic here
let nudgeItems = "\(cta)||\(itemType)||\(itemID)"
print(nudgeItems) // Just for example, you can use this data as needed
}
return true
}
Now try build your project, CF SDK should be initialized and ready to use.
Note that since we are using BGTaskScheduler for ios SDK, the events will not be sent exactly after the app the closed but will be sent at a later time on the availability of the resources by the OS.
Causal Foundry SDK automatically starts tracking user data (e.g., Upload/download speed, OS
version, device IDs) and engagement with the basic setup above. This data can be stored on the
device and uploaded in batches to reduce network and power usage, and to increase the likelihood of
successful uploads while you can also upload the events as soon as they happen. The upload is done
when the user device session ends. SDK also starts tracking user sessions with this basic setup.
Each event can further be understood in the context of its attributes which includes details like time, upload/download speed, device details, locale, online/offline usage, screen time, interactions, and so on. This enables you to gain in-depth insights into user interactions across your app. You can also leverage this data to segment users, personalize messages and configure campaign targeting.