RE: Best Practices for Capturing URL Data in HubSpot Forms on External Landing Pages

Hi everyone,

I’m looking for some advice on capturing URLs in a form.

We have two event landing pages hosted on a different platform (not HubSpot). Our goal is to use a single form across both pages so we don’t have to create new forms every time we host an event. We’ll likely be doing this regularly in the future, so we want to streamline the process.

The challenge is that we still want to separate the data for reporting and create lists so we can use workflows in HubSpot.

Here’s what we’ve done so far:

  • We created a property in HubSpot called “website url” and added it to the form as a hidden field.
  • Since the event landing pages are hosted elsewhere, we used JavaScript to dynamically load the site URL into the hidden “website url” field.

This solution works—we’re able to create lists and generate reports from the data. However, I wanted to check if anyone has found a better way to do this or if you foresee any issues with embedding the script below on both pages?

<script charset=“utf-8” type=“text/javascript” src=“https://js.hsforms.net/forms/embed/v2.js”></script>
<script>
hbspt.forms.create({
region: “XXXX”,
portalId: “XXXXX”,
formId: “XXXXXX”,
onFormReady: function($form) {
function setWebsiteField() {
var currentPageUrl = window.location.href;
$form.find(‘input[name=“website”]’).val(currentPageUrl);
}

var intervalId = setInterval(setWebsiteField, 500);

$form.on(‘submit’, function() {
clearInterval(intervalId);
setWebsiteField();
});
}
});
</script>

Did you try UTMs? This is exactly what they are supposed to do: help you diffrintiate where the contact is coming from, specially when these pages are external to HubSPot.

Hi @Ktamir - thanks for your reply!

Yes, we’re using UTMs also. We have a main page also with a link to both events, so unfortunately the UTMs will drop off when they navigate to the next pages.

Just a quick update on this, I had a chat with a developer and they said it’s the best solution for now! But open to any other comments if you have suggestions.

Hi,

It looks like you’ve implemented a solid solution with the hidden field and JavaScript for capturing the URL. One potential improvement could be using HubSpot’s built-in tracking capabilities with UTM parameters to track different campaigns or pages more efficiently. If you’re using multiple event landing pages, you could dynamically append UTM parameters to the URLs to help with segmentation.

Otherwise, your current approach seems effective, and if the script is functioning as expected without issues, it should work well for your needs!

Thanks