Track which dynamic page a new Wix Form was submitted from

Sometimes, you want to know which page a user submitted a form on - which can be especially useful for dynamic pages like a car listing or product detail. This tutorial walks you through how to add that data to your form submission.


Setup

Step 1: Add a Hidden Field

  1. Create a form with a hidden field, for example “Page Submitted”
  2. Give it a Field key (Found under the advanced tab). In this case page_submitted

This field will still show in the form composer, but not on your live site.


Step 2: Add This Code

Paste the following code into your page’s code panel:

$w.onReady(function () {
    $w("#dynamicDataset").onReady(() => {
        let itemObj = $w("#dynamicDataset").getCurrentItem();

        let currentPage = itemObj["link-cars-make"];

        $w("#myForm").setFieldValues({
            page_submitted: currentPage
        });
    });
});

Update the element IDs to work with the elements on your page


How It Works

  • #dynamicDataset is your dynamic pages dataset.
  • getCurrentItem() pulls the content of the current item
  • We extract a relevant value (in this case, the dynamic URL slug - link-cars-make)
  • Then we populate that into the form using setFieldValues()

This value will now be stored in your form submission.


Customize It

This setup is flexible! You can:

  • Use any field from the dataset (e.g. make, model, price, etc.)
  • Add multiple hidden fields
  • Concatenate values into a single field for context
  • Use information from other sources, such as UTM parameters

Examples

Concatenating multiple fields

let details = `${itemObj.make} ${itemObj.model}`;

$w("#myForm").setFieldValues({
  page_submitted: details
});

Saving UTM parameters

let utmParams = await wixSiteLocation.location.query()

$w("#myForm").setFieldValues({
  utm_source: utmParams.utm_source
})

That’s It!

You now have a form that tracks which item/page it was submitted from.

This is great for:

  • Better submissions context
  • Segmenting leads
  • Triggering automations based on dynamic page info

Happy building!

3 Likes