---
title: Vercel Functions
slug: feature-experimentation/docs/vercel-functions
docTags: 
createdAt: 2026-08-05T20:39:54.000Z
---

[Vercel Functions](https://vercel.com/docs/functions) lets you deliver content to your site's visitors with speed and personalization. They are deployed globally by default on Vercel's Edge Network and enable you to move server-side logic to the edge, close to your visitor's origin.

You can use Optimizely Feature Experimentation flags at the edge with [NextJS](https://nextjs.org/) applications deployed on [Vercel](https://vercel.com/). This example uses the [JavaScript (Node) SDK](docId:8h-w2Cm_Q9CrRsVQa1_0y) inside [Vercel Functions](https://vercel.com/docs/functions) for you to start experimenting with your experiences at the Edge. For a general guide to getting started, see the [JavaScript (Node) SDK Quickstart](docId\:eH-UMm_rOn_GdGDGLV6__).

## Auto update with Optimizely webhooks and Vercel Functions

This example fetches the latest [datafile](docId:3LmHm4b3kTxKBuoR93KN8) from the Optimizely CDN during every build. [Deploy Hooks](https://vercel.com/docs/concepts/git/deploy-hooks) from Vercel can be used with [Optimizely webhooks](docId\:wEYkX0MfQPUA4vguDXf67) to keep the application up to date with the latest changes in the Optimizely project.

### Identity management

Optimizely's Feature Experimentation SDKs require [passing a user-provided identifier at runtime ](docId\:j0PPoMJWYbz04K76EKLUI) to drive experiment and feature flag decisions. This example generates a unique ID, stores it in a cookie, and reuses it to make the [decisions sticky](docId\:g0ydY7XzuuT9yqJzZgZuG). Alternatively, you can use an existing unique identifier available within your application and pass it in as the value for the `OPTIMIZELY_USER_ID` cookie.

### How bucketing works

See [How bucketing works](docId\:eH-UMm_rOn_GdGDGLV6__).

## Demo application

In the following example, you can create a demo application using Next.js. An example of this demo application is available on [Vercel's GitHub](https://feature-flag-optimizely.vercel.app/).

### Prerequisites

To run this example, you need:

- An Optimizely account. If you do not have an account, you can [sign up on Optimizely.com](https://www.optimizely.com/products/experiment/feature-experimentation/).
- Have [NPM](https://www.npmjs.com/) or [Yarn](https://yarnpkg.com/) installed locally.
- Before running locally, follow the [quickstart for the JavaScript SDK](docId\:eH-UMm_rOn_GdGDGLV6__) to create the following:
  - At least one [flag](docId\:eH-UMm_rOn_GdGDGLV6__).
  - Your [SDK key](docId\:eH-UMm_rOn_GdGDGLV6__).

### Create a Deploy Hook in Vercel

1. Go to the **Settings** tab in your Vercel deployment.
2. Look for the **Deploy Hooks** section and create a **Hook**.
3. This will generate a URL that can be used to trigger a rebuild of the deployment.

### Create a Webhook in Optimizely

1. Follow the instructions and configure a [webhook](docId\:fxs-QgSDWJiHQc0JQ1Y0C) in your Optimizely project.
2. Use the `Deploy Hook` URL generated from the previous section to create the webhook.

### How it works

When you make a change to your Optimizely project using the [UI](https://app.optimizely.com/v2), the webhook hits Vercel's `Deploy Hook` URL, which triggers a new build on Vercel. Every new build fetches the latest [datafile](docId:3LmHm4b3kTxKBuoR93KN8) and uses it in the application.

### Clone and deploy locally

1. Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [NPM](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:

```shell
npx create-next-app@latest
```

```shell
yarn create next-app
```

1. Generate the Next.js app using this example:

```shell
npx create-next-app --example https://github.com/vercel/examples/tree/main/edge-middleware/feature-flag-optimizely
```

```shell
yarn create-next-app --example https://github.com/vercel/examples/tree/main/edge-functions/feature-flag-optimizely feature-flag-optimizely
```

1. Create a local environment file from the example and add your SDK key:

```shell
cp .env.example .env.local
```

1. Run Next.js in development mode:

```scss
npm install
npm run dev
```

```shell
yarn  
yarn dev
```

1. Deploy your example app to the cloud using the Next.js documentation on [Deploying](https://nextjs.org/docs/deployment).

## Additional resources

- [Vercel example on GitHub](https://github.com/vercel/examples/tree/main/edge-middleware/feature-flag-optimizely)
- [Vercel Functions](https://vercel.com/docs/functions) documentation
