Developer forum

Forum » Templates » Cookie manager.

Cookie manager.

Simon Nordahl
Simon Nordahl
Reply

Hi all

 

I've been looking around, but I can’t find a best practice or up to date descriptions for cookie warnings through the cookie manager (especially in Dynamicweb9).

First of what does the optinlevel (1-3?) cover? What’s the difference between them?

What the point of being able to choose the template and setting in the cookie manager if it’s always overruled (even when there’s no template selected) by the setting on website properties?

Is necessary to include JavaScript in the template to submit the cookie value (I thought you would inject the script)?

I’ve taken the JS from one of our Dynamicweb8 solutions, does it follow your best practice?

    <script type="text/javascript">

        function setOptInCookie(optInLevel) {

            var xmlhttp;

            if (window.XMLHttpRequest) {

                xmlhttp = new XMLHttpRequest();

            } else {

                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

            }

            xmlhttp.onreadystatechange = function () {

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

                    var div = document.getElementById(<id of cookie warning element>);

                    div.parentNode.removeChild(div);

                    return false;

                }

                return false;

            }

            xmlhttp.open("GET",

                "/admin/public/CookieOptInLevelConfig.aspx?cmd=SetCookieOptInLevel&OptInLevel=" + optInLevel,

                true);

            xmlhttp.send();

            return false;

        }

    </script>

Lastly we are trying to access item values on the area, but I can’t seem to get viewmodels to work in the Cookie template.

I’ve tried with both PageViewModel and ParagraphViewModel, but doing so trows an error saying the viewmodel has not been set.

Is it a bug or intended use?                                                             
 

Regards 

Simon Nordahl

 

 


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Simon,

Cookie opt-in levels
0 = None. Deny setting cookies.
1 = Functional. Allow only functional cookies, used by default if no opt-in cookie was set.
2 = All. Allow any cookie to be set.
These opt-in levels are also described in the standard template.

Setting the opt-in cookie
The opt-in cookie needs to be set by using javascript or .NET code. So you need to include a script in your template - similar to what is found in the standard template.

Cookie warning template
The default template can be set in Settings > Web and HTTP > Cookie Manager
This can be overridden by selecting a different template on each website. If this doesn't work as expected on your site, please provide more details (either link to the site or DW version and settings used).
For more details, see http://doc.dynamicweb.com/documentation-9/platform/advanced-settings/web-and-http#3519

View models
PageViewModel can be used in page layout templates.
ParagraphViewModel can be used in paragraph templates.
All other templates does not have view models (yet).
For more details, see http://doc.dynamicweb.com/documentation-9/platform/templating/razor-templates-viewmodels

I hope this answers your questions :)

Best regards,
Morten

 
Simon Nordahl
Simon Nordahl
Reply

Hi Morten

Thanks for the answer.

I wonder how much of this great knowledge is lost on information that is only present in the standard templates and now on the documentation portal.

I have taken your advice and I have just download, version 9.3.4, and looked for the standard templates in Admin\Update\Files\CookieWarning and found the attached HTML files (nothing in razor).

edit:

I missed the explanation on the opt in levels because it was embeded in html and not as commented lines.

 

I was hoping that you would make  it so the standard cookie script were there by default either through script injection in the template or have it in be available in form of a template tag (or later on a viewmodel), so we wouldn’t have to copy-paste the same script every time.

 

If I wanted to use the default template in Settings > Web and HTTP > Cookie Manager how do I deactivate the setting on the website? I can’t unselect a template, is it a matter of selecting “Custom” user notification? 

 

If we do not have any viewmodels available in the cookie template, what do we have? As far as I can tell there’s no template tags either. Is the only answer to go through the current pageview and try get values?

 

Regards Simon

 

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Simon,

Injecting cookie opt-in template / script
Most developers would like to have full control over markup and scripts included in the front end. This is one of the reasons why we don't just inject it.
We could provide it as a new option or add separate template tags for it, but I don't see much benefit in doing so compared to just using and modifying one of the provided standard templates?

Disabling the Cookie Manager settings on specific websites (from doc site: http://doc.dynamicweb.com/documentation-9/platform/advanced-settings/web-and-http#3519)
The template selected in the Cookie Manager settings are used on all websites in a solution – and cannot be fully disabled.
However, you can create an empty warning template and use it on the websites which should not display a cookie warning.

To do so:

  • Go to the Website settings
  • Click the Cookies-button in the ribbon bar
  • Select the empty template (or select Custom and don’t implement any custom code)
  • This de facto disables the Cookie Manager on that website.

Information available in cookie warning template
You can use the global template tags
You can use snippets to include content defined in your layout template (where you do have access to view models etc.)
You can use a razor template to fetch the information you need...

@Pageview.Area.Item["MySetting"]
@RenderItem(new { ItemType = Pageview.Area.ItemType, ItemId = Pageview.Area.ItemId, DetailsTemplate = "SomeFolder/SomeTemplate.cshtml"}).

... or you can configure the cookie manager to use custom notifications and add your own implementation in the layout template - without using a separate template for the warning.

Best regards,
Morten

 

You must be logged in to post in the forum