Guide: implementation of the cookie script (step 4)

Pages

Guide: implementation of the cookie script (step 4)

The script will work on your website upon completing the preceding steps. All you need to specify is when specific cookies are allowed to be used. This should be aligned with the levels (1, 2 or 3) that you defined in the configuration file in step 2. In this last step we will explain how to ensure that cookies are stored only in case the visitor accepts them. Find all the elements on your website which use cookies. This does not only concern e.g. Google Analytics, but also social media buttons (Facebook, Twitter, etc.) and any maps from Google Maps on your contact page.

4.1 Implementation with PHP

$cookie_tool->get_level()
With the above mentioned you can retrieve the level that has been accepted by the visitor. You can then set (or not set) specific cookies of this value. Hereby are some examples:
if($cookie_tool->get_level() == 1) {
// Code level 1 is accepted
}

  • Level 1 is accepted. You can therefore place all cookies.

if($cookie_tool->get_level() > 0 && $cookie_tool->get_level() < 3) {
// Code level 2 is accepted
}

  • Level 2 is accepted. You can therefore use cookies that correspond to level 2 and 3.

if($cookie_tool->get_level() == 3) {
// Code level is accepted
}

  • Level 3 is accepted. You may only use necessary cookies. You are allowed to store these directly, without the acceptance of the visitor.

<?php if($cookie_tool->get_level() > 0 && $cookie_tool->get_level() < 3) { ?>
< script type="text/javascript">// < ![CDATA[ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXX-XX']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); // ]]>
<?php } ?>

  • The above mentioned is an example of the implementation for Google Analytics.
  • Because Google Analytics may only work at level 1 or 2, this will be checked first. If it is correct, then the JavaScript will be executed.

4.2 Implementation with JavaScript

cookie_tool_level
The variable above contains the visitor’s level. You can then set (or not set) specific cookies of this value. Hereby are some examples:
if(cookie_tool_level == 1) {
// Code level 1 is accepted
}

  • Level 1 is accepted. You can therefore place all cookies.

if(cookie_tool_level > 0 && cookie_tool_level < 3) {
// Code level 2 is accepted
}

  • Level 2 is accepted. You can therefore use cookies that correspond to level 2 and 3.

if(cookie_tool_level == 3) {
// Code level 3 is accepted
}

  • Level 3 is accepted. You may only use necessary cookies. You are allowed to store these directly, without the acceptance of the visitor.

4.3 Links to pop-up settings

The pop-up will no longer be visible after the visitor has accepted the cookies. You can however, give visitors the possibility to adjust the cookie settings. You can easily link to the pop-up settings by adding the ID: “cookie_tool_config” to your link. You can create a link to the settings by including this code:
Cookie settings

Would you like to make an appointment?