Extend cooked lifetime

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

Syntax

window["optimizely"].push(extendCookieLifetime);

Parameters

Parameter and TypeChild AttributeDescription
extendCookieLifetime
ExtendCookieLifetimeObject
N/AAn object with the type field set to extendCookieLifetime. The other fields are the function arguments. Required.
type
string
Child attribute of type ExtendCookieLifetimeObjectThe argument indicating that youre using the extendCookieLifetime function. Required.
isEnabled
Boolean
Child attribute of type ExtendCookieLifetimeObjectSet to false to prevent Optimizely Web Experimentation 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 Web Experimentation 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 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 (e.g., most returning visitors') will 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 (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.