# Google Tag Manager - Push Form Data to dataLayer

**URL:** <https://community.hubspot.com/t/google-tag-manager-push-form-data-to-datalayer/46935>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [November 14, 2021, 8:59pm UTC](https://community.hubspot.com/t/google-tag-manager-push-form-data-to-datalayer/46935 "2021-11-14T20:59:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [November 15, 2021, 7:29am UTC](https://community.hubspot.com/t/google-tag-manager-push-form-data-to-datalayer/46935/2 "2021-11-15T07:29:40Z")

</div>

Hi @EMartin51 ,

There is probably a better way to retrieve the value from the data object, but this should work:

```lia-code-sample
<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,
 'hs-form-email' : $('input[name="email"]').val()
 });
 }
 });
</script>

```

Not sure why, but I’ve only been able to manipulate and retrieve form data with jQuery, but I love to see a Vanilla JS solution that actually works.

---

_[View the full topic](https://community.hubspot.com/t/google-tag-manager-push-form-data-to-datalayer/46935)._
