Overview
This guide provides step-by-step instructions to initialize the AppTrove iOS SDK in your iOS application. Proper initialization ensures accurate tracking, attribution, and reporting.
Prerequisites
- Access to the Trackier Panel
- iOS 10.0 or later and Xcode 12.0 or later
- Basic knowledge of Swift and iOS development
Initialization
Step 1: Retrieve SDK Key
- Log in to your Trackier Panel.
- Select your app, click Action, and choose SDK Integration.
- Copy the displayed SDK Key.
Using the correct SDK key is critical. An incorrect key may cause attribution and reporting issues.
Step 2: Initialize the SDK
Initialize the SDK in AppDelegate.swift
within the application(_:didFinishLaunchingWithOptions:)
method to ensure it loads in all scenarios, including deep linking. Use the TrackierSDKConfig
class to configure the SDK with your SDK key and environment.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Override point for customization after application launch.
/*
While Initializing the SDK, you need to pass two arguments in the TrackierSDKConfig:
1. The AppTrove SDK API key
2. The environment, which can be either "development", "production", or "testing"
*/
let config = TrackierSDKConfig(
appToken: "xxxx-xx-xxx-xxx", // Pass your AppTrove SDK API key
env: TrackierSDKConfig.ENV_DEVELOPMENT
)
TrackierSDK.initialize(config: config)
return true
}
}
Parameters
- appToken: Your SDK key from the Trackier Panel.
- env: Environment setting. Use:
TrackierSDKConfig.ENV_DEVELOPMENT
for testing.TrackierSDKConfig.ENV_PRODUCTION
for release builds.TrackierSDKConfig.ENV_TESTING
for staging environments.
Ensure the SDK key matches your application in the Trackier Panel to avoid attribution and reporting issues.
Step 3: Associate User Info (Optional)
You can associate user information (e.g., user ID, email) during SDK initialization to enhance tracking and attribution.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let config = TrackierSDKConfig(appToken: "xxxx-xx-xxx-xxx innerhalb, env: TrackierSDKConfig.ENV_DEVELOPMENT)
TrackierSDK.setUserId("XXXXXXXX")
TrackierSDK.setUserEmail("abc@gmail.com")
// Add custom user details
var userAdditionalDetails = [String: AnyObject]()
userAdditionalDetails["userMobile"] = "99XXXXXXXX" as AnyObject
TrackierSDK.setUserAdditionalDetails(userAdditionalDetails)
TrackierSDK.initialize(config: config)
return true
}
Available Methods
setUserId(_:)
: Unique user identifier.setUserEmail(_:)
: User's email address.setUserName(userName:)
: User's display name.setUserPhone(userPhone:)
: User's phone number.setUserAdditionalDetails(_:)
: Custom key-value pairs for extra metadata.
Best Practices
- Initialize Early: Place initialization in
application(_:didFinishLaunchingWithOptions:)
to capture all app launches. - Use Correct Environment: Set
ENV_TESTING
orENV_DEVELOPMENT
during testing to avoid polluting production data. Switch toENV_PRODUCTION
for release builds. - Verify SDK Key: Ensure the SDK key matches the one in the Trackier Panel to prevent tracking issues.
- Leverage User Info: Associate user details (e.g., user ID, email) to improve attribution accuracy.
Troubleshooting
- Incorrect SDK Key: Verify the SDK key matches the one in the Trackier Panel.
- Initialization Issues: Ensure initialization occurs in
application(_:didFinishLaunchingWithOptions:)
. - Environment Mismatch: Confirm the environment (
ENV_TESTING
,ENV_DEVELOPMENT
, orENV_PRODUCTION
) aligns with your deployment stage.
For further assistance, refer to the Trackier Documentation Portal or contact Trackier support at support@trackier.com.