Code Snippets

Code snippets allow you to create and reuse JavaScript code across multiple variants and experiments. This feature helps maintain consistency and saves time when implementing common functionality.

Creating a Snippet

  1. Navigate to Code Snippets > Create Snippet
  2. In the modal that appears:
    • Enter a descriptive name for your snippet
    • Use the code editor to write your JavaScript code
    • Click “Save” to store your snippet

Using Snippets in Variants

To use a saved snippet in your variant:

  1. Open the variant editor
  2. Click the code icon (</>) in the JavaScript panel
  3. Browse or search for your desired snippet
  4. Select the snippet to add it to your variant’s JavaScript code
  5. Modify the inserted code as needed for your specific use case
  6. Save your variant

Best Practices

  • Give snippets clear, descriptive names that indicate their functionality
  • Keep snippets focused on a single purpose
  • Comment your code to explain complex logic
  • Test snippets thoroughly before reusing them across variants

Managing Snippets

You can view and manage all your saved snippets through the Code Snippets page, where you can:

  • Edit existing snippets
  • Delete unused snippets
  • Organize snippets for better accessibility