Avoiding Optimizely impressions to save time & run better tests
Tags: optimizely, splittesting, abtesting, experimentation
Published: 2020-07-13 08:19:13

I recently posted some methods for [setting up experiments without Optimizely impression tracking](https://mintmetrics.io/experiments/bypass-optimizely-impressions-save-money/). For all the juicy details, you may like to read that post, but I'll share the gist of it below.

## Disclaimers

1. If you're using this specifically to avoid impression counting, then please be aware this can violate Optimizely's terms of service and/or your contract.
2. If you rely on Optimizely's reports for deciding winning variants, then this also isn't for you.
3. Triggers run on all pages, so be sure you know what you're doing before you publish any JavaScript.

## How it works

With that out of the way, here's how we typically setup zero-impression tests in Optimizely:

### 1. Add an open source split testing library to your shared code

Got to your Optimizely account and open "Settings" and then "JavaScript".

Next, paste in an open source split testing tool (in this example, we'll be using [Mojito](https://mojito.mx/), because it's a tool we maintain and are familiar with). But any open source split testing library will do.

![](https://mintmetrics.io/wp-content/uploads/2020/07/mojito_in_optimizely-1.png)

### 2. Create an A/B split test

From the "Experiments" tab, create a new A/B split test. Give it a name and URL for your preview links (anything will do here, because you won't be using Optimizely for the tracking)

![](https://mintmetrics.io/wp-content/uploads/2020/07/optimizely_create_experiment-1.png)

### 3. Set your page targeting to a "callback trigger"

Under "Page targeting", you'll need to set your trigger to "Use a callback function".

![](https://mintmetrics.io/wp-content/uploads/2020/07/select_optimizely_trigger_type-1.png)

### 4. Paste your split test code all within the trigger

Now it's time to add you other split test code. Following from the example above, we'll use a [Mojito A/B test](https://mojito.mx/docs/js-delivery-setup-js).

If your experiment code looks like this:

```
Mojito.addTest({
    "state": "live",
    "sampleRate": 0.5,
    "id": "ex1",
    "name": "ex1 scaffold",
    "recipes": {
        "0": {
            "name": "Control"
        },
        "1": {
            "name": "Treatment",
            "js": function treatment(test) {
                console.log('Test id: ' + test.options.id, ', name: ' + test.options.name, ', chosen recipe: ' + test.chosenRecipe.id);
            }
        }
    },
    "trigger": function trigger(test) {
        Mojito.utils.domReady(test.activate);
    }
});
```

Then you simply need to wrap it inside the trigger callback function, like so:

```
function trigger (activate, options) {
    Mojito.addTest({
        "state": "live",
        "sampleRate": 0.5,
        "id": "ex1",
        "name": "ex1 scaffold",
        "recipes": {
            "0": {
                "name": "Control"
            },
            "1": {
                "name": "Treatment",
                "js": function treatment(test) {
                    console.log('Test id: ' + test.options.id, ', name: ' + test.options.name, ', chosen recipe: ' + test.chosenRecipe.id);
                }
            }
        },
        "trigger": function trigger(test) {
            Mojito.utils.domReady(test.activate);
        }
    });
}
```

Once that's done, you can save it. Now you're right to launch your zero-impressions experiment.

### 5. Starting/Stopping your experiment

As with any Optimizely experiment, you can start it or stop it as you normally would.

![](https://mintmetrics.io/wp-content/uploads/2020/07/pause_optimizely_experiment.png)


## That's it in a nutshell

How do others implement experiments in Optimizely?