0

On my WordPress website I have a contact form built in Hubspot. I got the script of this form from Hubspot and past it in my contact page (https://stagezero.ai/contact/).

<script>
  hbspt.forms.create({
    region: "na1",
    portalId: "20085053",
    formId: "412d2c51-95f1-4a6c-b3f3-f71c5852ac98"
});
</script>

Whenever the form is submitted the user is redirected to our thank you page (https://stagezero.ai/thank-you/). So, whenever someone submit the form I want to extract the Emails of our users from the email field on our contact from. So basically, the goal is to get the emails stored as a variable so that it can be hashed and sent to google analytics. I have tried to do it by myself by writing and pasting this code in my contact page but unfortunately it did not work. Can some help me to achieve the goal which I have mentioned above? Thank you.

<script>
//code to get email values from contact form’s email field
var form = document.getElementById("hsForm_412d2c51-95f1-4a6c-b3f3-f71c5852ac98");
var email_field=document.getElementById("email-412d2c51-95f1-4a6c-b3f3-f71c5852ac98");
form.onsubmit = function(){
var email = email_field.value();

//code to send email values to Google Analytics
dataLayer.push({
    'event':'form_submit',
    'enhanced_conversion_data': {
      "email": email  // replace 'yourEmailVariable' with email variable //
    }
  });
};
</script>
  • Emails are considered PII. You're not supposed to collect them with front-end behavioral tracking in US and it's likely an infringement of GDPR. Also, what you've shown is not enough. Show the html of the form. Make sure it's not in an iframe. – BNazaruk Dec 03 '22 at 19:04
  • Thank you for responding The form is created in Hubspot so do i need to have its access to in order to get the emails? is there not any other way to get emails from website? If the form is in iframe would it be not possible to get email fields? And lasty, the form is added on my own site, would it still violate GDPR if i take emails because eventually when form is submitted i can get the information from hubspot? – Farhan Awan Dec 04 '22 at 10:40
  • If it's in an iframe, then you have no access to what's being typed there. Unless the iframe lets you know by issuing window events to the parent window. Either read their documentation, ask support or deploy a listener and see what's being sent to you, but I'm pretty sure it wouldn't give you the typed info. There may be a security concern from their side. – BNazaruk Dec 05 '22 at 03:59

0 Answers0