# Passing UTM parameters and refferal url with the developer Embed code

**URL:** <https://community.hubspot.com/t/passing-utm-parameters-and-refferal-url-with-the-developer-embed-code/142363>\
**Category:** APIs & Integrations\
**Tags:** developer-tools, forms, contacts\
**Created:** [November 10, 2025, 1:43pm UTC](https://community.hubspot.com/t/passing-utm-parameters-and-refferal-url-with-the-developer-embed-code/142363 "2025-11-10T13:43:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeetuDubey](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@JeetuDubey](https://community.hubspot.com/u/JeetuDubey)\
**Post date:** [November 10, 2025, 1:43pm UTC](https://community.hubspot.com/t/passing-utm-parameters-and-refferal-url-with-the-developer-embed-code/142363/1 "2025-11-10T13:43:39Z")

</div>

I am using developer embed code to embed hubspot form in my site .

I want to track UTM params with reffreal url but it is not happeing there.

I have used custom JS to pass cookie values to the hidden values but it is not passing with the form.

The code I tried :

const $refPageURL = jQuery(‘input[name=“0-1/referral\_page\_url”]’);

$refPageURL.val(sessionStorage.getItem(“customReferrer”));

$refPageURL.change();

Even when I tried keeping the value inside a visible text field, it was automatically cleared on click because HubSpot’s form script reinitializes the field inputs on interaction.  
After further inspection, I discovered a hidden field named hs\_context, which contains all field values in JSON format. This JSON object is what HubSpot actually uses for submission — meaning any custom values set through regular inputs are overwritten by what’s inside hs\_context at the time of submit.  
I attempted to inject our custom data directly into the hs\_context object, and while the field shows the correct value in the form, HubSpot still doesn’t allow these script-injected values to persist through submission. This behavior appears to be part of HubSpot’s built-in data validation and security layer.  
Code :

var contextField = jQuery(“input[name=‘hs\_context’]”);

var contextData = JSON.parse(contextField.val());

var customReferrer = sessionStorage.getItem(“customReferrer”) || “Default Referrer”;

contextData.fieldValues[“0-1/referral\_page\_url”] = customReferrer;

contextField.val(JSON.stringify(contextData));

Please let me know the best way to pass custom values with the hubspot form so it can get submitted with the form

---

<div class="post-metadata">

**Author:** ![evaldas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/evaldas/32/69160_2.png) [@evaldas](https://community.hubspot.com/u/evaldas)\
**Post date:** [November 10, 2025, 3:25pm UTC](https://community.hubspot.com/t/passing-utm-parameters-and-refferal-url-with-the-developer-embed-code/142363/2 "2025-11-10T15:25:32Z")

</div>

Hi @JeetuDubey,

In order to work with the HubSpot forms, you will need to use the global form events:

> **[Global form events - HubSpot docs](https://developers.hubspot.com/docs/api-reference/latest/marketing/forms/global-form-events)**
>
> Learn how to use listeners to form global events to define custom behavior when users interact with forms on your site.

For legacy forms:

> **[Legacy forms - HubSpot docs](https://developers.hubspot.com/docs/cms/start-building/features/forms/legacy-forms)**
>
> View reference information for legacy forms, including available form events, validation error messages, and internationalization options.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Christensen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/christensen/32/24543_2.png) [@Christensen](https://community.hubspot.com/u/Christensen)\
**Post date:** [November 10, 2025, 3:51pm UTC](https://community.hubspot.com/t/passing-utm-parameters-and-refferal-url-with-the-developer-embed-code/142363/3 "2025-11-10T15:51:11Z")

</div>

Hey @JeetuDubey, when using the embed code of a form, you need to consider that it will be loaded in an iframe and modifying values inside an iframe is not best practice. You’ll run into cross-origin restrictions and it’s generally a security nightmare.  
I would suggest you try this suggestion as a workaround that’s been proven to work in another thread: [https://community.hubspot.com/t5/Tips-Tricks-Best-Practices/How-to-pass-UTM-parameters-to-HubSpot-form/m-p/491554/highlight/true#M1584](https://community.hubspot.com/t5/Tips-Tricks-Best-Practices/How-to-pass-UTM-parameters-to-HubSpot-form/m-p/491554/highlight/true#M1584)
