Home › How-tos › The Secret Setups › dataLayer
How to build a dataLayer for lead tracking
Live guide · Checked 28 October 2026 · Updated 28 October 2026 · Checked every week against dataLayer's own help pages
Set up a clean dataLayer that every tag reads from: one generate_lead event with the form, the lead type and a value, so GA4, Google Ads and Meta all count the same leads.
- Time
- 30 minutes
- You will need
- Google Tag Manager on your site (see the Tag Manager How-to)
- Access to your site's code, or a place to add a script before the Tag Manager snippet
- A list of your forms and what each lead is worth to you
- Stuck?
- Troubleshooting or ask us a question
Step by step
Decide what you'll track
Write down every action that counts as a lead: each form, phone and email clicks, bookings. For each one, pick a short lead type (for example
quote,callback,booking) and a typical value in your currency.One event name for every lead keeps it simple:
generate_leadis the name GA4 recommends, so use that.Add the dataLayer before Tag Manager
The dataLayer must exist before the Tag Manager snippet loads, so nothing pushed early is lost. Put this as high as you can in the
<head>, above the Tag Manager code:<script> window.dataLayer = window.dataLayer || []; </script>Push a lead when a form is sent
When a form is sent successfully (not when the button is clicked), push one event with the details. Put this in your form's success handler, or on the thank-you page:
window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'generate_lead', form_id: 'quote-form', // which form lead_type: 'quote', // your short lead type value: 150, // what a lead like this is worth currency: 'GBP', lead_id: 'L-' + Date.now() // a unique id, used later to stop double counting });Never put names, emails or phone numbers in these fields: GA4's rules don't allow personal details in event data.
Make Data Layer Variables in Tag Manager
In Tag Manager open Variables, then under User-Defined Variables click New and choose Data Layer Variable. Make one for each field, using the exact name as the Data Layer Variable Name:
form_id lead_type value currency lead_idName them clearly, for example
DLV - form_id, so they're easy to pick later.Make the trigger
Open Triggers > New > Custom Event. Set Event name to
generate_leadand choose All Custom Events. Name itCE - generate_lead.Every lead tag (GA4, Google Ads, Meta and the rest) uses this one trigger.
Send it to GA4
Open Tags > New > Google Analytics > Google Analytics: GA4 Event. Enter your measurement ID, set Event Name to
generate_lead, and add Event Parameters:form_id {{DLV - form_id}} lead_type {{DLV - lead_type}} value {{DLV - value}} currency {{DLV - currency}}Set the trigger to
CE - generate_leadand save.Test it in Preview
Click Preview, enter your site's address and send a test form. In Tag Assistant, click the
generate_leadevent on the left: you should see your fields under Data Layer, and the GA4 tag under Tags Fired.Publish and mark the key event
Click Submit and Publish in Tag Manager. In GA4 go to Admin > Data display > Events (it can take up to a day for
generate_leadto appear) and turn on Mark as key event.
Tips from people who set these up every week
- Push on success, never on click: a click on a form with an error isn't a lead.
- Keep the same field names across every form and platform, and you'll never have to rebuild the tags.
- The lead_id lets Meta, TikTok and others match the browser and server copies of the same lead, so it's counted once.
Troubleshooting: questions and answers
The event shows in Preview but not in GA4.
Check the GA4 tag fired on generate_lead in Tag Assistant, then look in GA4 Admin > DebugView while in Preview. New events take up to 24 hours to appear in reports.
My form reloads the page before the push runs.
Push the event on the thank-you page instead, or use the form tool's own success event (several guides in The Secret Setups cover the common tools).
Can I send the email address for Enhanced Conversions?
Yes, but only to the Google Ads tag, never to GA4. See the Enhanced Conversions guide in this series.
Official help pages
Let Claude fix the rest of your funnel
Lead Focus is 12 Claude Skills that find the stage of your funnel that's costing you leads, then fix it: ads, landing pages, follow-ups and tracking. One payment, 12 months of updates, and a 14-day refund.
Get Lead Focus · $29.99Still stuck, or have a question?
Tell us where you got to and what you see. We read every message and reply by email, usually the same working day.