I’m looking to pass in a parameter into a button URL that lives in my unified menu component across all my pages.
Basically - if someone is on a particular landing page on my site - I’m looking to append ?click_src={page-title} to my www.link.com/get-started button url.
Right now I’m achieving the desired effect on any of my non-component buttons - by manually updating them. That’s effectively passing through into my hubspot forms already. Not fancy at all. But I’m at a loss for what to do for my main menu bar.
The end goal is to be able to see which page converted a user to submit our unified lead form - without have to rely on analytics. Their click_src will be saved as a value on their hubspot contact record.
So this code is appending my designated links with a custom parameter.
It’s also replacing all the spaces with underscores and stripping out ampersands.
You may need to replace other special characters that aren’t covered in these cases.
This could also be tweaked to work with Class Names or even attributes…but for now ID’s work for me.
Also - we needed to add in a delay interval to make sure the elements had been created on the page, because without it, the code was being run first - before the elements had been created on the DOM.