How do I pass UTM parameters from my URL to an embedded form on my wix site?

Hi there, I’m looking for assistance in passing UTM parameters from my URL to an embedded form on my wix site. From what I can tell so far, the main issue is that when you embed a code or a website into Wix it creates a sort of nested iframe. So the UTM codes that would be available to the parent iframe aren’t available to my embedded form. I have tried to create a script that will add the UTM to any iframe src tags it finds however because they’re sandboxed it doesn’t look like the script will load properly.

Here is the script I’ve used and having tested it in the head and body-bottom section, neither of them make a difference.

Do you have any suggestions or ideas on how I might find a workaround?

I would also love a solution to this. I’ve gone back to using Wix forms then Zapier to send the info into a CRM.

Hi!

did you guys figure it out? i’m dealing with the same issue.

Thanks!
Naama

Hi! use this!
import wixLocation from ‘wix-location’;

$w.onReady(function () {
const { utm_source, utm_medium, utm_campaign, utm_content, utm_term } = wixLocation.query;
$w(“#input-utmsource”).value = ${utm_source};
$w(“#input-utmsource”).hide();

$w(“#input-utmmedium”).value = ${utm_medium};
$w(“#input-utmmedium”).hide();

$w(“#input-utmcampaign”).value = ${utm_campaign};
$w(“#input-utmcampaign”).hide();

$w(“#input-utmcontent”).value = ${utm_content};
$w(“#input-utmcontent”).hide();

$w(“#input-utmterm”).value = ${utm_term};
$w(“#input-utmterm”).hide();

});

“input” is each form field.

Hi there, I went through the same scenario. This is how I’m able to capture UTM parameters from the landing page, store them in session, and autofill the hidden fields in a lightbox.

Note: My code can be optimised further. gclid, wbraid, gbraid, and msclkid can be saved into one Gclid field instead of having a hidden field for each one.

Step 1: Create a custom form using this article. There will be a Collection, a dataset of the collection on the page where the form is put, and a custom form to collect leads to save them to the collection.

Step 2: Collect UTM parameters from the landing page and store them in the session.

import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;
import { session } from ‘wix-storage’;
import * as wixSiteWindow from ‘@wix/site-window’;

$w.onReady(function () {
// Use standard browser API to read the full URL
const queryString = wixLocation.query;
const urlParams = new URLSearchParams(queryString);

// Store UTM and ad tracking parameters
session.setItem('utm_campaign', urlParams.get('utm_campaign') || '');
session.setItem('gclid', urlParams.get('gclid') || '');
session.setItem('adset', urlParams.get('adset') || '');
session.setItem('adid', urlParams.get('adid') || '');

});

Step 3: Put the collected parameters into the hidden fields of the form as soon as the form loads.

import {session} from ‘wix-storage’;

$w.onReady(function () {
// Set primary hidden fields
$w(‘#input3’).value = session.getItem(‘utm_campaign’) || ‘’;
$w(‘#input4’).value = session.getItem(‘gclid’) || ‘’;
$w(‘#input5’).value = session.getItem(‘adset’) || ‘’;
$w(‘#input6’).value = session.getItem(‘adid’) || ‘’;

// Set extra hidden fields for tracking alternatives
$w('#input7').value = session.getItem('wbraid') || '';
$w('#input8').value = session.getItem('gbraid') || '';
$w('#input9').value = session.getItem('msclkid') || '';

// Ensure values are set before form submission

// $w(‘#dataset3’).onBeforeSave(() => {
// $w(‘#input3’).value = session.getItem(‘utm_campaign’) || ‘’;

});
import {session} from ‘wix-storage’;

$w.onReady(function () {
// Set primary hidden fields
$w(‘#input3’).value = session.getItem(‘utm_campaign’) || ‘’;
$w(‘#input4’).value = session.getItem(‘gclid’) || ‘’;
$w(‘#input5’).value = session.getItem(‘adset’) || ‘’;
$w(‘#input6’).value = session.getItem(‘adid’) || ‘’;

// Set extra hidden fields for tracking alternatives
$w('#input7').value = session.getItem('wbraid') || '';
$w('#input8').value = session.getItem('gbraid') || '';
$w('#input9').value = session.getItem('msclkid') || '';

});