Dynamic Button URL based on custom Property?



Hi there.


I'm currently installing a few lines of jQuery on several non-hubspot pages. The pages have a hubspot form with a hidden field that the jQuery should automatically populate with the page URL upon form submission.

The URL should then be stored in a contact property called registration_backlink.


The logic is to use the contact property called registration_backlink in order to create dynamic buttons in emails so each person is referred to register and submit their details on an updated version of the page they visited before. What's the best way to go about doing this?

An alternative to the whole process would be to enroll contacts into an active list based on the URL they came from and send them an email with smart content based on list city but as we're running hundreds of events we would be running out of active lists!

Ideal Process/Example:

User visits https://ww1.qstopmba.com/events/qs-world-mba-tour/europe/st-petersburg
User clicks Green button and form pops up.
User fills in form and jQuery fires by adding https://ww1.qstopmba.com/events/qs-world-mba-tour/europe/st-petersburg into the contact property registration_backlink
When event details are published, User receives an email with a dynamic URL button, in this case linking to https://ww1.qstopmba.com/events/qs-world-mba-tour/europe/st-petersburg


This is a non-hubspot page, but we use a hubspot form.
The link above is a test-website and may appear as usafe to visit on some browsers
The jQuery we're using for this is:

var getURL = window.location.href;


Hi @aaaaandrei, did you see my previous reply here: jQuery to get page URL in hidden field?

I tested the code on my site and it worked properly:

	var getURL = window.location;


You can also place the code above inside the onFormSubmit method instead of document ready as per these docs: https://developers.hubspot.com/docs/methods/forms/advanced_form_options


Hi @Connor_Barley thanks for the reply!
Just seen it thanks for that.

That's how I initially coded it but opted for the code I mentioned above as it was suggested to us by our on-boarding HS manager.

However, this ticket is a little different than the previous one. It has to do with dynamic urls for buttons instead of fixed ones. so Click Here! should take contacts to the url in their contact property.

Do personalisation tokens work inside links?


Oh, got it @aaaaandrei, my fault!

Yes so if you are sending an email to the user, you should be able to use a custom property in that email with the URL that they filled out the form on that you set with jquery. So if they filled out the form and their property was properly set, in the email you can use that property by inserting a personalization token the normal way: https://knowledge.hubspot.com/articles/kcs_article/cos-general/how-to-use-personalization-with-your-content, or write in the source code:

{{ contact.internal_name_of_property_here }}. For me that is: {{ contact.url }}


Amazing, thanks @Connor_Barley.
I tested it and it works!


Awesome! Glad to help @aaaaandrei :grinning: