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
- Navigate to Code Snippets > Create Snippet
- 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:
- Open the variant editor
- Click the code icon (
</>
) in the JavaScript panel - Browse or search for your desired snippet
- Select the snippet to add it to your variant’s JavaScript code
- Modify the inserted code as needed for your specific use case
- 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