The Full Stack Developer Guide Developer Hub

Welcome to the Full Stack Developer Guide developer hub. You'll find comprehensive guides and documentation to help you start working with the Full Stack Developer Guide as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Extend cookie lifetime

Disable or enable the automatic lifetime extension of the visitor ID cookie.

Syntax

window["optimizely"].push(extendCookieLifetime);
Parameters
Parameter and Type
Child Attribute
Description

extendCookieLifetime
ExtendCookieLifetimeObject

-

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're using the extendCookieLifetime function. Required.

isEnabled
Boolean

Child attribute of type ExtendCookieLifetimeObject

Set to false to prevent Optimizely from extending the lifetime of existing cookies when the snippet activates.

Example Call

window["optimizely"].push({
  "type": "extendCookieLifetime",
  "isEnabled": false
});

Description

By default, whenever the snippet activates, it resaves any existing Optimizely visitor ID cookie onto the currently configured cookieDomain and with the currently configured cookieExpiration.

For example, if you use the Cookie 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 Optimizely from automatically extending the expiration period of the visitor ID cookie.

  • A visitor ID cookie whose value does not change during snippet activation (e.g., most returning visitors') will retain the original domain and expiration date that were specified when the cookie was set (during a prior snippet activation).
  • A visitor ID cookie that is new (e.g., a new visitor's) or whose value is modified (due to having been synchronized from another origin via waitForOriginSync, for example), will be 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.

Updated 11 months ago


Extend cookie lifetime


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.