Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function criteo_population(){
- // Settings
- var cookiename_cto = "cto"; //Name of the cookie
- var splitRate_cto = 50; //Split rate between the 2 partners
- // Check if cookie already exits
- var population_cto = '';
- 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(cookiename_cto + "=") == 0){
- population_cto = c.substring(cookiename_cto.length, c.length);
- population_cto = population_cto.split('=')[1]; // Returns A or B
- }
- }
- // Populate the cookie, as there is no pool present in the cookie
- if(population_cto == '' || population_cto == undefined){ console.log("we generated again a population value");
- population_cto = (((Math.random() * 100 | 0) + 1) <= splitRate_cto) ? "A" : "B";
- }
- var date = new Date();
- date.setTime(date.getTime()+(365*24*60*60*1000));
- var expires = "; expires="+date.toGMTString();
- var default_path = "; path=/"; // really important so the var will be reachable from any page of the website
- document.cookie = cookiename_cto+"="+population_cto+expires+default_path;
- return population_cto; // Returns A or B
- }
Advertisement
Add Comment
Please, Sign In to add comment