Posted on 28/05/2024 06:01:02
There are some points of how to control the cookies.
We have a tool to manage the cookies: Settings > Web & HTTP > Cooke Manager.
- In "Settings" you may configure some base settings. There you may set your own template. The templite file should be placed in the "Files/Templates/CookieWarning" folder.
- In "Categories" you may manage the available categories. And then assign some cookies to the categories. If you use the built-in "Cookies.cshtml" Swift template, it automatically list all the Categories - renders them as togglers in the modal.
Once a user selected some Categories in the modal and save it, the "Dynamicweb.CookieOptInLevel" cookie will be created. While this cookie is exist and not expired, you cannot open that modal again.
To remove the cookie you can:
1. Execute the "Dynamicweb.Environment.CookieManager.ExpireCookie("Dynamicweb.CookieOptInLevel");" code in any .cshtml template.
2. POST a form with needed parameters - the example of the form is placed in the built-in "Cookies.cshtml" Swift template. Search for "dwCookieModalCustomForm" in the file.
To remove the cookie you need to have a form with the same "method" and "action" and 2 hiddens it has. Just set the "OptInLevel" hidden value to "0".
The page reload is need in both cases to take effect.
The Item Type where you can configure the cookies modal is "Master" - it uses in Website settings. But it only affect how the built-in "Cookies.cshtml" renders.
For any manipulations with the cookies themselves, you can use the "Dynamicweb.Environment.CookieManager".
There are 2 related threads where you may find some additional info:
https://doc.dynamicweb.com/forum/templates/templates/cookie-manager
https://doc.dynamicweb.com/forum/swift/swift/enable-and-use-consent-mode-gtm-through-dw-cookie-manager