Previously we are able to solve using a JS script code to query the current page UTM and put it across all external URL (Below is the code) but it’s not working on this situation as its a button and it doesn’t have HREF element,
---- script—
function updateQueryString(uri, key, value) {
var re = new RegExp("([?&])" + key + “=.*?(&|$)”, “i”);
var separator = uri.indexOf(’?’) !== -1 ? “&” : “?”;
if (uri.match(re)) {return uri.replace(re, ‘$1’ + key + “=” + value + ‘$2’);}
else {return uri + separator + key + “=” + value;}
}
You could use the HubL variable request.query to add the query parameters to the redirectUrl field of your form’s custom embed code; the developer doc below has some more info on customizing the form embed code.
This is a list of options that you can use if you just need to tweak a default hubspot form. If you need complete control over the styles and actions of your form, you will still want to use the Forms API.
How to get UTM passed back to the destination URL after user click submit button
Thanks Derek. Somehow missed this message. We solved it
This is the solution our tech team found
var urlParam = function(name){
var results = new RegExp(’[?&]’ + name + ‘=([^&#]*)’).exec(window.location.href);
return (results || [])[1];
};
var setUrlParamToForm = function(name, form) {
var param = urlParam(name);
if (param) {
$(’’).attr({
type: ‘hidden’,
name: name,
value: param,
}).appendTo(form);
}
};
setUrlParamToForm(‘utm_source’, $form);
setUrlParamToForm(‘utm_campaign’, $form);
setUrlParamToForm(‘utm_medium’, $form);
setUrlParamToForm(‘utm_term’, $form);
setUrlParamToForm(‘utm_content’, $form);
code which makes hidden fields in form, with utm params from url