Initializing the SDK¶
Now that you have installed the SDK and know how to configure it. Let's start the integration:
-
Configure and initialize Usercentrics after app launch.
using Unity.Usercentrics;
-
Instantiate a 'UserOptions' object with your desired configuration
- Select the Usercentrics prefab at
Plugins/Usercentrics
. - Configure it in the inspector:
- Save the changes.
- Select the Usercentrics prefab at
-
Drag the Usercentrics prefab from
Plugins/Usercentrics
into your scene This gameobject must be present in an early scene of your game before any script that interacts with Usercentrics. -
Call
Initialize()
from the 'Usercentrics' instance, and provide completion blocks for both success and failure.On success, it'll be returned a UsercentricsReadyStatus1. Use this status to know if you need to collect consent or apply the already collected consent.Usercentrics.Instance.Initialize( (usercentricsReadyStatus) => { // Success: Returns UsercentricsReadyStatus object }, (errorMessage) => { // Failure: Returns non-localized error } );
-
🚀 You are now ready to collect and apply consent.
Resetting the SDK
Initializing the SDK twice will lead to a crash. If you need to reset the configuration, please use reset(). This will clean all local storage and release the initialized instance. You may initialize the SDK again after this.
This is a recommended strategy for cases like:
- Using mutiple settingsIDs on one app, to address different customers or user tiers.
- Init failures due to unavailable connection or network error and you wish to retry. Make sure you know what you are doing, as you can easily end up in a loop of resets.
- If a user logs out, you might wish to remove all local storage. Use restoreUserSession to restore a user's consent after login.
- During development for testing, to clean the local storage.
Make sure you validate the expected behaviour, before using reset in production.
-
This status will be loaded when the SDK is fully initialized. ↩