The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.
Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
API Reference

Extend cookie lifetime

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

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 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, 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 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 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
});