GuidesAPI ReferenceRelease Notes
HomeLog InHome
Guides

Initialize Android SDK

Best practice: Initialize the Experiences SDK as early as possible when your app loads (for example, in your Application class onCreate). Early initialization improves performance and keeps analytics stable.

This guide outlines how to kickstart your application with the Experiences SDK using an API key. The setup includes initializing the SDK in the App class with optional delegates for global and player entry point configurations.

To initialize the SDK with an API key, add the following code to your Application class.

import com.blaze.blazesdk.BlazeSDK

    override fun onCreate() {
        super.onCreate()
        ...
        BlazeSDK.init(
           apiKey = { API_KEY },
          // Any other optional arguments
          ...
        )
        ...
    }

Optional additional params are here with their default values if not passed to init.

        externalUserId: String? = null,
        cachingSize: Int? = null,
        cachingLevel: BlazeCachingLevel = BlazeCachingLevel.DEFAULT,
        geoLocation: String? = null,
        forceLayoutDirection: BlazeLayoutDirection? = null,
				globalDelegate: BlazeSDKDelegate? = null,
        playerEntryPointDelegate: BlazePlayerEntryPointDelegate? = null,
        completionBlock: () -> Unit = { },
				errorBlock: (failure: BlazeResult.Error) -> Unit = { }

Initialization errors:

   INVALID_API_KEY,
   NETWORK_FAILURE,
   INVALID_APP_CONFIG,
   SDK_ALREADY_INITIALIZED,
   SDK_INITIALIZATION_ERROR
- invalidAPIKeyError: when an invalid API key is used
- networkError can be for example when : 
- A call to load the settings for the SDK fails (i.e. a non-success HTTP status code is returned)
- A malformed settings response is received from the server
- Invalid App Config: returned when SDK failed to init specific app configuration 
- SDK Already initialized : Called init sdk multiple times which is not allowed.
📘

Overview

The externalUserId parameter is used to uniquely identify a user session when initializing our SDK. This identifier serves as a key for customizing and tracking user-related activities during the SDK session.

Overriding Behavior
If you re-initialize the SDK with a new externalUserId, the SDK will override the previous user identifier. The new externalUserId will be used for all subsequent activities and tracking. The previous viewer's unsynced activity is sent to WSC Sports, and their activity is cleared from the device. The previous identifier stays valid: set it again and that viewer's activity is restored.

Clearing Previous User Identifier
If you initialize the SDK with externalUserId set to null, it will clear the previous user identifier, effectively anonymizing the session. Activities in this state will not be associated with any user identifier until a new externalUserId is set.

Recommended Practice
Due to our overriding and clearing behavior, it is crucial to use careful logic in your application to manage when and how to initialize new sessions. Make sure that you are intentionally setting or clearing externalUserId based on the desired outcome for user tracking and activity management.


Did this page help you?