Custom JavaScript is available on all plans, including Free.
Start Here
Overview
The Custom JavaScript feature allows you to add JavaScript code to your forms. Use it for custom analytics beacons, loading third-party scripts, or any other functionality that requires JavaScript.Why This Matters
Sometimes you need tracking or functionality that’s specific to your stack. Custom JavaScript lets you add code to your forms—send conversion beacons to your own endpoint, or load third-party scripts inside the sandbox—without touching OrbitForms’ built-in tracking.Use Cases
Analytics Beacons
Send custom events to your own tracking endpoint
Third-Party Scripts
Load external scripts inside the sandbox
Custom Logic
Run code when the form loads
Built-in Tracking
Use the Meta Pixel, GA4, GTM, and Cometly fields for standard events
Setup Guide
1
Open your form settings
Go to your form in the dashboard and click on the “Integrate” tab.
Forms → Select form → Integrate tab2
Find Custom JavaScript
Scroll down to the Custom JavaScript section under Tracking & Analytics.
Scroll to "Custom JavaScript" section3
Enter your code
Paste your JavaScript code into the text area. The code will execute when the form loads.
Paste code into text area4
Save your changes
Click Save. Your custom JavaScript will now run on your form.
Click "Save" buttonCode Examples
Form Slug Variable
Your code has access to aformSlug variable containing the current form’s slug:
Send a Beacon to Your Own Endpoint
Send form-load events to your own tracking endpoint:Debug Logging
Log when the form loads (for testing):Load Third-Party Script
Dynamically load an external script (it loads inside the sandbox):What the Sandbox Blocks
To protect your respondents, certain code is rejected before it ever runs. The following patterns are blocked:eval(),new Function(),setTimeout('...')/setInterval('...')with string argumentsimportstatements and dynamicimport()<script>tag injection,innerHTML/outerHTMLassignment,document.write()- Inline event handlers (
onclick=, etc.) andjavascript:/vbscript:URLs - Accessing
document.cookieorglobalThis - Redirecting the page (
location.href = ...,window.location = ...) atob(),String.fromCharCode, Web Workers,URL.createObjectURL- Code longer than 50 KB
Important Notes
When code runs — Custom JavaScript executes once when the form page loads, inside the sandbox. If you need to run code on form submission,
consider using webhooks or workflows instead.
Troubleshooting
Code not running?
Code not running?
Open browser developer tools (F12) and check the Console tab for errors. Syntax errors will
prevent your code from executing.
Third-party function not defined?
Third-party function not defined?
Globals from other scripts on the page (like
fbq or gtag) are not available inside the sandbox, even
if the corresponding integration is enabled. To fire Meta Pixel or GA4 events, use the built-in integration
fields on the same Integrate tab instead of Custom JavaScript.Debugging tips
Debugging tips
Use
console.log() statements
to verify your code is running and inspect variable values in the browser console.Best Practices
- Always test your code on a test form before applying to production
- Use try/catch blocks to prevent errors from breaking your form
- Check if third-party functions exist before calling them
- Keep your code minimal - complex scripts may slow down form loading
- Document your code with comments for future reference