Integration recipes
The cases that come up in a real module, each with its solution. The example module applies most of them: the relevant file is given so that you can copy code that works.
The minimum: a script after consent #
For a module that only loads a third-party script:
- Declare the partner: see Declare the partners.
- Print the script with
type="kixelltag/javascript"anddata-kt-vendor="mymodule": see Browser side. - Register the hooks in
install()and in an upgrade script. - Tell the merchant to tick the partner in the Kixell Tag partner screen.
If this script stores something on the device, it must also stop and clean up when the visitor withdraws consent in the page.
A cookie set by the server #
In the demo: kixconsentdemo.php (setVisitorCookie(), sendCookie()), controllers/front/collect.php, views/js/kixconsentdemo.js.
page script: kixelltag_consent_state, then hasConsent('mymodule') = yes
└─ POST /module/mymodule/collect (fetch, credentials: 'same-origin')
front controller: hasVendorConsent('mymodule') again
yes: Set-Cookie mymodule_vid=<random identifier>; HttpOnly; SameSite=Lax; Secure
no: Set-Cookie that deletes it
JSON response {"consent": true|false}
- The decision is made in the browser, because the page may come from a cache, then checked on the server in a request that no cache shares: the browser cannot be trusted.
- A cookie set over HTTP can be HttpOnly, and Safari does not limit its lifetime to 7 days as it does for a cookie written in JavaScript.
- The script calls the controller only once per browsing session: it notes this in
sessionStorage, only after a yes. - The cookie only contains a random identifier. The data stays on the server, stored under this identifier.
Withdrawing consent #
In the demo: hookActionKixellTagConsent() and the "revoke" branch of views/js/kixconsentdemo.js.
Two paths, so that a withdrawal is always applied:
- On the server, in the
actionKixellTagConsenthook: when$params['modules']['mymodule']is false, read the identifier from your cookie, delete this visitor's data, then the cookie. This path works without JavaScript and for a choice made on a linked site. - In the page: when
hasConsent('mymodule')becomes false, delete what the page stored. If the server keeps data, call the controller withaction=revoke: it only deletes if it too finds no consent.
Withdrawal does not require deleting data already used for a completed purpose, such as an order already attributed or an invoice. State in your privacy policy what you keep and why.
Orders, payment notifications and scheduled tasks #
A payment notification (IPN, webhook), a scheduled task or the command line does not have the visitor's cookies: hasVendorConsent() always answers no there.
- While the visitor is browsing (front controller,
actionCartSave, cart or checkout pages), read the consent and record it with your data, for example one row per cart with aconsentcolumn. - When the order is validated (
actionValidateOrder), use the consent recorded for the order's cart, never a live reading. - When the consent hook answers no, delete or anonymise this visitor's rows.
Keeping proof of consent #
The hook passes consent_uid, the visitor's identifier in the consent register: date, choice and version of the partner list. Record it with the data the consent covers if you need to prove it later. It is personal data: do not log it and do not send it to any third party.
Several consent tools #
A module sold to many shops can support Kixell Tag and other tools. Provide a setting, the consent adapter, and a single function that answers yes or no:
public function hasConsent()
{
switch (Configuration::get('MYMODULE_CONSENT_ADAPTER')) {
case 'kixelltag':
return self::kixellTagConsent('mymodule'); // the hasVendorConsent() wrapper
case 'other_cmp':
return self::otherCmpConsent();
default:
return false; // empty or unknown setting: no consent
}
}
- With the
kixelltagadapter, use only this API: do not parse the Kixell Tag cookies with a regular expression. - Declare the partner only with this adapter: return
[]otherwise. - In the page, listen to
kixelltag_consent_stateonly with this adapter.
Without Kixell Tag #
When Kixell Tag is missing, disabled or too old, or its banner is turned off, the method answers no, the hooks are not called and the kixelltagOnReady function never is. The module collects nothing.
Do not add a fallback such as "no consent tool, so I collect". If the merchant wants the module to work without a consent tool, this must be an explicit module setting, which they choose knowingly, never a default behaviour.
Checking another partner #
A module that sends data to a known partner can check consent to that partner directly: KixellTag.hasConsent('iab:755') in the page, hasVendorConsent('iab:755') on the server. The partner must be ticked by the merchant, otherwise the answer is no. The identifiers of common platforms are in Partners (vendors).
Updating an existing module #
Shops that already have your module do not go through install() again. Register the hooks in an upgrade script and increase the module version:
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_1_5_0($module)
{
return $module->registerHook('actionKixellTagRegisterVendors')
&& $module->registerHook('actionKixellTagConsent');
}
Then let merchants know in your release notes: as long as they have not ticked the new partner in the Kixell Tag partner screen, the module receives no consent and collects nothing.
PrestaShop 1.6 and older PHP versions #
The API works the same way from PrestaShop 1.6 to 9 and from PHP 5.6 to 8. Only a few PrestaShop and PHP calls change:
| Need | PrestaShop 1.6 | PrestaShop 1.7 to 9 |
|---|---|---|
| Add a script | $this->context->controller->addJS(…) |
$this->context->controller->registerJavascript(…) |
| Pass settings to the script | Media::addJsDef([…]) |
Media::addJsDef([…]) |
| Print at the bottom of the page | displayFooter |
displayFooter or displayBeforeBodyClosingTag |
| Front controller | ModuleFrontController with $ajax = true, response in init() then exit |
Same |
| Need | PHP 5.6 to 7.2 | PHP 7.3 and higher |
|---|---|---|
SameSite cookie |
setcookie($name, $value, $expires, '/; SameSite=Lax', '', $secure, true) |
setcookie($name, $value, ['samesite' => 'Lax', …]) |
| Random identifier | openssl_random_pseudo_bytes(16) before PHP 7.0, random_bytes(16) from then on |
random_bytes(16) |
Missing or wrong information? Tell the support team