Introduction:
To increase our branding efforts and demographic awareness, we would like to see an event in GA4 whenever someone submits this form. Additionally, it is interesting to identify visitors who want to receive our newsletter.
Temporary solution:
A form submit isn’t always the most reliable trigger in Google Tag Manager, however, and preferably we want to track this form as soon as possible. Until development can schedule some time to implement a reliable form submission event within the codebase, we need to create a temporary solution in the form of sandboxed JavaScript.
Plan of approach:
Build temporary logic using sandboxed JavaScript to construct a dataLayer.push for an event which contains the following parameters:
- First_name : string
- Email : string
- Phone_number : number
- Newsletter_opt_in : boolean
This sandboxed JavaScript is injected to the page through Google Tag Manager.
Additionally, a new GA4 tag must be created, which sends data to our server-side Google Tag Manager container.