Google Tag Manager

⌘K
  1. Home
  2. Google Tag Manager
  3. Advanced Google Tag Manag...
  4. Tracking Resource Form Submission (Popup Form) Event in GA4 via GTM (Gatsby.js)

Tracking Resource Form Submission (Popup Form) Event in GA4 via GTM (Gatsby.js)

Objective

Track form submissions from the resource section popup as a GA4 event (generate_lead) using Google Tag Manager, even though there is no page reload or thank-you page.

Why This Approach?

Since this is a JavaScript-powered popup form, GTM’s default Form Submission trigger likely won’t detect it.

👉 The most accurate solution: fire a custom GTM event using dataLayer.push() after a successful submission.

Step 1: Add dataLayer.push() to Your Form Logic

Ask your developer (or update the Gatsby form component) to push an event after successful submission, like this:

window.dataLayer = window.dataLayer || [];

window.dataLayer.push({

  event: “generate_lead”,

  form_location: “popup_resource_form”

});

Place this code after the form data has been successfully submitted and accepted, not just when the submit button is clicked.

Step 2: Create a Custom Event Trigger in GTM

  1. Go to GTM
  2. In the left menu, go to Triggers
  3. Click New
  4. Name it: Custom – generate_lead (Resource Popup)
  5. Choose Trigger Type → Custom Event
  6. Set Event name to: generate_lead
  7. Choose: All Custom Events
  8. Click Save

Step 3: Create a GA4 Event Tag

  1. Go to Tags → Click New
  2. Name it: GA4 – generate_lead (Resource Download)
  3. Tag Configuration → Select GA4 Event
  4. Select your GA4 Configuration Tag
  5. Set Event Name to: generate_lead
  6. Add optional parameters (for context):
    form_location : popup_resource_form

         resource_type : whitepaper

Step 4: Link the Trigger to the Tag

  1. Scroll to Triggering
  2. Select: Custom – generate_lead (Resource Popup)
  3. Click Save

Step 5: Preview and Test

  1. Click Preview in GTM
  2. Open the Resource page on your website
  3. Click Download this file → Form appears
  4. Fill out and submit the form
  5. In the Tag Assistant debug window, confirm:
    • Event generate_lead appears in the timeline
    • GA4 event tag fires successfully
    • Event parameters (form_location, resource_type) show up correctly

Step 6: Publish

Once confirmed, click Submit → Publish in GTM
Name the version: GA4 Event – Resource Popup Submission

Result

Each time a user submits the popup resource form, a GA4 event generate_lead is triggered, helping you:

  • Track downloads
  • Attribute leads to specific campaigns or files
  • Build conversion-based audiences in GA4

How can we help?