Generic selectors
Exact matches only
Search in title
Search in content

UTM tracking for embedded forms

By using a custom JS script added to the form, you can fill form fields with UTM tracking parameters or other source values. Once submitted, you can use these values in other workflows involving external integrations or the form API.

To add a custom script to your online forms, go to the Advanced → Form tab. Then, select the option Add a JS script to your form and paste the script URL.

Advanced JS script

We have provided a few script examples below on how you can capture the UTM tracking parameters or other values.


Example Script 1

This script retrieves the src link of the form iframe containing search parameters from a UTM cookie. The values of these parameters are then extracted and prefilled in hidden form fields.

var queryString = window.location.search;

var urlParams = new URLSearchParams(queryString);
var is_campaign = urlParams.get('utm_campaign');
var is_source = urlParams.get('utm_source');
var is_medium = urlParams.get('utm_medium');

document.getElementById('id123-control11111111').value = is_source;
document.getElementById('id123-control2222222').value = is_medium;
document.getElementById('id123-control3333333').value = is_campaign;

(‘id123-control11111111’) represents the field control ID. Replace it with the actual ID of your form fields. You can find them by using the Inspect tool on your form.

Prefill form fields

Example Script 2

Another approach to capturing any value in a field involves the following syntax structure:

loader.getEngine().getDocument().getControlsList().find(function (control) { 
        return control.id === 0000000; // this targets a field based on its control id
    }
).setValue({value: 'new value'}); // this sets a value in a control

This script captures the parent window URL where the form is embedded and populates it in a hidden field on the form.

jQuery(document).ready(function() {
  setTimeout(function() {
    var parentFrame = window.location;
    var desiredControl = loader.getEngine().getDocument().getControlsList().find(function(control) { 
      return control.id === 0000000; // the desired control id
    });
    desiredControl.setValue({value: parentFrame.href});
    console.log('custom static resource loaded');
  }, 2000);
});

‘new value’ can be static or dynamic (returned by a function or retrieved after a third-party API call) as long as that value (‘new value‘) is a string.

Control.id represents again the ID of your form field. Replace “0000000” from our example with the ID of your field.

Leave a Reply

Your email address will not be published. Required fields are marked *

Frequently Asked Questions

Here is a list of the most frequently asked questions. For more FAQs, please browse through the FAQs page.

Is this service free?
Yes, we offer a free form builder service. Just sign up to the Basic plan and you are all set. This plan is forever free, but you are limited with a few features only, such as 5 forms per account, 100 submissions per month and you have to keep the backlink to 123FormBuilder on your forms. Check out our features matrix for more information.
How many forms can I create?
It depends on the service plan you are on. Higher service plans enable more features, including more web forms for your account. If you need more forms, go to the My Account section of your account and click the upgrade button. To create an unlimited number of forms, either upgrade to the Platinum service plan or higher. Consult our features matrix for more information.
How can I publish my forms?
You can publish your forms in many ways, by using their direct URL or HTML link, embedding them with a JavaScript code, Inline HTML or iFrame, using the Facebook app or the WordPress plugin, using popups, the Blogger code snippet and many more. Once you have created and customized your form, go to the Publish section to complete your work. Read more in our documentation.
How do I change my form design?
You can change the design of your form in the Themes section, which is located in your form settings. We offer a set of more than 30 predefined form themes for your forms, but you can also create your own from scratch. You can customize the submit button, the logo and more. To apply your own stylesheets, all forms come with a custom CSS editor.

Can't find what you're looking for?