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 Teun, would yo help me how to add this? I got some problem because when i add that code that you posted here. No more hubspot-success-form fires. Its an Custom HTML Tag.
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.
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.
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.
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.
Hello, I applied this process to track form submissions in google ads, but the google ads tag preview shows that form_submit gets hits sent with the user provided data with the enhanced conversion and hashed email. But the next event is the conversion and the conversion comes with the ec_mode - a (automatic) instead of manual, So it doesn’t receive the hashed email: em - tv.1.
Given that the original post is quite old (two years!), it would be best to create a fresh post. To ensure the community can offer the best support, please include ample detail and context, along with any relevant screenshots or code snippet.
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.
Thank you! — Jaycee