The Utiq API offers objects and methods for on-demand access to various Utiq functionalities with a single call. The API is available as part of the Utiq loader script (utiqLoader.js
) and can be accessed via the window.Utiq.API
object. Specific methods are described below.
handleConsentChange
handleDataClear
getUtiqConsentStatus
getIdGraphEntry
setVerboseLoggingLevel
resetLoggingLevel
showConsentManager
handleConsentChange
Method used for handling custom CMP consent change by managing the consent cookie and dispatching proper events handled by the Utiq service. It should be used when there’s a need to change the consent status.
Parameters:
isConsentGranted
: boolean - when consent is granted set to true
. Otherwise, if consent is rejected set to false
.Example usage:
try {
window.Utiq.API.handleConsentChange(true)
} catch (err) {
console.error(`handleConsentChange API call failed. Reason: ${err.message}`)
}
handleDataClear
Method used to handle clear of all Utiq-related data from the browser cache and memory. Data clear is done automatically when window.Utiq.API.handleConsentChange(false)
is called, so this method does not have to be called manually within the Utiq flow.
Parameters:
Example usage:
try {
window.Utiq.API.handleDataClear()
} catch (err) {
console.error(`handleDataClear API call failed. Reason: ${err.message}`)
}
getUtiqConsentStatus
Method used to get current Utiq consent status.
Parameters:
Returns:
true
/ false
undefined
- only if the Utiq service has not yet been initializedExample usage:
try {
const status = window.Utiq.API.getUtiqConsentStatus()
// Do something with the status
} catch (err) {
console.error(
`getUtiqConsentStatus API call failed. Reason: ${err.message}`
)
}
getIdGraphEntry
Method used to get current Utiq consent status.
Parameters:
entryName
: string - Name of the entry that should be extracted from the ID graph. Accepted values are: mtid
, atid
, ttl
, domain
, fetchDate
.Returns:
string type value
Example usage:
try {
const value = window.Utiq.API.getIdGraphEntry('entryName')
// Do something with the value
} catch (err) {
console.error(
`getIdGraphEntry API call failed. Reason: ${err.message}`
)
}
setVerboseLoggingLevel
This method activates verbose
logging, including DEBUG
and TRACK
messages for detailed insights into flow steps or issues. The logging level, stored in the browser’s local storage, remains enabled until reset using the resetLoggingLevel
method, detailed below.
Parameters:
Returns:
This method logs
"[INFO] Verbose logging level has been set"
message, that indicates the logging level has been set successfully.
Example usage:
try {
window.Utiq.API.setVerboseLoggingLevel()
} catch (err) {
console.error(
`setVerboseLoggingLevel API call failed. Reason: ${err.message}`
)
}
resetLoggingLevel
This method reverts the logging level to the default by deleting the local storage entry. The default level, covering ERROR
, WARNING
, and INFO
messages, offers adequate operational insights as the flow progresses.
Parameters:
Returns:
This method logs
"[INFO] Logging level has been reset to info level"
message, that indicates the logging level has been set back to the default successfully. If theverbose
logging level was set beforehand, it could also show a couple of other entries mentioning the value of the current logging level, that is set in browser’s local storage.
Example usage:
try {
window.Utiq.API.resetLoggingLevel()
} catch (err) {
console.error(
`resetLoggingLevel API call failed. Reason: ${err.message}`
)
}
showConsentManager
Displays the Utiq Consent Manager overlay popup. This method operates with the default Utiq consent management setup. Find more details on the Utiq dedicated consent popup page.
Parameters:
Returns:
Example usage:
try {
window.Utiq.API.showConsentManager()
} catch (err) {
console.error(`showConsentManager API call failed. Reason: ${err.message}`)
}