Configuration

After installing the SDK, you can configure the Magify instance to match your application requirements.

The SDK provides several configuration options, including:

  • SDK initialization;
  • optional runtime flags;
  • client identity management;
  • third-party SDK synchronization.

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)
}

Optional SDK flags

Optional SDK flags should be configured before calling initialSetup().

magify.turnOffGeoIP = true
magify.isLoggingEnabled = true

Client identity

To use a specific clientId, provide it during SDK initialization.

Otherwise, the system generates and stores one automatically.

val config = MagifyConfig(
    ...
    userId = "custom_client_id",
    ...
)

Changing clientId

You cannot overwrite the current live or sandbox clientId.

To initialize the SDK with a new clientId, perform the following steps:

  1. Call magify.resetState().
  2. Restart the application so that the Application class is recreated.
  3. Initialize the SDK with the new clientId.
  4. Restore optional runtime fields.

Reset the SDK state:

magify.resetState()

Initialize the SDK with a new clientId:

val config = MagifyConfig(
    applicationName = "android-application",
    defaultConfig = "Magify-Config.json",
    isSandbox = false,
    userId = "new_client_id"
)

magify = Magify.createInstance(androidApp, config)

Restore optional fields:

magify.subscriptionStatus = SubscriptionState.ACTIVE_PAID
magify.inAppStatus = InAppStatus.PURCHASED
magify.mediaSource = MediaSource(
    network = "appsflyer",
    campaign = "ua_01",
    adGroup = "us"
)

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()

Next step

Now that the SDK is configured, you can proceed to the SDK Lifecycle section to learn how the SDK behaves during application runtime.

Related articles

MagifyManager․Storage

InfoProduct

IPopupBase

SDK Lifecycle

Customization

Purchases