Custom JavaScript

Free

Add custom tracking scripts, events, or any code to your forms

πŸ‘‹

Start Here

Overview

The Custom JavaScript feature allows you to add any JavaScript code to your forms. Use it for custom analytics events, third-party integrations, A/B testing 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 gives you full control to add any code to your formsβ€”fire custom conversion events, load third-party widgets, or implement advanced tracking that built-in integrations don't cover.

Use Cases

Custom Events

Fire custom Meta Pixel, GA4, or other tracking events

Third-Party Scripts

Add chat widgets, heatmaps, or A/B testing

Custom Logic

Run code when the form loads or on user actions

Advanced Tracking

Implement custom conversion tracking

Setup Guide

1

Open your form settings

Go to your form in the dashboard and click on the "Integrate" tab.

Forms β†’ Select form β†’ Integrate tab
2

Find Custom JavaScript

Scroll down to the Custom JavaScript section under Tracking & Analytics.

Scroll to "Custom JavaScript" section
3

Enter your code

Paste your JavaScript code into the text area. The code will execute when the form loads.

Paste code into text area
4

Save your changes

Click Save. Your custom JavaScript will now run on your form.

Click "Save" button

Code Examples

Meta Pixel Custom Event

Fire a Lead event with custom parameters

// Track a Lead event with value
if (typeof fbq !== 'undefined') {
  fbq('track', 'Lead', {
    content_name: 'Contact Form',
    value: 50.00,
    currency: 'USD'
  });
}

Google Analytics Custom Event

Send a custom event to GA4

// Track a custom event
if (typeof gtag !== 'undefined') {
  gtag('event', 'form_interaction', {
    form_name: 'Contact Form',
    form_location: 'homepage'
  });
}

Debug Logging

Log when the form loads (for testing)

// Debug: Log form load
console.log('Orbit form loaded at:', new Date().toISOString());
console.log('Page URL:', window.location.href);

Load Third-Party Script

Dynamically load an external script

// Load a third-party script
(function() {
  var script = document.createElement('script');
  script.src = 'https://example.com/widget.js';
  script.async = true;
  document.head.appendChild(script);
})();

Important Notes

Avoid duplicate tracking

If you're adding Meta Pixel or GA4 via Custom JavaScript, don't also enable them in the built-in integration fields above. This will cause duplicate events.

When code runs

Custom JavaScript executes when the form page loads. If you need to run code on form submission, consider using webhooks or workflows instead.

Security

Only add JavaScript from sources you trust. Malicious code could affect your form's functionality or compromise user data.

Troubleshooting

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?

If you're calling functions like fbq or gtag, make sure the corresponding integration (Meta Pixel, GA4) is also enabled, or load the script first.

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

Did this answer your question?

Ready to Add Custom Tracking?

Add custom JavaScript to your forms and unlock unlimited tracking possibilities.

Get Started
Custom JavaScript Integration | Orbit AI | Orbit AI