There was a problem loading the comments.

How do I add cookies to the cookie consent?

Support Portal  »  Knowledgebase (FAQ)  »  Viewing Article

Editions: Enterprise, Ultimate, Corporate
Versions: 4.3.0+

In case of the individual extension of VIMP, it may be necessary that you have to include your own cookies or cookies of third party providers in the cookie consent.

In the following we explain how you have to proceed.

In order to set your own cookies via PHP, you first have to check in the code whether the user has accepted the cookie consent or the corresponding category. You can check this as follows:

isset($_COOKIE['cookiesAccepted']) [&][&] json_decode($_COOKIE['cookiesAccepted'])->preferencesCookies

In the example above we check for accepting the category "preferences". If the condition is true, you can use PHP (>=7.3) to set your own cookie in the appropriate component as follows:

setcookie(nameOfCookie, valueOfCookie, [
 'expires' => $expire,
 'path' => $path,
 'domain' => $domain,
 'samesite' => $sameSite,
 'secure' => $secure,
 'httponly' => $httpOnly,

Third party cookies can be set via Javascript e.g. in the layout.php file of a template as follows:

<?php if(isset($_COOKIE['cookiesAccepted']) [&][&] json_decode($_COOKIE['cookiesAccepted'])->partnershipsCookies) != '') : ?>
<script src="//<cookie_javascript.js>"></script>
<?php endif; ?>

In this case, replace "<cookie_javascript.js>" with the file containing the javascript code for setting the cookie. The "src" attribute of the <script> tag must point to the corresponding file.

Similarly, you can also set third-party cookies in a component using PHP:

<?php if (isset($_COOKIE['cookiesAccepted']) [&][&] json_decode($_COOKIE['cookiesAccepted'])->partnershipsCookies): ?>
<?php include_partial('<path_to_partial>'); ?>
<?php endif; ?>

Replace "<path_to_partial>" with the corresponding route, e.g. "start/_myCookie". The corresponding partial must be located in the corresponding template folder (e.g. /templates/pacific/templates/frontend/start).

Share via

Related Articles