Developer Corner¶
Target group: Developers
JavaScript API¶
cookieman.js exposes these methods:
cookieman.showOnce()¶
- Data type
- void
- Description
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()¶
- Data type
- void
- Description
Shows the confirmation modal. You can call that from anywhere you need it (e.g. with a link from your data protection declaration page).
<button onclick="cookieman.show()"> Adjust your cookie preferences </button>
Attention
If your website uses a strict Content-Security-Policy (see Mozilla Developer Network) the onclick= needs to be replaced with registering a click-handler from an external <script> (also see how cookieman supports Content-Security-Policy).
cookieman.hide()¶
- Data type
- void
- Description
- Hides the confirmation modal.
cookieman.consenteds()¶
- Data type
- array
- Example
- [“mandatory”, “ads”]
- Description
- Returns all groups keys the user has consented to.
cookieman.hasConsented(selection)¶
- Data type
- boolean
- Description
Returns true if the user has consented to the given selection, else false.
A selection is any name of a checkbox in the popup, e.g. ‘marketing’.
cookieman.onScriptLoaded(String trackingObjectKey, int scriptId, function callback)¶
- Data type
- void
- Description
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). 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']) } )
Tip
Cookieman also includes the (1kB) cookie library JavaScript Cookie that also exposes its API and makes it easier to work with cookies.
Development¶
Choose your branch:
- 8lts (TYPO3 8.7)
- 9lts (TYPO3 9.5)
- master (TYPO3 10.x).
To try it: just run ddev start which will install a TYPO3 with example content and cookieman. This installs helper extensions that automatically enable a certain theme and some TypoScript setup to facilitate development. The admin user is “admin”, password “adminadmin”.
After switching branches, you might need a git clean -fdX -e ‘!.idea’.
To throw away the database and restart cleanly, run ddev rm -ORU && git clean -fdX -e ‘!.idea’ && ddev start
ddev install-git-hooks will install the CGL tools as a pre-commit hook.