I’ve found a way to do it through GTM, thanks to a kind stranger on stackoverflow:
<script type="text/javascript">
window.addEventListener("message", function(event) {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
window.dataLayer.push({
'event': 'hubspot-form-success',
'hs-form-guid': event.data.id,
'email': Object.keys(hubspot._emailValidationAndResubCache)[0]
});
}
});
</script>
This will push the clean email address to the dataLayer as part of the event array:
