I'm trying to push a form's email value into the dataLayer once a form has been submitted; I've called the variable "hs-form-email" in the code below. I've been trying lots of different ways, and if I literally just use 'event.data', I can see the names and values in the variable, but I can't find a way to only extract the email value - could someone help?
Hi Adden, I just noticed that the contents of event.data changed from data.submissionValues to something named differently. Is this something you've noticed too, i.e. a change on the Hubspot forms, or might this be caused by and change made by our team to the forms?
You can also dynamically access email input from the data layer with this step by step process.
Key to this process is, that you are not reliant on values being extracted from the DOM and you do not need to know at with position the email field is located since the code retrieves it dynamically.
2. Set up data layer variable called HubSpot Data where the name of the data layer variable is exactly hs-data.
3. Set up custom javascript variable – I call it HubSpot Mail (Forms) – with the following code:
function() {
var email;
for (var i = 0; i < {{HubSpot Data}}.data.length; i++) {
if({{HubSpot Data}}.data[i].name === 'email') {
email = {{HubSpot Data}}.data[i].value;
}
}
return email;
}
4. Use the variable HubSpot Mail (Forms) at your disposal, for example for enhanced conversions in Google Ads.
5. Set up data layer variable called HubSpot ID where the name of the data layer variable is exactly hs-id. You can now also use the ID of the form to send it to Google Analytics 4 as a custom parameter to identify the forms later on.
If you need any clarification about the setup, please reach out anytime!
Hi, Thanks for the Solution! However I can´t get it to work completely. I´m trying to use the variable from the field input as a an Event Parameter in a GA4Event. (I´m looking to use a custom input field of "Customer_Segment" to diversify my conversion value based on that, but in this case I´m using your email example so as not to do too many things at once)
But when I fill out my form and submit in preview mode, I only get "value: undefined":
In the API CallI can see that the information is there however, but like I said, it doesn´t seem to get picked up by the Event Parameter...
Do you have any suggestions as to what I should try?
yes, I have the complete setup as your instructions Below you can see the complete setup, with my customer Segment input instead of Email. Maybe I´m missing something...?
Hey, @SebKoppjes👋 Please consider clicking the Accept Solution button for @NiklasBuschner's post. I'm sure he'd appreciate it. And it will add it to the top of this post.
You create a new variable from the User-provided Data type and select your HubSpot Mail (Forms) variable for email and optionally a phone variable for phone.
Then you add this variable to your Google Ads conversion tag from the option "Include user-provided data from your website".
How did you add it? Because i tried too like @Teun say but Listener don't appear when i submit a form. If i try without email data, it works but adding that additional code breaks the HTML for me.