Hey everyone,
I'm developing an enterprise site for a large corporate customer and They wanted to implement a website tour for first time users based on a cookie. So with the new law I wanted to make sure I did this correctly and I was able to come up with something that worked pretty well. I'll share here is case anyone needs the same thing.
first I created this and called it cookie.js and placed it in my skin folder
----------------------------------------------------------------------------------------------------------------
/*Creates and checks for cookie and is EU Compliant*/
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return (y);
}
}
}
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
function checkCookie() {
var username = getCookie("username");
if (username != null && username != "") {
window.location = "/AboutUs.aspx#_";
}
else {
username = prompt("Cookies are being used on this site. Further browsing requires consent. Please enter your name to continue.", "");
if (username != null && username != "") {
setCookie("username", username, 365);
window.location = "/AboutUs.aspx#jTour/themes/0/0";
}
}
}
----------------------------------------------------------------------------------------------------------------
This is the redirect link to the tour that loads after they enter their name into the EU compliant cookie acknowledgement Pop up.
window.location = "/AboutUs.aspx#jTour/themes/0/0";
if they have already entered there name and been to the site once before then they need to be redirected to the home page.... but that's where I put the following body onload event and js include which is in the home.ascx file. I had to use an inner.ascx without the cooke.js and body onload event on every other page of the site. very important otherwise the script pushes you back to the home page every time you click on anything.
<!-- .....delete the comment lines when putting this into your ascx file.
<body onload="checkCookie()"></body>
<dnn:DnnJsInclude ID="DnnJsInclude9" runat="server" FilePath="/js/cookie.js" PathNameAlias="SkinPath" />
--> .....delete the comment lines when putting this into your ascx file.
this takes them back to the home page if they have already been once before but it doesn't load the script again because of the #_
window.location = "/AboutUs.aspx#_";
You can edit your popup text in this line.
username = prompt("Cookies are being used on this site. Further browsing requires consent. Please enter your name to continue.", "");
It's set to keep the cookie for a year unless the end user deletes it. I'll save how I incorporated jTour into DNN for another post. but this should solve the EU worry if you really had too obtain consent.
Enjoy,
Mario