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>