You are here

userCookieDice100 - Cookie Drop

Container Reference: 
Tag Type: 
Custom HTML
Tag Description: 
Drops by default a 10 day Dice Cookie on the user
	<script>
// conditional variables :
var randomNumber = {{randomNumber0-99}};
var userCookieDice100 = {{userCookieDice100}};

// Function for that Cookie creation
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// very simple behavior :
// I don't have the cookie, I drop it
// I have the cookie, I do nothing
// And I store the value of the randomNumber I get in that cookie

// First Page I drop the Cookie.
// Second Page the cookieDice triggers are operational :)

if ( userCookieDice100 == undefined ) {

	// I don't have a cookie for that user yet
	// Cookie Name
	var cookieName = "userCookieDice100";
	// Cookie Value
	var cookieValue = randomNumber;
	// Cookie length in days : 10 days is largely enough
	var cookieDays = "10";
	// I drop the cookie
	createCookie(cookieName, cookieValue, cookieDays);
} // end of IF Statement

</script>