---
title: Extend cookie lifetime
slug: web-experimentation/api/q29C-extend-cookie-lifetime
docTags: 
createdAt: 2026-08-05T20:56:13.000Z
---

By default, whenever the snippet activates, it resaves any existing Optimizely Web Experimentation [visitor ID cookie](docId\:WDI76OY7DoWjpdq_kjv56) onto the currently configured [\`cookieDomain\`](docId\:DA2miUOGZ1KGHVoH6zit_) and with the currently configured [\`cookieExpiration\`](docId\:bCslTXNyu11D_yuBScS57).

For example, if you use the [Cookie Expiration API](docId\:bCslTXNyu11D_yuBScS57) 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\`](docId\:clNxioUhA39QFL4POJdLM), 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

```javascript
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

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