JavaScript API 

cookieman.js exposes these methods:

cookieman.showOnce() 

cookieman.showOnce()

| Data type: void |

Shows the confirmation modal when consent has not been saved yet.

It is automatically called on each page from cookieman-init.js (with an aditional condition, see When is the popup shown to users?)

cookieman.show() 

cookieman.show()

| Data type: void |

Shows the confirmation modal.

You can also use the attribute data-cookieman-show on any element to show the modal when clicked.

<button data-cookieman-show>
  Adjust your cookie preferences
</button>
Copied!

cookieman.hide() 

cookieman.hide()

| Data type: void |

Hides the confirmation modal.

cookieman.consenteds() 

cookieman.consenteds()

| Data type: array | Example: ["mandatory", "ads"] |

Returns all group keys the user has consented to.

cookieman.hasConsented(groupKey) 

cookieman.hasConsented(groupKey)

| Data type: boolean |

Returns true if the user has consented to the given group (e.g. 'marketing'), else false.

cookieman.hasConsentedTrackingObject(trackingObjectKey) 

cookieman.hasConsentedTrackingObject(trackingObjectKey)

| Data type: boolean |

Returns true if the user has consented to all groups that contain the given trackingObject, else false.

trackingObjectKey is the trackingObjects.‹tracking object key› from TypoScript, e.g. 'Matomo'.

cookieman.onScriptLoaded(String trackingObjectKey, int scriptId, function callback) 

cookieman.onScriptLoaded(String trackingObjectKey, int scriptId, function callback)

| Data type: void |

This is a hook to do things after an external script has been loaded. This is useful if you are interacting with external scripts that are loaded by Cookieman.

  • trackingObjectKey is the trackingObjects.‹tracking object key› from TypoScript, e.g. 'Matomo'.
  • scriptId is the number of the <script> inside your trackingObjects.‹tracking object key›.inject (starting from 0 with the first).
  • callback is a function reference. It receives trackingObjectKey and scriptId (see example below). The callback is called immediately if the referred to <script> has already finished loading.

Example:

cookieman.onScriptLoaded(
    'Matomo',
    0, // first script in 'inject'
    function (trackingObjectKey, scriptId) {
        _paq.push(['trackConversion'])
    }
)
Copied!

cookieman.onConsented(String groupKey, function callback) 

cookieman.onConsented(String groupKey, function callback)

| Data type: void |

This is a hook to do things once consent for a given group has been given – an alternative to using a trackingObject's inject section.

  • groupKey is the settings.groups.‹group key› from TypoScript, e.g. 'marketing'.
  • callback is a function reference. It receives groupKey (see example below). The callback is called immediately if the group is already consented to. Otherwise, it is called the next time consent is given (accept-all, save, or cookieman.consent()). If consent is later revoked and given again, the callback fires again.

Example:

cookieman.onConsented(
    'marketing',
    function (groupKey) {
        loadMyVideoEmbeds()
    }
)
Copied!

cookieman.onConsentChanged(function callback) 

cookieman.onConsentChanged(function callback)

| Data type: void |

This is a hook to react whenever the user's consent selections are saved (accept-all, accept-none, save, or cookieman.consent()) – useful if you'd rather listen for changes than poll cookieman.hasConsented().

  • callback is a function reference. It receives the array of currently consented group keys (same shape as cookieman.consenteds()).

Example:

cookieman.onConsentChanged(
    function (consenteds) {
        console.log('consent is now:', consenteds)
    }
)
Copied!