UTM Parameters from Wix Velo Page Code to iframe – Works in Studio Preview but Fails on Customization

Hello Wix Velo community!

Hi everyone!

After 211+ failed attempts :face_with_bags_under_eyes: , I’m reaching out to the community for help. We have a specific issue: Page Code captures UTM parameters and stores them in sessionStorage, but the iframe cannot retrieve these values - resulting in empty fields in the webhook and lost campaign data.

CONTEXT & BACKGROUND

✓ Tested the official Wix example: https://www.wix.com/velo-examples/hello-strg-studio
→ Works in Wix Studio editor preview mode
FAILS when customizing and using our custom iframe

✓ No masterpage.js in our project (isolated issue)

✓ Page Code imports:

import { session } from ‘wix-storage’;
import wixLocation from ‘wix-location’;
import wixData from ‘wix-data’;
import { local } from ‘wix-storage’;

✓ Read extensively in community posts:

THE REAL ISSUE

Page Code successfully stores UTM params in sessionStorage, BUT the iframe HTML component cannot read these stored values when trying to retrieve them. Result: all UTM params show as null/empty in the webhook.

The issue isn’t sending data TO the iframe it’s that the iframe cannot ACCESS wix-storage (session/local) from browser context.

STEPS WE FOLLOWED

STEP 1: Page Code captures and stores UTM
(This part WORKS ✓)

import { session } from ‘wix-storage’;
import wixLocation from ‘wix-location’;

w.onReady(async function() {
try {
// Capture full URL with UTM params
const urlCompleta = wixLocation.url;



// Extract UTM parameters
const queryObj = wixLocation.query;
const utmParams = {
  utmsource: queryObj.utmsource || null,
  utmmedium: queryObj.utmmedium || null,
  utmcampaign: queryObj.utmcampaign || null,
  utmcontent: queryObj.utmcontent || null,
  utmterm: queryObj.utmterm || null,
  gclid: queryObj.gclid || null,
  // ... other UTM parameters
};



// STORE in sessionStorage
await session.setItem('wixutmparams', JSON.stringify(utmParams));

console.log('✓ UTM stored in session:', utmParams);

} catch (err) {
console.error(‘Error capturing UTM:’, err);
}
});



✓ **Console shows:**

V210-PAGE UTM stored in session: { utmsource: “google”, utmmedium: “paid”, … }



**STEP 2: iframe tries to READ from sessionStorage**
(This part FAILS ✗)


✗ **Console shows:**

Uncaught ReferenceError: session is not defined
localStorage.getItem(‘wixutmparams’) returns: null


THE PROBLEM - DETAILED

  1. Page Code context (worker) = has access to `wix-storage` (session/local)
  2. iframe context (browser) = NO access to `wix-storage`
    • iframe cannot import `wix-storage`
    • iframe cannot call `session.getItem()` or `local.getItem()`
    • iframe CAN use native `localStorage`/`sessionStorage`, BUT Wix keeps it isolated
    • Result: Data stored by Page Code in Wix’s session storage is NOT readable from iframe

This seems like a Wix sandbox security boundary that blocks cross-context storage access.


QUESTIONS FOR THE COMMUNITY

  1. Is there a documented way to pass data from Page Code to iframe through wix-storage?

    • Besides postMessage (which we’ve tried listener doesn’t work in Page Code worker context)
  2. Does Wix sandbox intentionally isolate iframe from wix-storage?

    • If so, is there an alternative architectural approach?
  3. Has anyone successfully transferred UTM data from Page Code → iframe in production?

    • What method did you use?
  4. Is postMessage the ONLY option?

    • We need the iframe to receive data that Page Code captures before the iframe loads

EXPECTED FLOW (That should work but doesn’t)

URL loaded: ?utm_source=google&utm_medium=paid&utm_campaign=test-v210

↓

Page Code (worker) executes:
→ Captures URL via wixLocation.url ✓
→ Extracts UTM via wixLocation.query ✓
→ Stores in session.setItem(‘wixutmparams’, {…}) ✓
→ Logs “UTM stored in session” ✓

↓

iframe HTML loads:
→ Tries: session.getItem(‘wixutmparams’) ✗ FAILS
→ Tries: localStorage.getItem(‘wixutmparams’) ✗ Returns NULL
→ Cannot read data = form remains empty
→ Webhook sent with: utmsource: null (LOST!)

↓

Expected result: utmsource: “google” in webhook
Actual result: utmsource: null in webhook


ENVIRONMENT INFO

  • Wix Velo: Enabled
  • Page Code: Active on page
  • iframe: HTML Component embedded in Wix
  • Storage tested: wix-storage (session), localStorage, memory
  • Browser: Chrome Latest (tested)
  • Wix Mode: Domain test (teste.wixstudio.com/”site”)

## WHAT WE NEED

A working example OR clarification on:

  • ✓ How to reliably pass UTM data from Page Code to iframe
  • ✓ Whether wix-storage is accessible from iframe context
  • ✓ Alternative methods if postMessage listener doesn’t work in Page Code worker

Any dev who has solved this: please share your approach!

Thank you for your help!

TAGS:
wix-data wix-urls-v2 urls wix-storage-frontend site-storage wix-studio

1 Like

I’d recommend using the postMessage approach to communicate between the iFrame and the page code.

We have a video that covers everything you’ll need to send data from the page to the iFrame, and then from the iFrame back to the page:

The video has always been my go to for remembering how to do this :slight_smile: Was there a specific need for using storage? Or was it just the first thought for sharing data between the page and iFrame?

1 Like

Hi Wix Community Team,

We want to say a genuine thank you for the documentation and support that
made our Page Code ↔ IFRAME integration project successful.

THE DOCS THAT SAVED US

Three pieces of documentation were absolutely critical:

  1. wix-location API docs - Showed us how to capture URLs with query params.
  2. iframe/introduction docs - Explained postMessage as the solution.
  3. General examples in video - Patterns of retry logic, error handling, config.

Without these, we would have:
:cross_mark: Tried impossible approaches (accessing IFRAME DOM from Page Code)
:cross_mark: Made security mistakes.
:cross_mark: Spent weeks debugging timing issues.
:cross_mark: Created unmaintainable code.

Our project succeeded because we:
✓ Read your docs carefully.
✓ Applied the principles.
✓ Went deeper with our own experimentation.
✓ Documented our findings.

THANK YOU FOR:
✓ Building APIs that work.
✓ Documenting them clearly.
✓ Explaining the WHY.
✓ Showing real examples.
✓ Supporting developers.
✓ Making Wix Velo approachable.

You’re making Wix Velo the most developer-friendly platform in the builder space.

Keep doing what you’re doing! :raising_hands:

With gratitude.

P.S. - If any developers need help with the code for the ↔ IFRAME page, I can add more details to this post. That’s what the Wix community is all about, helping each other.

1 Like

This text is definitely not an Easter egg.

6 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.