Multi Profile Consent
iOS
Multi Profile Support
Support for multi profiles has been added to OT SDK based on the profileID/DSID. As part of this feature, all the user choices (w.r.t purposes, categories, vendors and SDK list) and profile specific data (coming down as part of data download) will be stored per profile basis. As a result, whenever a profileID/DSID is set by an application, that particular profile storage will be loaded.
In order to use Multi Profile consent, you must first enable it in your templates section. Cookie Consent > Templates > Select a Template > Enable the mobile app template (under details) > Navigate to the mobile app platform > Banner > Multi Profile Consent.
Number of Profiles Supported
The SDK only supports up to 6 profiles today.
Default Profile
There will always be a default profile configured by the OneTrust SDK. Whenever DSID/ProfileID is not set by the application, we will load this default profile. At any point, there will be only one such default profile maintained by OT SDK.
Retrieve Current Profile ID
This method allows you to retrieve the identifier of the current profile.
Swift
OTPublishersHeadlessSDK.shared.currentActiveProfile
- Returns a string
Renaming or Overriding Profiles/Data Subject Identifier
By default, the OneTrust SDK logs a user's consent anonymously under a random GUID. The ID and consent is stored locally on the device as well as in the OneTrust database (if the consent logging toggle is enabled in your geolocation rules).
The following method can be used to rename a profile from one DSID/Profile ID to another.
OTPublishersHeadlessSDK.shared.renameProfile(from: "currentProfileID", to: "newProfileID", withIdentifierType: "identifier type", completion: { renameSuccess in
print(renameSuccess)
})
from
: The current identifier of the profile. If no profile identifier is passed (e.g.nil
), the current profile identifier will be updated to new identifier.to
: The new identifier of the profile.withIdentifierType
: Optional, only used when Unified Profile is in scope- The completion block will be triggered once the rename operation is complete and returns a boolean
- Ensure that the new DSID is unique and does not already exist.
- Ensure that startSDK() has been called at least once.
This method will only rename the profile ID stored locally on the device. The ID stored in the OneTrust Consent database will not update until the user interacts with the CMP again. If you want to have the ID stored in the consent database to be updated right away (without interaction from the user), the recommendation is to to call saveConsent() after renameProfile. This will commit the user's consent choices again and create a new receipt.
OTPublishersHeadlessSDK.shared.saveConsent(type: .preferenceCenterConfirm)
Please note: If multi profile is not in use and you'd like to just rename the ID, you must then also pass the identifier into OTProfileSyncParams
and startSDK
. Example code snippet below:
OTPublishersHeadlessSDK.shared.renameProfile(to: "[email protected]") { Bool in
print("Rename complete")
}
let sdkParams = OTSdkParams(countryCode: nil, regionCode: nil)
let profileSyncParams = OTProfileSyncParams()
profileSyncParams.setIdentifier(OTPublishersHeadlessSDK.shared.currentActiveProfile)
sdkParams.setProfileSyncParams(profileSyncParams)
OTPublishersHeadlessSDK.shared.startSDK(storageLocation: cdnLocation, domainIdentifier: appID,
languageCode: lang,
params: sdkParams) { [weak self] response in
guard let self = self, let _ = response.error else { return }
print("Current DSID = \(OTPublishersHeadlessSDK.shared.currentActiveProfile)")
}
Switching Profiles
Profile switching will happen in the following scenarios:
- Whenever
startSDK()
is called, we will be checking for the profileID/DataSubjectID that will be passed as part of sdkParams object. If this identifier is empty, we will be switching to/loading the default profile maintained by OT SDK. - Whenever
switchProfile()
is called, we will be checking to see if the data is available for switching a profile. If it is available, we will switch to the passed in profile. - If an empty identifier is passed, we will be loading the default profile maintained by OT SDK.
- For data availability, we check if culture data, common data and domain data are available locally for all profiles.
- If cross device sync enabled scenarios, along with the above data, we will also check if profile data is available locally.
- For above two conditions to be met, ensure that
startSDK()
is called at least once for an application ID before calling the switchProfile API.
Note: Switching profiles when cross device sync is enabled is not supported yet.
Swift
OTPublishersHeadlessSDK.shared.switchProfile(to: "profileIDToBeSwitchedTo", completion: {profileSwitchError in print(profileSwitchError ?? "Profile Switch Successful.") } )
- Parameter to: The identifier of the profile to be loaded.
- Parameter completion: The completion block that will be triggered at the end of the profile switch operation.
Deleting Profile
Use the method deleteProfile()
to delete a profile. If the profile being deleted is currently active, we switch the active profile to default profile and then delete it.
Note: Ensure that
startSDK()
is called at least once for an application ID before calling the deleteProfile API.
Swift
OTPublishersHeadlessSDK.shared.deleteProfile("profileIDToBeDeleted", completion: { deletionError in print(deletionError ?? "Profile Deletion Successful.") } )
- Parameter profileID: The identifier of the profile to be deleted.
- Parameter completion: The completion block that will be triggered after deleting a profile.
Whenever the OTPublisherHeadlessSDK.shared.clearOTSDKData()
method is called, all the stored profiles and their storages will be deleted along with the SDK storage.
Updated 5 months ago