This repository contains examples of custom code which can be used within Optimizely. The examples are organized into different categories.
Within an page definition you can use a custom page activation trigger to delay the activation of a page (and thus the experiments attached to it). For example, instead of activating the page when the website loads, you could activate the experiment after an user interaction.
- Activate page when user click search button
- Activate page when user scrolls down to a specific element
Instead of matching a page based on a URL pattern or on a CSS selector, it's also possible to write a custom JavaScript condition.
In your Optimizely project settings, you can add custom JavaScript code that will be run every time the Optimizely snippet is loaded. This can be used to configure custom attributes. Note that the optimizely
object won't be initialized yet, so make sure to initialize this variable.
- Set a custom user attribute based on a cookie
- Set a custom user attribute based on an event in the GTM
dataLayer
object - Set a custom user attribute based on the domain name
- Set a custom user attribute based on the query string
In an experiment, you can add custom JavaScript code that will be run for every variation. Note that this includes the original variation. This can be used to set up custom event tracking consistently across all variations.
Lastly, in a variation, you can add custom JavaScript code to create functional changes instead of just visual changes.