Rich-text Reply
Highlighted

Set Cookie Expiration API

clement_cy_au 2w ago

Set Cookie Expiration API

In the developer doc, it quoted:

" You must call "setCookieExpiration" prior to loading the Optimizely snippet.". Just wonder if the window.optimizely is not yet defined, how the api will work? 

 

BTW, I have tried to use 

window['optimizely'] = window['optimizely'] || [];

window['optimizely'].push(["setCookieExpiration", 365]);

to set in the chrome console where our site has optimizelyEndUserId cookie. But the expiration days of the cookie does not changed.

Re: Set Cookie Expiration API

I am in OptimizelyX, the code which I tried is
window["optimizely"].push({
"type": "cookieExpiration",
"cookieExpirationDays": 365
});
instead.

Re: Set Cookie Expiration API

To do as described here:
https://developers.optimizely.com/x/solutions/javascript/reference/#function_cookieexpiration

 

You will need to declare optimizely in your code and push the attributes to it before the snippet loads.

I do not do this myself, but your webpage will contain code that looks something like the following.

 

<script>
window.optimizely = window.optimizely || [];
window.optimizely.push({
	"type": "cookieExpiration",
	"cookieExpirationDays": 365
});
</script>
<script src="//cdn.optimizely.com/js/123456789.js"></script>

As this is not something I have had cause to do yet, please let us know if this works

--Jason Dahlin
Analytics and Testing Guru Smiley Happy


Experimentation Hero

Re: Set Cookie Expiration API

Tks. Will get our IT and see whether they can do this.