Inject JavaScript or CSS into a visual variation — before the visual edits run.
You can add custom JavaScript and/or CSS to any visual editor variation. Code runs first, before any visual edits are applied — making this a useful way to prep the DOM, modify elements, or introduce logic that complements your visual changes.
How to add custom code
Before you get started
Review the code editor guide to learn about writing code in Optimize. Need jQuery? Enabled it as a plugin.
In the visual editor:
- Click the Changes tab in the Changes panel
- Click the Options icon > Add custom code
- Set a Selector and/or Precondition — at least one is required per optimization for coded variations
- Enter JavaScript or CSS in the associated code fields at the bottom
- Click Run code to preview your code
- Click Save > Done
- Preview your variation before launching it