pierrebalian of Rocket55 Web Team
3/29/2017 - 12:39 AM

Set a Cookie

Set a Cookie

/**
 * Set a cookie.
 * 
 * Example Usage :
 * 		setCookie(
 * 			'gclidCookie',
 * 				encodeURI(
 * 					JSON.stringify(
 * 						encodeParamGclid
 * 					)
 * 				),
 * 			1
 * 		);
 *
 * @param {string} cookieName The name of the cookie.
 * @param {string} cookieValue The value for the cookie.
 * @param {number} cookieExpiration The expiration value for the cookie in days.
 */
function setCookie( cookieName, cookieValue, cookieExpiration ) {
	
	/**
	 * @type {Date}
	 */
	var d;
	 
	/**
	 * @type {string}
	 */
	var expires;
	 
	d = new Date();
	 
	d.setTime(
		d.getTime() + (
	 		cookieExpiration * 24 * 60 * 60 * 1000
	 	)
	);
	 
	expires = 'expires=' + d.toUTCString();
	 
	document.cookie = cookieName + '=' + cookieValue + '; ' + expires + '; path=/';	
	
}