Skip to content

JavaScript API

Our script exposes a number of functions and properties for programmatically controlling the consent solution.

All of these handle the consent categories we support:

  • undefined = Unknown cookies not yet defined in our tool
  • necessary = Strictly necessary cookies
  • functional = Functional cookies
  • statistical = Statistics cookies
  • marketing = Marketing cookies

Below is a reference to the officially supported methods. Any usage beyond this is not officially supported, and functionality cannot be guaranteed. This includes actions such as reading our cookie directly or extracting other information from properties not listed below.

If you have needs that aren’t covered by the current API surface, feel free to contact us, and we’ll do our best to find an official way to support them.

Listen for consent changes

When building functionality that depends on a visitor’s consent, listen for the CookieConsent event so your code can respond when the visitor changes their choices.

cookieTractor.consent.contains() and cookieTractor.consent.current let you check the current consent state, but a one-time check does not notify your code of later changes. Your implementation should handle both granted and withdrawn consent.

See JavaScript Events and Functions for event details and implementation examples.


This function opens the cookie dialog in the visitor’s browser:

cookieTractor.openConsentSettings()

Returns true if the visitor currently has consent for the specified category; otherwise returns false.

This checks consent at the time of the call. To respond to subsequent consent changes, listen for the CookieConsent event.

cookieTractor.consent.contains(categoryAlias)

Function to add consent for the specified category. You can call this with a string or an array of strings to add multiple categories:

cookieTractor.consent.add(categoryAlias)

Removes consent for the specified category:

cookieTractor.consent.remove(categoryAlias)

Contains the visitor’s consent key/ID:

cookieTractor.consent.key

An array of category aliases representing the visitor’s current consents.

Reading this property does not notify your code when consent changes. Listen for the CookieConsent event to respond to updates.

cookieTractor.consent.current

A list of strings with categoryAlias for all consent categories available on the website. This is a reference list, not the visitor’s choices:

cookieTractor.consent.available

Properties that contain string representations of our consent categories:

cookieTractor.category.{categoryAlias}

// that is:
cookieTractor.category.undefined
cookieTractor.category.necessary
cookieTractor.category.functional
cookieTractor.category.statistical
cookieTractor.category.marketing

Deletes our consent cookie from the visitor’s browser:

cookieTractor.cookie.remove()

Helper function that attempts to delete a cookie by name using the cookieName parameter:

cookieTractor.cookie.remove(cookieName)

Support

If you have questions about the JavaScript API, feel free to contact us at info@cookietractor.com