We would like to see the referrer url, (the last URL visited before landing on our contact page; the page that prompted the user to click the contact us link), in our form submissions and contact records. I tried the JavaScript HubSpot shared with me but it does not work.
We have a lot of products/services on our site and we need to know which one prompted their interest in contacting us so that we can direct the contact to right person.
I am using a HubSpot form
I used the standard Form module to embed the form
I set up a “referrerurl” property for Contacts
I created a hidden “referrer url” field in the form
Hey @AHagan,
Thanks for posting in the Community!
Tagging in a few experts here to see what insight they may have on the best practices to set this up! @danmoyle, @Josh, and @RomyFuchs1 - any thoughts?
Shane, Senior Community Moderator
Basically add ?referrer-page=ai-super-clusters at the end of your redirect url.
Where: “referrer-page” is a property that you have to create in HubSpot.
Make sure you the internal name is “referrer-page” and the values inside it are “ai-super-clusters”, “gen-ai-in-a-box” and so on.
Now inside your form add the referrer-page property, with no values and set it to hidden.
In order to inject the url part inside your form submission, you can use this piece of code (if your form is an iframe embed - obtained the code with chatgpt)
"
onFormReady: function($form) {
const params = new URLSearchParams(window.location.search);
const referrer = params.get(‘referrer-page’);
if (referrer-page) {
$form.find(‘input[name=“referrer-page”]’).val(referrer-page);
}
}
"
We use this and it works very well.
Additionally, you can embed HubSpot CTAs in every page and will give you more clarity on who clicked a CTA and when, inside the HubSpot contact overview, but for the topic of your question, it is not mandatory.
Cosmin Explore
HubSpot Consultant | Funnel Optimization & CRM Admin
Problem solved? Hit “Accept as Solution” and help the next person find it faster.