SDK Initialization
Initializing the SDK
Create and configure the Magify instance inside your Application class.
import com.magify.sdk.Magify
// Application class
lateinit var magify: Magify
override fun onCreate() {
val config = MagifyConfig(
applicationName = "android-application", // short app name as listed in the dashboard
defaultConfig = "Magify-Config.json", // only limits and products are expected in the config
isSandbox = false // set to true only for sandbox environment
)
magify = Magify.createInstance(androidApp, config)
}
After creating the instance and setting any optional flags, complete initialization:
magify.initSdk(
complete = {
}
)
magify.initialSetup()
Initializing SDK with other libraries
The SDK supports multiple initialization scenarios when used together with third-party attribution SDKs.
AppsFlyer clientId is passed to Magify
lateinit var magify: Magify
// your code for AppsFlyerLib initializing
...
val clientId = AppsFlyerLib.getInstance().getAppsFlyerUID(this)
val config = MagifyConfig(
applicationName = "android-application",
defaultConfig = "Magify-Config.json",
isSandbox = false,
userId = clientId
)
magify = Magify.createInstance(androidApp, config)
// optional magify sdk flags
...
magify.initSdk(
complete = {
}
)
magify.initialSetup()
If Magify is initialized first
lateinit var magify: Magify
val config = MagifyConfig(
applicationName = "android-application",
defaultConfig = "Magify-Config.json",
isSandbox = false,
userId = "clientId" // set your custom clientId or set null
)
magify = Magify.createInstance(androidApp, config)
// optional magify sdk flags
...
magify.initSdk(
complete = {
}
)
magify.initialSetup()
// your code for AppsFlyerLib initializing
...
val clientId = magify.clientId
AppsFlyerLib.getInstance().setCustomerUserId(clientId)
SDKs are initialized only after authorization
lateinit var magify: Magify
// clientId received after authorization
private var clientId: String = "your_custom_user_id"
// your code for AppsFlyerLib initializing
...
AppsFlyerLib.getInstance().setCustomerUserId(clientId)
val config = MagifyConfig(
applicationName = "android-application",
defaultConfig = "Magify-Config.json",
isSandbox = false,
userId = clientId
)
magify = Magify.createInstance(androidApp, config)
// optional magify sdk flags
...
magify.initSdk(
complete = {
}
)
magify.initialSetup()
For integration with Adjust, AppLovin MAX, LevelPlay/IronSource, and RevenueCat, see Integration with other SDK.
Next step
Continue with Configuration options to set optional runtime flags, manage client identity, and synchronize subscription status.