API Reference
Overview
Active Methods
Get Domain Info
This method returns a dictionary containing all the information about the domain (application) including rulesets and template configurations.
// Swift
OTPublishersHeadlessSDK.shared.getDomainInfo()
// ObjC
[OTPublishersHeadlessSDK.shared getDomainInfo];
Get Common Data
This method returns a dictionary which contains template based information like branding which includes keys for determining colors and styles in the UI specific to a template configured for the user's geolocation along with consent logging information.
// Swift
OTPublishersHeadlessSDK.shared.getCommonData()
// ObjC
[OTPublishersHeadlessSDK.shared getCommonData];
Get Groups Data
This method returns a dictionary containing the information about all the categories and sdk IDs specific to a template configured for the user's geolocation.
// Swift
OTPublishersHeadlessSDK.shared.getDomainGroupData()
// ObjC
[OTPublishersHeadlessSDK.shared getDomainGroupData];
Get Banner Data
This method returns a dictionary which contains all the keys required to render a banner.
// Swift
OTPublishersHeadlessSDK.shared.getBannerData()
// ObjC
[OTPublishersHeadlessSDK.shared getBannerData];
Banner Allow All
Call this method when user selects Allow All button on the Banner. This will opt-in the user to all Category/Purposes.
// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .bannerAllowAll)
// ObjC
[OTPublishersHeadlessSDK.shared saveConsentWithType:OTConsentInteractionTypeBannerAllowAll];
IAB TCF2
For IAB TCF2 templates, this method also sets the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-in. These values will be encoded into the TC String and saved to UserDefaults.
Banner Reject All
Call this method when user selects Reject All button on the Banner. This will opt-out the user to all Category/Purposes.
// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .bannerRejectAll)
// ObjC
[OTPublishersHeadlessSDK.shared saveConsentWithType:OTConsentInteractionTypeBannerRejectAll];
IAB TCF2
For IAB TCF2 templates, this method also updates the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-out. These values will be encoded into the TC String and saved to UserDefaults.
Banner Close
Call this method when closing the Banner. It will save the default consent values for each Category/Purpose based on the geolocation rule.
// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .bannerClose)
// ObjC
[OTPublishersHeadlessSDK.shared saveDefaultConsentValues];
IAB TCF2
For IAB TCF2 templates, this method also updates the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any). These values will be encoded into the TC String and saved to UserDefaults.
Get Preference Center Data
This method returns a dictionary which contains all the keys required to render a Preference Center.
// Swift
OTPublishersHeadlessSDK.shared.getPreferenceCenterData()
// ObjC
[OTPublishersHeadlessSDK.shared getPreferenceCenterData];
Preference Center Allow All
Call this method when user selects Allow All button on the Banner. This will opt-in the user to all Category/Purposes.
// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .preferenceCenterAllowAll)
// ObjC
[OTPublishersHeadlessSDK.shared saveConsentWithType:OTConsentInteractionTypePreferenceCenterAllowAll];
IAB TCF2
For IAB TCF2 templates, this method also sets the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-in. These values will be encoded into the TC String and saved to UserDefaults.
Preference Center Reject All
Call this method when user selects Reject All button on the Banner. This will opt-out the user to all Category/Purposes.
// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .preferenceCenterRejectAll)
// ObjC
[OTPublishersHeadlessSDK.shared saveConsentWithType:OTConsentInteractionTypePreferenceCenterRejectAll];
IAB TCF2
For IAB TCF2 templates, this method also updates the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-out. These values will be encoded into the TC String and saved to UserDefaults.
Programmatically Update and Save Purpose Consent
These methods are typically utilized in a BYOUI approach and can be used to update and save consent programmatically for a specific category to true
or false
based on user input. Simply pass in the group/category ID and consent status to update the values.
Usage
Modifying the user's consent is a two step approach. updatePurposeConsent()
is used to set the state of the consent (toggles) on the UI and saveConsent()
is used to commit and save the consent to local storage. saveConsent
MUST be called or consent will NOT be committed and changed.
// Swift
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0004", consentValue: true, updateHierarchy: true)
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0002", consentValue: false, updateHierarchy: true)
// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .preferenceCenterConfirm)
Parameters
forGroup
- Category/Group ID of the category to be modified (e.g. C0001, C0002, C0004, etc.)consentValue
- Consent status given by the user for a category/group. Boolean type.updateHierarchy
- Updates the toggle state on the OneTrust UItype
- Denotes the type of interaction used to commit/save consent (e.g. banner allow all, preference center confirm, preference center reject, etc.)
Below is a sample implementation on how to update and save if you have multiple categories to update at a time.
// Swift
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0004", consentValue: true, updateHierarchy: true)
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0005", consentValue: true, updateHierarchy: true)
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0006", consentValue: true, updateHierarchy: true)
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "IABV2_6", consentValue: true, updateHierarchy: true)
OTPublishersHeadlessSDK.shared.saveConsent(type: .preferenceCenterConfirm)
Reset updated consent values for all Categories
This method resets any updated Category/Purpose consent values to their defaults prior to being saved to disk. Use this method if a user makes updates in their Preference Center but then exits without Saving their choices.
// Swift
OTPublishersHeadlessSDK.shared.resetUpdatedConsent()
/// ObjC
[OTPublishersHeadlessSDK.shared resetUpdatedConsent];
Get Vendor List UI
This method will allow your application to retrieve the dictionary required to render the vendor list UI. It returns a dictionary containing local state of active IAB Vendor List if values are updated without save using updateVendorConsent/updateVendorLegitInterest. Returns previously saved IAB vendor state if nothing has changed. Nil if no active vendors are found.
// Swift
OTPublishersHeadlessSDK.shared.getVendorListUI()
// ObjC
[OTPublishersHeadlessSDK.shared getVendorListUI];
Get Vendor List Data
This method will allow your application to retrieve the dictionary required to render the vendor list UI. It returns a dictionary containing saved state of active IAB Vendor List. Returns nil if no active vendors are found.
// Swift
OTPublishersHeadlessSDK.shared.getVendorListData()
// ObjC
[OTPublishersHeadlessSDK.shared getVendorListData];
Get Total Vendor Count
This method allows you to return the total number of IAB TCF vendors your app is using. This can be useful in instances where you're building your own banner and need to include the vendor count as required by IAB.
var vendorCount = OTPublishersHeadlessSDK.shared.getVendorListData(for: VendorListMode.iab)
vendorCount?.count
Query Consent Status for a Category
Query the current consent status for any of the Categories included in your application. This can be used to determine what privacy action is needed at app launch or anytime the consent status is needed without being notified by an event broadcast. Simply pass in the Category ID (eg. C0001) and the method will return the current consent status.
// Swift
OTPublishersHeadlessSDK.shared.getConsentStatus(forCategory: "C0002")
// ObjC
[OTPublishersHeadlessSDK.shared getConsentStatusForCategory:@"C0002"];
Parameters
- forCategory - Custom group ID contained in the group dictionary returned by SDK public methods. Custom group IDs for each category can be obtained from OneTrust console as well.
Returns
- 1 = Consent Given
- 0 = Consent Not Given
- -1 = Consent has not been collected/ sdk is not yet initialized
Query Consent Status for a Specific SDK
Query the current consent status for any of the SDKs included in your application. This can be used to determine what privacy action is needed at application launch or anytime the consent status is needed without being notified by an event broadcast. Pass in the SDK ID and the method will return the current consent status.
// Swift
OTPublishersHeadlessSDK.shared.getConsentStatus(forSDKId: "2368810c-94da-4f18-ab92-c55c5f74cca9")
// ObjC
[OTPublishersHeadlessSDK.shared getConsentStatusForSDKId:@"2368810c-94da-4f18-ab92-c55c5f74cca9"];
Parameters
- SDK GUID - SDK ID contained in the group dictionary returned by SDK public methods. SDK IDs for each SDK configured in the application can be obtained from OneTrust console as well.
Returns
- 1 = Consent Given
- 0 = Consent Not Given
- -1 = Consent has not been collected
Set Data Subject Identifier
This method sets the identifier
for the User Profile the consent is being saved to.
- When the
identifier
is not set, the SDK will generate a unique (anonymous) identifier by default.
Requires SDK Init? | Yes |
---|---|
Method | OTPublishersHeadlessSDK.shared.renameProfile(from: "currentProfileID", to: "newProfileID",completion: { renameSuccess in print(renameSuccess) } ) |
Arguments | id: string |
After renaming the user ID, you must pass the identifier into OTProfileSyncParams
and startSDK
.
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)")
}
Get Data Subject Identifier
This method returns the Data Subject ID saved by the SDK. You can use this value to lookup Consent Receipts for a User on the OneTrust Admin.
Requires SDK Init? | Yes |
---|---|
Method | OTPublishersHeadlessSDK.shared.currentActiveProfile |
Arguments | n/a |
Returns | string |
Should Show Banner
This method will inform your application if the OneTrust Banner has to be presented to the user or not for the user's current location. This method will return true or false based on the geolocation configurations you have assigned for the application in OneTrust environment.
This can be used by your app to determine if functions to build and display UI have to be called.
// Swift
OTPublishersHeadlessSDK.shared.shouldShowBanner()
// ObjC
[OTPublishersHeadlessSDK.shared shouldShowBanner];
Returns
true
- show banner for that geolocationfalse
- don't show banner for user's geolocation / consent has been taken already.
Clear SDK Data
This method will delete all the data saved in the SDK. When application calls this method, SDK will:
- Clear all values saved in UserDefaults
- Clear all previously given user consent values, if any
- Reset all public method values to defaults
// Swift
OTPublishersHeadlessSDK.shared.clearOTSDKData()
//ObjC
[OTPublishersHeadlessSDK.shared clearOTSDKData];
Multi Profile Consent
The following methods can be used to support multi profile consent for your application if you allow multiple user profiles to use one login.
- Use the following method to allow users to switch profiles so that consent profile of the current user is saved and profile for the new user is retrieved from user defaults.
OTPublishersHeadlessSDK.shared.switchProfile(to "profileIDToBeSwitchedTo", completion: {profileSwitchError in print(profileSwitchError ?? "Profile Switch Successful.") } )
- Use the following method to allow you to rename a user's profile.
OTPublishersHeadlessSDK.shared.renameProfile(from: "currentProfileID", to: "newProfileID",completion: { renameSuccess in print(renameSuccess) } )
- Use the following method to delete a user's profile.
OTPublishersHeadlessSDK.shared.deleteProfile("profileIDToBeDeleted", completion: { deletionError in print(deletionError ?? "Profile Deletion Successful.") } )
- Use the following method to retrieve the current profile ID.
OTPublishersHeadlessSDK.shared.currentActiveProfile
Deprecated Methods
acceptAll()
acceptAll()
Method | Swift: OTPublishersHeadlessSDK.shared.acceptAll() ObjC: [OTPublishersHeadlessSDK.shared acceptAll]; |
---|---|
Description | Method connected with the Accept All button for both Banner and Preference Center. |
Reason | We are shifting to a more flexible approach using saveConsent(type: ) . This gives more flexibility for capturing advanced analytics in future. |
Deprecated Version | 6.10.0 |
Migrate To | Applications should migrate to using either: saveConsent(type: .bannerAllowAll) saveConsent(type: .preferenceCenterAllowAll) |
rejectAll()
rejectAll()
Method | Swift: OTPublishersHeadlessSDK.shared.rejectAll() ObjC: [OTPublishersHeadlessSDK.shared rejectAll]; |
---|---|
Description | Method connected with the Reject All button for both Banner and Preference Center. |
Reason | We are shifting to a more flexible approach using saveConsent(type: ) . This gives more flexibility for capturing advanced analytics in future. |
Deprecated Version | 6.10.0 |
Migrate To | Applications should migrate to using either: saveConsent(type: .bannerRejectAll) saveConsent(type: .preferenceCenterRejectAll) |
saveDefaultConsentValue()
saveDefaultConsentValue()
Method | Swift: OTPublishersHeadlessSDK.shared.saveDefaultConsentValue() ObjC: [OTPublishersHeadlessSDK.shared saveDefaultConsentValue]; |
---|---|
Description | Method used when a user Closes the Banner and the default consent for the geolocation is saved to disk. |
Reason | We are shifting to a more flexible approach using saveConsent(type: ) . This gives more flexibility for capturing advanced analytics in future. |
Deprecated Version | 6.10.0 |
Migrate To | Applications should migrate to using saveConsent(type: .bannerClose) |
saveConsentValue()
saveConsentValue()
Method | Swift: OTPublishersHeadlessSDK.shared.saveConsentValue() ObjC: [OTPublishersHeadlessSDK.shared saveConsentValue]; |
---|---|
Description | Method for saving Category/Purpose consent status changes to disk once they've been updated with updatePurposeConsent(forGroup: , consentValue: ) . |
Reason | We are shifting to a more flexible approach using saveConsent(type: ) . This gives more flexibility for capturing advanced analytics in future. |
Deprecated Version | 6.10.0 |
Migrate To | Applications should migrate to using saveConsent(type: .preferenceCenterConfirm) |
initOTSDKData
initOTSDKData
Method | Swift: OTPublishersHeadlessSDK.shared.initOTSDKData() ObjC: [OTPublishersHeadlessSDK.shared initOTSDKData]; |
---|---|
Description | The way the SDK initializes. |
Reason | We are moving away from storing the entire JSON response as a part of this method, and instead will be returning a new OTResponse object in case the application needs to save the entire JSON response. |
Deprecated Version | 6.15.0 |
Migrate To | Applications should migrate to using startSDK() |
getOTSDKData
getOTSDKData
Method | Swift: OTPublishersHeadlessSDK.shared.getOTSDKData() ObjC: [OTPublishersHeadlessSDK.shared getOTSDKData]; |
---|---|
Description | Allows application to access full JSON data payload. |
Reason | We are moving away from storing the entire JSON response in string format in User Defaults. Instead, we will be storing cultureData , domainData , and profile separately. |
Deprecated Version | 6.15.0 |
Migrate To | Applications should migrate to using either: getDomainGroupData() getDomainInfo() getCommonData() |
setDataSubjectIdentifier
setDataSubjectIdentifier
Method | Swift: OTPublishersHeadlessSDK.shared.cache.dataSubjectIdentifier ObjC: [OTPublishersHeadlessSDK.shared setDataSubjectIdentifier:@"User Identifier"]; |
---|---|
Description | Sets the identifier for the User Profile the consent is being saved to. |
Reason | This method has been replaced by renameProfile() |
Deprecated Version | 6.34.0 |
Migrate To | Applications should migrate to using: renameProfile() |
getDataSubjectIdentifier
getDataSubjectIdentifier
Method | Swift: OTPublishersHeadlessSDK.shared.cache.dataSubjectIdentifier |
---|---|
Description | Returns the Data Subject ID saved by the SDK. You can use this value to lookup Consent Receipts for a User on the OneTrust Admin. |
Reason | This method has been replaced by currentActiveProfile() |
Deprecated Version | 6.34.0 |
Migrate To | Applications should migrate to using: currentActiveProfile() |
Override Data subject Identifier
OneTrust SDK logs consent transactions based on consent logging feature that have been enabled in OneTrust's environment. By default, consent logging feature will generate a unique identifier for each device and log transactions considering it as an anonymous user.
OneTrust provides a method to override this randomly generated identifier by passing a valid String value for identifier variable. This method will set the value to SDK and show as the Data Subject Identifier in OneTrust environment while reviewing transactions. This method MUST be called after initializing the SDK.
If the identifier is set after user giving consent, then the last anonymous transaction and the subsequent transactions will be logged with the new identifier set by your application.
// Swift
OTPublishersHeadlessSDK.shared.overrideDataSubjectIdentifier("userId")
// ObjC
[OTPublishersHeadlessSDK.shared overrideDataSubjectIdentifier:@"userId"];
Parameters
- Data Subject Identifier - a valid String value.
Updated 5 months ago