API Methods

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

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}`)
}

revokeConsentWithPopup

Method used to revoke consent. The user sees a confirmation popup upon revokation completion. It should be used instead of the handleConsentChange method when the user should see a confirmation of the consent revokation.

Parameters:

  • none

Example usage:

try {
  window.Utiq.API.revokeConsentWithPopup()
} catch (err) {
  console.error(`revokeConsentWithPopup 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:

  • none

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:

  • none

Returns:

  • boolean: true / false
  • undefined - only if the Utiq service has not yet been initialized

Example 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

  • value of a data entry
  • “Entry key (string) parameter is missing”
  • “No Utiq configuration set up”
  • “No required IDC data present. Cannot extract the ID graph entry”
  • “Could not find an entry for provided entry name: {entryKey}”

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:

  • none

Returns:

  • none

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:

  • none

Returns:

  • none

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 the verbose 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:

  • none

Returns:

  • none

Example usage:

try {
  window.Utiq.API.showConsentManager()
} catch (err) {
  console.error(`showConsentManager API call failed. Reason: ${err.message}`)
}