CMS Development

pbeville
Contributor

Identifying individual contacts from a URL

SOLVE

Hi

 

I use a QR code to point users to a landing page (which is on a postal letter sent to a Hubspot contact).  I am able to customise the landing page based on variables in the URL using HubL HTTP request variables {{% request.query_dict %}}.  Is there any way that I can add something to the URL to feed back into Hubspot so I know the user has visited the site and add it to their activity record?

 

Many thanks. 

0 Upvotes
1 Accepted solution
pbeville
Solution
Contributor

Identifying individual contacts from a URL

SOLVE

OK, I solved this by adding a hidden form to the page with just the email required and added this code to the footer (thanks to Claude for the code!):

<script>
window.onload = function() {
console.log('Script started');

const urlParams = new URLSearchParams(window.location.search);
const email = urlParams.get('email');

console.log('Email from URL:', email);

if (email) {
// Wait for HubSpot's form API to be ready
var checkHubSpot = setInterval(function() {
if (window.hbspt) {
clearInterval(checkHubSpot);
console.log('HubSpot loaded');

// Find the form after a short delay
setTimeout(() => {
const forms = document.querySelectorAll('form.hs-form');
console.log('Forms found:', forms.length);

forms.forEach(form => {
const emailField = form.querySelector('input[name="email"]');
if (emailField) {
emailField.value = email;
console.log('Email field populated');

setTimeout(() => {
const submitButton = form.querySelector('input[type="submit"]');
if (submitButton) {
console.log('Submit button found, clicking...');
submitButton.click();
} else {
console.log('Submit button not found');
}
}, 2000);
}
});
}, 1000);
}
}, 100);
}
}
</script>

View solution in original post

0 Upvotes
8 Replies 8
pbeville
Solution
Contributor

Identifying individual contacts from a URL

SOLVE

OK, I solved this by adding a hidden form to the page with just the email required and added this code to the footer (thanks to Claude for the code!):

<script>
window.onload = function() {
console.log('Script started');

const urlParams = new URLSearchParams(window.location.search);
const email = urlParams.get('email');

console.log('Email from URL:', email);

if (email) {
// Wait for HubSpot's form API to be ready
var checkHubSpot = setInterval(function() {
if (window.hbspt) {
clearInterval(checkHubSpot);
console.log('HubSpot loaded');

// Find the form after a short delay
setTimeout(() => {
const forms = document.querySelectorAll('form.hs-form');
console.log('Forms found:', forms.length);

forms.forEach(form => {
const emailField = form.querySelector('input[name="email"]');
if (emailField) {
emailField.value = email;
console.log('Email field populated');

setTimeout(() => {
const submitButton = form.querySelector('input[type="submit"]');
if (submitButton) {
console.log('Submit button found, clicking...');
submitButton.click();
} else {
console.log('Submit button not found');
}
}, 2000);
}
});
}, 1000);
}
}, 100);
}
}
</script>

0 Upvotes
GiantFocal
Top Contributor | Partner
Top Contributor | Partner

Identifying individual contacts from a URL

SOLVE

Hi @pbeville,

 

Can you confirm what needs to be tracked on HubSpot and the activity record?

Is it whether they have visited the website or not?

Best regards,
Ernesto @ GiantFocal
Found this answer helpful?
Marking it as the solution helps both the community and me - thanks in advance!
0 Upvotes
pbeville
Contributor

Identifying individual contacts from a URL

SOLVE

@GiantFocal Yes, the fact that they have visited the website, ideally in the activity record but it could be in the form of a note... Thank you.

0 Upvotes
pbeville
Contributor

Identifying individual contacts from a URL

SOLVE

Hi @SteveHTM 

 

Thank you for the prompt response, unfortunately they will not have an HS cookie installed as we are cold apporoaching them via a postal letter, hence the question, There is information about them in the URL (via the QR code) and this is used to personalise the landing page - so I was hoping these could be fed back into Hubspot in some way?

 

Thanks, Phil

0 Upvotes
SteveHTM
Key Advisor | Partner
Key Advisor | Partner

Identifying individual contacts from a URL

SOLVE

You did say the contact existed already in your HubSpot database - right? If so, then they may have a cookie from a previous conversion.

 

Depending on how determined you are, it would be possible to include a contact reference (ID perhaps) coded into your personalized URL and use that to associate the web session with a contact record.

 

Good luck!

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature
0 Upvotes
pbeville
Contributor

Identifying individual contacts from a URL

SOLVE

@SteveHTM they are unlikely to have visited our site before and, therefore, to have a cookie but this.... "Depending on how determined you are, it would be possible to include a contact reference (ID perhaps) coded into your personalized URL and use that to associate the web session with a contact record." is exactly what I would like to do if you know how - I can definitely add the ID to the URL but need to know how to process it on the landing page... If you can help me with that I will be very grateful! 🙏🏼

0 Upvotes
SteveHTM
Key Advisor | Partner
Key Advisor | Partner

Identifying individual contacts from a URL

SOLVE

They may be a number of ways to add such functionality, but I'd start exploring along the lines of:

- understanding how you could trigger a workflow based on a specific URL visit that included a contact ID. This may require some creativity 🙂

- Using that contact ID in the workflow (possibily needing a custom code workflow step) to write details of the visit to the contact record.

 

It would be nice to think you could do all this in HubL customization code on the landing page (as a side effect of crm_object() perhaps), but writing anything to the database is tricky in my experience.

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature
0 Upvotes
SteveHTM
Key Advisor | Partner
Key Advisor | Partner

Identifying individual contacts from a URL

SOLVE

@pbeville - if the browser used to visit the site has a HS cookie installed, or sthe site visit later turns into a form conversion, then HubSpot automatically tracks the visit session on the Contact record. You can also use such visits to trigger workflows etc. or change score.

 

Maybe that's not what you were looking for?

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature
0 Upvotes