# Snippet settings

URL: https://docs.ablyft.com/developers/installation/snippet-settings/

> Settings that control how the ABlyft snippet is built and delivered, and related project settings.



The snippet settings control how your project's snippet is built and delivered to your visitors.
You find them in your project under **Settings → Snippet**.

The page has two columns. On the left are the settings, on the right is the output: your snippet code, its details and
the sub-snippets of your [environments](https://docs.ablyft.com/developers/installation/environments/).

## Overview

| Setting                                         | Default           | What it does                                                                  |
| ----------------------------------------------- | ----------------- | ----------------------------------------------------------------------------- |
| [Cache expiration (ttl)](#cache-expiration-ttl) | 1 minute          | How long the snippet may be cached before it is fetched again                 |
| [Anti-flicker mode](#anti-flicker-mode)         | Use built-in mode | Prevents visitors from seeing the original page before a variation is applied |
| [Minify JavaScript](#minify-javascript)         | On                | Reduces the size of your custom code                                          |
| [Data layer watching](#data-layer-watching)     | Intercept         | How the snippet detects new data layer events                                 |
| [Include jQuery](#include-jquery)               | –                 | Deprecated                                                                    |

> The settings in **General Settings** are marked as deprecated in the app. Some of them, such as the cache expiration,
> are managed by ABlyft support and cannot be changed in the form.

## Cache expiration (ttl)

Defines for how long the snippet counts as fresh. During this time, a visitor's browser may use its cached copy instead of
fetching the snippet again.

| Option          |                                           |
| --------------- | ----------------------------------------- |
| Disable Caching | The snippet is always loaded from the CDN |
| **1 Minute**    | Recommended, default                      |
| 2 Minutes       |                                           |
| 5 Minutes       |                                           |

This setting is read-only in the app. If you want to change it, contact ABlyft support.

> **Changes are not instant:** After you publish a change, visitors whose browser has a cached snippet receive the new version only after the cache
> expiration has passed. With the default of one minute this takes at most about a minute.

While [debug mode](https://docs.ablyft.com/developers/debugging/preview-and-live-log/#debug-mode) is on, caching is turned off.

## Anti-flicker mode

Flicker means that visitors briefly see the original page before a variation is applied. Choose how you want to prevent it:

* **Use built-in mode** (default): The snippet hides the page (`visibility: hidden` on the `<html>` element) right after it
  has loaded and shows it again as soon as all experiments have been applied, or after 2 seconds at the latest,
  whichever comes first.
* **Use your own custom mode:** The snippet does not hide the page. Use this if you handle flicker yourself, for example
  with your own script in the `<head>`.

For the best result, load the snippet synchronously and as early as possible in the `<head>`, see
[Embed the snippet](https://docs.ablyft.com/developers/installation/snippet/#synchronous-or-asynchronous).

## Minify JavaScript

When enabled (default), ABlyft minifies the JavaScript that you added to the project: project code, helper code, and the
code of experiments and variations. This reduces the file size of your snippet.

Check the effect in **Snippet size (before gzip)** on the right side of the page.

## Data layer watching

Defines how the snippet detects new entries in your data layer. It applies to the
[`dataLayer Event` audience rules](https://docs.ablyft.com/developers/tracking-and-events/datalayer-events/#use-data-layer-events-in-audiences) and to
[`watchDataLayerEntry()`](https://docs.ablyft.com/developers/reference/javascript-api/tools/#watchdatalayerentry).

| Method                  | Behavior                                                                                              |
| ----------------------- | ----------------------------------------------------------------------------------------------------- |
| **Intercept** (default) | The snippet wraps `dataLayer.push` and reacts immediately to every new entry                          |
| **Polling**             | The snippet checks the data layer every 500 ms. Choose this if other scripts replace `dataLayer.push` |

## Include jQuery

The jQuery settings (**Include jQuery**) are deprecated and are not described further.

## Snippet output

The right side of the page shows:

* **Implementation (base snippet):** the code to place on your site. Click it to copy. See [Embed the snippet](https://docs.ablyft.com/developers/installation/snippet/).
* **Project/Snippet ID** and **Snippet version** (the snippet version is managed by ABlyft)
* **Snippet revision**, **Last published** and **Snippet size (before gzip)**, see
  [Check the state of your snippet](https://docs.ablyft.com/developers/installation/publishing/#check-the-state-of-your-snippet)
* **Sub-Snippets:** one snippet for each environment that has **Create a sub-snippet** enabled, see
  [Sub-snippets](https://docs.ablyft.com/developers/installation/environments/#sub-snippets)

## Publishing

ABlyft publishes your snippet automatically whenever something relevant changes, including the settings on this page.
See [Publishing](https://docs.ablyft.com/developers/installation/publishing/). The new version reaches your visitors once the
[cache expiration](#cache-expiration-ttl) has passed.

## Related project settings

Further settings with an effect on the snippet are located elsewhere in the project settings.

| Setting                                                              | Where                                                      | Effect                                                                                                                                  |
| -------------------------------------------------------------------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| [Debug mode](https://docs.ablyft.com/developers/debugging/preview-and-live-log/#debug-mode) | Settings → Project Settings                                | Console output, caching off                                                                                                             |
| Use SPA features                                                     | Settings → Project Settings → Project Activations Settings | Enables Reset-JS and page triggers for single-page apps, see [SPA navigation](https://docs.ablyft.com/developers/application-integration/spa-navigation/)      |
| Run only on `ablyft.reInit()`                                        | Same section                                               | The snippet only starts when your code calls [`ablyft.reInit()`](https://docs.ablyft.com/developers/reference/javascript-api/#ablyftreinit)                    |
| Allow in iFrames                                                     | Same section                                               | Lets the snippet run inside iFrames                                                                                                     |
| Automatically clean up bucketing                                     | Same section                                               | Removes experiments that were archived within the last 6 months from the visitor's stored bucketing, so that it does not grow too large |
| [Publication webhooks](#publication-webhooks)                        | Settings → Project Settings                                | Notifies your systems after each publication                                                                                            |
| External tracking domains                                            | Settings → Project Settings                                | Passes the variation assignment to another domain, see below                                                                            |
| Prerequisites                                                        | Settings → Prerequisites                                   | Rules for showing variations and for starting tracking, see [Consent manager](https://docs.ablyft.com/developers/consent-and-security/consent-manager/)        |
| Data Protection & Compliance                                         | Settings → Data Protection & Compliance                    | Browser storage, Do Not Track and cookie settings, see [Storage & privacy](https://docs.ablyft.com/developers/consent-and-security/storage-and-privacy/)       |

### Publication webhooks

Publication webhooks let ABlyft notify your systems after every publication, for example to back up or version the
snippet, to keep a local copy on your own server, or to send a team notification.

After each publication, ABlyft sends an HTTP `POST` request (form data) to every URL that you configured. The request
contains these fields:

| Field              | Description                                                                 |
| ------------------ | --------------------------------------------------------------------------- |
| `team_id`          | ID of your team                                                             |
| `project_id`       | ID of the project                                                           |
| `snippet_revision` | Revision number of the published snippet                                    |
| `snippet_script`   | The complete JavaScript snippet. Only included if **Include JS** is enabled |

Your endpoint should answer within 3 seconds. The `User-Agent` of the request is `ABlyft Publication Webhook`.

To receive and store the snippet on your own server, see the receiver example in
[Self-hosting the snippet](https://docs.ablyft.com/developers/installation/snippet/#self-hosting-the-snippet).

You can trigger the webhooks without changing anything, see
[Publish manually: Test webhooks](https://docs.ablyft.com/developers/installation/publishing/#publish-manually-test-webhooks).

### External tracking domains

If your tracking happens on another domain (not just a subdomain), enter it under **External tracking domains**.
ABlyft then passes the variation assignment to that domain through a URL parameter. The name of this parameter is
[`ablyft_set_bucketing`](https://docs.ablyft.com/developers/reference/url-parameters/#ablyft_set_bucketing) by default and can be changed in
**Bucketing handover query parameter**.

### Advanced settings

The fields **custom snippet**, **tracker URL** and **asset URL** (under Data Protection & Compliance → Custom Settings)
are read-only and can only be changed by ABlyft support.

