An input is the original source of the data you want to track. This could be a website, mobile app, or even a data feed from another platform. The mParticle SDK you use depends on your input.
In this tutorial, we’ll use the iOS SDK. However, before we can fully integrate the SDK into our app we need to create the input in our mParticle account.
The iOS SDK is initialized in an MParticleOptions
object. When initializing the SDK, you must include both your API key and secret generated when setting up an iOS input in mParticle.
The Higgs Shop initializes the SDK in the file core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/AppDelegate.swift
:
func makeOptions() -> MParticleOptions? {
guard let key = getConfigInfo("MPARTICLE_KEY"),
let secret = getConfigInfo("MPARTICLE_SECRET") else {
AppDelegate.shouldShowCredsAlert = true
log("Error: No mParticle key and secret were found")
return nil
}
if key == "REPLACEME" || secret == "REPLACEME" {
AppDelegate.shouldShowCredsAlert = true
if let value = getOverrideConfig("IS_UITEST") {
if value == "YES" {
AppDelegate.shouldShowCredsAlert = false
}
}
}
let options = MParticleOptions(key: key, secret: secret)
if let logLevel = parseLogLevel(getConfigInfo("MPARTICLE_LOGLEVEL")) {
// Log level is set to .none by default--you should use a preprocessor directive to ensure it is only set for your non-App Store build configurations (e.g. Debug, Enterprise distribution, etc)
#if DEBUG
options.logLevel = logLevel
#endif
}
options.customLogger = { (message: String) in
self.log("Custom Higgs Logs - \(message)")
}
if let autoTracking = parseBool(getConfigInfo("MPARTICLE_AUTOTRACKING")) {
if autoTracking == false {
options.automaticSessionTracking = false
options.shouldBeginSession = false
Self.eventsBeginSessions = false
}
}
if let sessionTimeout = parseDouble(getConfigInfo("MPARTICLE_SESSIONTIMEOUT")) {
options.sessionTimeout = sessionTimeout
}
if let proxyDelegate = parseBool(getConfigInfo("MPARTICLE_PROXYDELEGATE")) {
if proxyDelegate == false {
// If you are disabling App Delegate proxying, you will need to manually forward certain App Delegate methods.
// See our docs here: https://docs.mparticle.com/developers/sdk/ios/configuration/#uiapplication-delegate-proxy
options.proxyAppDelegate = false
}
}
return options
}
Notice that when the Higgs Shop sample app initializez the SDK, some options (like the log level, key, and secret) are defined in environment variables which can be changed by editing the scheme in Xcode.
The Higgs Shop sample app defines environment variables for your API key and secret in a scheme. To add your API key and secret to the sample app:
HiggsShopSampleApp.xcodeproj
in Xcode.REPLACEME
with your API key and secret for the variables named MPARTICLE_KEY
and MPARTICLE_SECRET
.The SDK includes configuration settings so you can customize your integration. There are two that you should be aware of at this stage:
Data sent from your app to mParticle is labeled as either Development
or Production
. By default, the sample app is configured to label all data as Development
. Since you are setting up a development environment to learn how the iOS SDK works, do not change this setting.
If you were to release an iOS app to the public with an mParticle integration, you can change the environment to Production
by editing the scheme:
You can set your log level to VERBOSE
or ERROR
depending on the level of detail you want printed to the console when running your app. By default, the sample app is configured with the VERBOSE
log level. Do not change this setting when following this tutorial.
Learn more about iOS SDK log level settings in Getting Started.
Was this page helpful?