Extend cookie lifetime
By default, whenever the snippet activates, it resaves any existing Optimizely Web Experimentation visitor ID cookievisitor ID cookie onto the currently configured `cookieDomain`cookieDomain and with the currently configured `cookieExpiration`cookieExpiration.
For example, if you use the Cookie Expiration APICookie Expiration API to specify a lifetime of 365 days, you can use extend cookie lifetime to disable the automatic lifetime extension, ensuring the cookie's expiration does not get refreshed on each snippet activation. As a result, the cookie would expire 365 days after it was created.
Call this API with isEnabled: false to prevent Web Experimentation from automatically extending the expiration period of the visitor ID cookie.
- A visitor ID cookie whose value does not change during snippet activation (for example, most returning visitors') retain the original domain and expiration date that was specified when the cookie was set (during a prior snippet activation).
- A visitor ID cookie that is new (for example, a new visitor's) or whose value is modified (due to having been synced from another origin through `waitForOriginSync`waitForOriginSync, for example), are set as normal, using the currently-configured cookieDomain and cookieExpiration.
You must call this prior to each snippet initialization to suppress the cookie-extending behavior.
Syntax
window["optimizely"].push(extendCookieLifetime);Parameters
Parameter and Type | Child Attribute | Description |
|---|---|---|
extendCookieLifetime ExtendCookieLifetimeObject | N/A | An object with the type field set to extendCookieLifetime. The other fields are the function arguments. Required. |
type string | Child attribute of type ExtendCookieLifetimeObject. | The argument indicating that you are using the extendCookieLifetime function. Required. |
isEnabled Boolean | Child attribute of type ExtendCookieLifetimeObject. | Set to false to prevent Web Experimentation from extending the lifetime of existing cookies when the snippet activates. |
Example call
window["optimizely"].push({
"type": "extendCookieLifetime",
"isEnabled": false
});