lundi 30 mars 2015

facebook client (app) and cookies (new cookie created per url instead of one per domain)

I have a site where if cookie is set it should not display an AD, cookie is valid for 24 hours. Everything works fine on browsers, mobile browsers and so on, but if a user open an url of my site from Facebook App (client) on iOS (can't probe it on Android yet) the cookie works but is generated per every single url, so the ad is shown first time every single page is loaded. It should be only every first time the site is loaded in a 24 hours period.


Again this only happens on Facebook mobile app (iOS as far as I know). Here my code to generate the cookie.



// Cookie functions

function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
}

function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/; domain=.site.com;";
}

function checkCookie(cname) {
var cookie=getCookie(cname);
if (cookie) {
return true;
}else{
return false;
}
}


So what could be the cause of this behavior?


Aucun commentaire:

Enregistrer un commentaire