Developer forum

Forum » Feature requests » Cookie Manager - Extra info.

Cookie Manager - Extra info.

Claus Kølbæk
Claus Kølbæk
Reply

Hi

When listing the cookies from the cookie manager you seem to only be able to list categories atm. - and even if you create a custom category and add cookies to that list, you cannot in the frontend get a list of the cookies you have added to the categori.

What I (annoyingly) need to be able to list, is sorta what you do in the bottom of the page here: https://doc.dynamicweb.com/documentation-9/platform/platform-tools/cookie-manager a full list of all the cookies with explanations - another example of the end product I need, is the details part the popup here: https://cookieinformation.com

So my request:

1. Be able to add a description to each cookie in the backend so it is not just a cookie name, but also able to contain something similar to your "Used for" (I know I can achieve this by saving this info elsewere, fx in translate tags and such, it would just be great if it could all be stored together).

2. Get a loop under each categori that can list the cookies added to the categori.


Replies

 
Claus Kølbæk
Claus Kølbæk
Reply

After diving into the API a bit I see that I can actually solve number 2. almost by using Dynamicweb.Environment.CookieManager.GetCategoryCookies(i.GetString("Category")). However for some reason it returns a string instead of a Dynamicweb.Environment.Cookie which I honestly expected it too - which I then can solve by Dynamicweb.Environment.CookieManager.GetCookie(cookieName). Then I at least have a cookie class with some of the information I need, and am then able to match the cookie name to a list of information stored in the website settings or similar.  - Still would really prefer to be able to store it in one central place, or maybe attach an item or custom fields like fx with users.

Now I just need to figure out how to let a user opt in and out of a custom category instead of using your built in levels, the documentation is a bit low on help here, so any assistance would be appreciated :) 

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Claus

Thank you for the input. Something will happen in this area as we have new EU legislation due next year related to this - going from the cookie directive to the cookie regulation. But right now we are awaiting exactly what will be the new rules.

Meanwhile, find a template attached that handles category opt-ins.

And the code:

@using Dynamicweb.Environment;

@{

 var categories = CookieManager.GetCategories();

}



<div id="cookieWarningContainer">


    <form id="cookieWarningForm" method="post" action="/Admin/Public/CookieOptInLevelConfig.aspx">

        <input type="hidden" name="cmd" value="SetCookieOptInLevel" />

        <input type="hidden" name="OptInLevel" id="OptInLevel" value="0" />

 

        <fieldset>

            <legend>Cookies</legend>

            <p>

 This website uses cookies to continuously improve the user experience and performance as well as make relevant marketing based on your interests. 

 Your information will be shared with 3rd parties such as LinkedIn and Google. 

 You may withdraw your consent at any time. Read more on our cookie and personal data policy. 

 </p>

 <div style="text-align: right;">

 <button type="button" onclick="setOptInCookie(1);">Allow selection</button>

 <button type="button" onclick="setOptInCookie(2);">Allow all</button>

 </div>

 @if(categories.Any()){

 <div class="cookieCategoryList">

 @foreach (var category in categories)

 { 

 <div><label><input type="checkbox" name="OptInCategory" value="@category" /> @category</label></div>

 }

 <div style="float:right;margin: 4px;">

 <a id="cookieShowDetailsButton" href="javascript:toggleCategoryDetails(true);">Show details</a>

 <a id="cookieHideDetailsButton" style="display:none;" href="javascript:toggleCategoryDetails(false);">Hide details</a>

 </div>

 </div>

 }

 <div id="cookieCategoryDetails" style="display:none;overflow:auto;">

 <fieldset>

 <legend>Cookie declaration</legend>

 <div class="cookieCategoryMenu"> 

 @foreach (var category in categories)

 { 

 var cookies = CookieManager.GetCategoryCookies(category);

 if (cookies.Count > 0){ 

 <a id="cookieCategoryMenuButton_@category" name="cookieCategoryMenuButton" href="javascript:showCategoryDetail('@category');"><label>&nbsp;</label>@category (@cookies.Count)</a>

 }

 }

 </div>

 <div style="overflow:auto;"> 

 @foreach (var category in categories)

 { 

 <div id="cookieCategoryDetail_@category" name="cookieCategoryDetail" style="display:none;">

 <ul>

 @foreach (var cookieName in CookieManager.GetCategoryCookies(category))

 { 

 <li>

 @cookieName

 </li>

 }

 </ul>

 </div>

 }

 </div> 

 </fieldset> 

 </div>

        </fieldset>

    </form>


    <script>

        function toggleCategoryDetails(show) {

            document.getElementById("cookieCategoryDetails").style.display = show ? "" : "none";

            document.getElementById("cookieShowDetailsButton").style.display = show ? "none" : "";

     document.getElementById("cookieHideDetailsButton").style.display = show ? "" : "none"; 

        } 

 

     function showCategoryDetail(categoryName) {

 var menuButtons = document.querySelectorAll('#cookieCategoryDetails a[name=cookieCategoryMenuButton]');

 menuButtons.forEach(function(e){

 e.classList.remove("active");

 }); 

 document.getElementById("cookieCategoryMenuButton_" + categoryName).classList.add("active");

 

 var details = document.querySelectorAll('#cookieCategoryDetails div[name=cookieCategoryDetail]');

 details.forEach(function(e){

 e.style.display = "none";

 }); 

 document.getElementById("cookieCategoryDetail_" + categoryName).style.display = ""; 

        } 

 

        function setOptInCookie(optInLevel) {

            document.getElementById("OptInLevel").value = optInLevel;

 

            var formElement = document.getElementById("cookieWarningForm");

            var formData = new FormData(formElement);


            var xmlhttp = new XMLHttpRequest();

            xmlhttp.onreadystatechange = function () {

                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                    var container = document.getElementById("cookieWarningContainer");

                    container.parentNode.removeChild(container);

                    return false;

                }

            }


            xmlhttp.open(formElement.method, formElement.action);

            xmlhttp.send(formData);


            return false;

        }

    </script>

 

 <style>

 #cookieWarningContainer{

 position: absolute; 

 top:0; 

 left:0; 

 width:100%; 

 height:100%; 

 background-color: rgba(0, 0, 0, .3);

 }

 

 #cookieWarningForm{

 position: absolute; 

 top: 50%; 

 left: 50%; 

 transform: translate(-50%, -50%); 

 padding: 20px; 

 color: #000; 

 background-color: #fff; 

 border: 1px solid #999; 

 border-radius: 10px; 

 box-shadow: 3px 3px 3px 3px rgba(0, 0, 0, .1);

 }

 

 #cookieWarningContainer .cookieCategoryList{

 overflow:auto;

 } 

 

 #cookieWarningContainer .cookieCategoryList div{

 float:left;

 margin-right:10px;

 font-weight: bold;

 } 

 

 .cookieCategoryMenu {

 float:left; 

 white-space: nowrap;

 }


 .cookieCategoryMenu a {

   background-color: #eee;

   color: black;

   display: block;

   padding: 12px;

   text-decoration: none;

 }


 .cookieCategoryMenu a:hover {

   background-color: #ccc;

 }


 .cookieCategoryMenu a.active {

   background-color: #4CAF50;

   color: white;

 }

 </style> 

</div>
Votes for this answer: 1
 
Claus Kølbæk
Claus Kølbæk
Reply

Alright so adding Categories=CookieCategoryName1,CookieCategoryName2 to the cookie Dynamicweb.CookieOptInLevel is basicly what is needed, with the opt in level being 1.

And I understand waiting for the new rules, however, after new guide lines (found here, danish link: https://www.datatilsynet.dk/presse-og-nyheder/nyhedsarkiv/2020/feb/nye-retningslinjer-om-behandling-af-personoplysninger-om-hjemmesidebesoegende/) we have customers who don't want to wait.

Anyways - thank you for the assistance, should be able to find a somewhat working solution with this.