Skip to content

GA4Published 14 min read

Gravity Forms Conversion Tracking with GTM, GA4 and Ads

How to track Gravity Forms submissions in Google Tag Manager for GA4 and Google Ads, for every confirmation type, AJAX setting and multi-page form, without counting a lead twice.

Muhammad Qitmeer, founder of Augere Labs
Muhammad Qitmeer
Co-founder and CEO, Augere Labs
Share

Gravity Forms conversion tracking with GTM depends on one setting you check first: the form's confirmation type. If the confirmation is a Page or Redirect, fire your GA4 and Google Ads tags on the thank-you URL, with {entry_id} passed in the query string so reloads are not counted. If it is a Text confirmation on an AJAX form, listen for the gform_confirmation_loaded jQuery event and push a dataLayer event with the form ID. If it is a Text confirmation without AJAX, detect the confirmation message element when the page loads.

This guide is for agency owners, PPC managers and developers who track Gravity Forms on client WordPress sites. It covers the three confirmation types, AJAX versus non-AJAX behavior, the current Gravity Forms JavaScript events (including the 2.9 replacements), multi-page step tracking, passing the form ID, enhanced conversions data, a server-side option using gform_after_submission, spam, Stripe and the official Google Analytics Add-On. Every snippet avoids the common ways a lead ends up counted twice.

Why the built-in GTM Form Submission trigger fails on Gravity Forms

The first thing most people try is the GTM Form Submission trigger. On Gravity Forms it is unreliable for two reasons.

  • AJAX forms do not submit like normal forms. With AJAX enabled, Gravity Forms sends the data in the background and swaps the markup. GTM's listener may never see a standard submit event, or it sees one on the click.
  • A submit is not a lead. The trigger fires when the browser tries to submit, which includes attempts that fail required-field validation or get flagged as spam. You end up counting button presses.

The fix is to track the result, not the attempt. Gravity Forms only shows a confirmation, or sends the visitor to a confirmation page, after the entry passes validation. That is the signal to build on. If you want the general pattern across other form plugins, our GTM form tracking guide covers it.

Which confirmation type is the form using?

Open the form, go to Settings, then Confirmations. Every form has a Default Confirmation that cannot be deleted, and it may have extra confirmations with conditional logic. Gravity Forms has three types:

Confirmation typeWhat the visitor seesBest GTM trigger
TextA message replaces the form on the same URLAJAX: gform_confirmation_loaded. Non-AJAX: confirmation element on page load
PageA WordPress page chosen from a dropdownPage View on that page, with a query string check
RedirectAny full URL you enterPage View on that URL, with a query string check

Check every confirmation, not just the default. A common setup sends qualified leads to a Redirect and everyone else to a Text message. If you only tag the thank-you page, you miss half the leads. If you tag both without knowing why, you may be tracking the wrong ones. Conditional confirmations are also useful on purpose: route budget-qualified answers to a separate thank-you URL and make that the Google Ads primary conversion.

Tracking Page and Redirect confirmations

This is the most reliable method, and the one we default to when the client has no reason to keep a Text confirmation. Both Page and Redirect types have a Pass Field Data via Query String box that accepts merge tags. Put this in it:

gf_form={form_id}&gf_entry={entry_id}

Now each real submission lands on a URL like /thank-you/?gf_form=3&gf_entry=1842. That gives you three things: a way to tell real submissions from someone visiting the thank-you page directly, the form ID for reporting, and a unique ID to deduplicate on.

Do not pass the email, name or phone this way. The URL ends up in GA4's page location, in server logs and in referrers. Google's policies prohibit sending personal data to GA4, and that is the easiest way to break them.

The GTM setup

  1. Variables. Create two URL variables with Component Type set to Query, keys gf_form and gf_entry.
  2. Dedupe tag. Add a Custom HTML tag (code below) that fires on Page View when Page Path equals your thank-you path and gf_entry matches the regex .+.
  3. Trigger. Create a Custom Event trigger for gf_lead.
  4. Tags. Fire the GA4 event tag and the Google Ads conversion tag on that custom event, not on the page view.
<script>
  (function () {
    var params = new URLSearchParams(window.location.search);
    var entryId = params.get('gf_entry');
    var formId = params.get('gf_form');
    if (!entryId) return;
  
    var key = 'gf_lead_' + entryId;
    try {
      if (window.localStorage.getItem(key)) return;
      window.localStorage.setItem(key, '1');
    } catch (e) {}
  
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
      event: 'gf_lead',
      gf_form_id: formId,
      gf_entry_id: entryId,
      gf_confirmation: 'redirect'
    });
  })();
  </script>

The localStorage check stops reloads, back-button visits and reopened tabs from firing the conversion again in the same browser. It does not stop a forwarded link opened on another device, which is why the entry ID also goes to Google Ads (next section). If localStorage is blocked, the tag still fires, so you lose dedupe but not the conversion.

How do you stop thank-you page reloads counting twice?

A thank-you page tracked on a plain page view is the most common source of inflated Gravity Forms numbers we see. People refresh it, bookmark it, land on it from browser history, or a staff member links to it. Each visit counts. Three layers fix it:

  • Require the query string. No gf_entry, no event. Direct visits to /thank-you/ stop counting.
  • Browser dedupe. The localStorage check above handles reloads in the same browser.
  • Platform dedupe. In the Google Ads conversion tag, map the Transaction ID field to a Data Layer Variable for gf_entry_id. Google Ads ignores a second conversion with the same transaction ID for the same conversion action. Google documents this in Use a transaction ID to minimize duplicate conversions.

GA4 does not deduplicate generate_lead or custom events by ID. Only the browser-side check protects GA4. Also set the thank-you page to noindex so it does not pick up search visits. If the client is already seeing doubles in Ads, work through our fix for Google Ads counting conversions twice.

Tracking Text confirmations: AJAX vs non-AJAX

With a Text confirmation the URL never changes, so there is no page to trigger on. How you detect it depends on whether the form submits with AJAX.

How to tell if a form uses AJAX

AJAX is set where the form is embedded, not in the form settings. Check the embed:

  • Shortcode. [gravityform id="3" ajax="true"] means AJAX. No ajax attribute, or ajax="false", means a full page reload.
  • Block editor. The Gravity Forms block has an AJAX option in its settings panel.
  • Page builders. Elementor, Divi and others wrap the shortcode and expose their own AJAX toggle.
  • Quick test. Submit the form with the browser Network tab open. If the page does not reload, it is AJAX.

The same form can be AJAX on one page and non-AJAX on another. Check every page the form is embedded on.

AJAX Text confirmations: gform_confirmation_loaded

Gravity Forms triggers gform_confirmation_loaded on AJAX-enabled forms when the confirmation message is displayed. It passes the form ID as the second argument. The official gform_confirmation_loaded reference shows it bound with jQuery, and that matters: it is triggered through jQuery, so bind it with jQuery(document).on, not addEventListener.

This Custom HTML tag handles both AJAX and non-AJAX Text confirmations. Fire it on the Window Loaded trigger, on all pages that have a Gravity Form. Window Loaded matters because WordPress often loads jQuery in the footer, after GTM's earlier triggers run.

<script>
  (function () {
    if (window.__gfTrackingBound) return;
    window.__gfTrackingBound = true;
    window.dataLayer = window.dataLayer || [];
  
    var fired = {};
  
    function pushLead(formId, method) {
      formId = String(formId);
      if (fired[formId]) return;
      fired[formId] = true;
  
      var lead = {
        event: 'gf_lead',
        gf_form_id: formId,
        gf_confirmation: method
      };
  
      var stored = null;
      try { stored = window.sessionStorage.getItem('gf_ud_' + formId); } catch (e) {}
      if (stored) {
        lead.user_data = JSON.parse(stored);
        try { window.sessionStorage.removeItem('gf_ud_' + formId); } catch (e) {}
      }
      window.dataLayer.push(lead);
    }
  
    // AJAX forms with a Text confirmation
    if (window.jQuery) {
      jQuery(document).on('gform_confirmation_loaded', function (event, formId) {
        pushLead(formId, 'ajax_text');
      });
    }
  
    // Non-AJAX forms: the confirmation is already in the page HTML
    var messages = document.querySelectorAll('.gform_confirmation_message');
    for (var i = 0; i < messages.length; i++) {
      var match = (messages[i].id || '').match(/gform_confirmation_message_(\d+)/);
      if (match) pushLead(match[1], 'page_text');
    }
  })();
  </script>

The __gfTrackingBound guard stops the listener from being bound twice if the tag fires again, for example when someone adds a History Change trigger later. Each binding would push its own event, and that is a classic cause of exact 2x counts.

Non-AJAX Text confirmations

Without AJAX, the form posts to the same URL and the server returns the page with the confirmation message in place of the form. The second half of the script finds it. Gravity Forms gives the message element the class gform_confirmation_message and an ID of gform_confirmation_message_ followed by the form ID. Check the live markup on the client's theme before you rely on it, since heavily customized themes can change the wrapper.

One extra risk: the confirmation is the response to a POST. If the visitor refreshes, the browser asks to resubmit, and if they agree Gravity Forms receives a second real submission and creates a second entry. That is a real duplicate entry, not just a tracking problem. Switching to AJAX or a Redirect confirmation removes it.

AJAX with a Redirect confirmation

On an AJAX form with a Page or Redirect confirmation, there is no confirmation message to display. The browser just moves to the new URL, so gform_confirmation_loaded is the wrong signal. Track the thank-you URL as described above. If a form uses Text for some conditions and Redirect for others, keep both methods. They never fire for the same submission.

Which Gravity Forms JavaScript events can you use in GTM?

Gravity Forms 2.9 introduced new JavaScript events and deprecated some older jQuery ones. Here is what each is good for in tracking, and what to avoid.

EventFires whenUse for tracking?
gform_confirmation_loadedAJAX form shows a Text confirmationYes, the lead signal for AJAX Text confirmations
gform_page_loadedAJAX multi-page form moves to the next or previous pageYes, for step tracking
gform/ajax/post_page_changePage change on a multi-page form using the 2.9 AJAX submission methodYes, for step tracking on 2.9+. Use this or gform_page_loaded, not both
gform_post_renderEvery render: first load, page change, validation errors, confirmationNo. Deprecated in 2.9 in favor of gform/post_render
gform/post_renderForm rendered (2.9+), with event.detail.formId and event.detail.currentPageOnly for form views or form starts, never as a conversion
gform/submission/pre_submissionAfter a submit, next or previous button click, before the request is sent (2.9+)No. It fires before validation, so it counts attempts

The trap is gform_post_render and its replacement. Older tutorials use it because it also fires when the confirmation shows. It fires after a failed validation too, so it counts every rejected attempt. If you inherit a container that uses it as a conversion trigger, that alone can explain inflated numbers. Our GA4 form submissions not tracked checklist covers the opposite problem when nothing fires at all.

How do you track multi-page Gravity Forms steps in GA4?

On long quote forms, step data shows where people drop off. With AJAX enabled, add this to the same Custom HTML tag or a separate one:

<script>
  (function () {
    if (window.__gfStepsBound || !window.jQuery) return;
    window.__gfStepsBound = true;
    window.dataLayer = window.dataLayer || [];
  
    jQuery(document).on('gform_page_loaded', function (event, formId, currentPage) {
      var detail = (event.originalEvent && event.originalEvent.detail) || {};
      formId = formId || detail.form_id;
      currentPage = currentPage || detail.current_page;
      window.dataLayer.push({
        event: 'gf_step',
        gf_form_id: String(formId),
        gf_step: Number(currentPage)
      });
    });
  })();
  </script>

The detail fallback is there because the current Gravity Forms docs show gform_page_loaded with values on event.detail, while older versions passed them as extra jQuery arguments. Reading both keeps one listener working across versions without binding it twice.

Things to know:

  • Previous counts too. The event fires when the visitor goes back a page. Record the step number and build the funnel from the highest step reached, not from event counts.
  • Validation errors on a page. If a page fails validation, the visitor stays on it. Do not count a step until the page number changes.
  • Non-AJAX multi-page forms. Each page change is a full reload and these events do not fire. If step data matters, enable AJAX on that embed.
  • Keep steps out of conversions. Send gf_step to GA4 as a normal event. Never mark it as a key event or import it into Google Ads.

Sending the form ID to GA4 and Google Ads

Every push above carries gf_form_id. In GTM, create a Data Layer Variable for it, then:

  • GA4. Send generate_lead (a Google recommended event) with a form_id parameter, and register form_id as an event-scoped custom dimension. Mark generate_lead as a key event once. Our GA4 key events naming plan explains why one lead event with a parameter beats one event per form.
  • Google Ads. Usually one conversion action for real leads. Add a trigger condition such as gf_form_id matches ^(3|7)$ so newsletter or job application forms do not count as leads.
  • Several forms on one page. The form ID is the only way to tell a footer newsletter form from the main quote form. Always filter on it.

Enhanced conversions with Gravity Forms

Enhanced conversions need the visitor's email or phone at the moment the conversion tag fires. With an AJAX Text confirmation, the form is gone from the page by then. With a Redirect, you are on a new page. Capture the values when the visitor types them:

<script>
  (function () {
    if (window.__gfUserDataBound) return;
    window.__gfUserDataBound = true;
  
    document.addEventListener('change', function (e) {
      var el = e.target;
      if (!el.closest || !el.closest('.gform_wrapper')) return;
      var form = el.closest('form');
      if (!form || !form.id) return;
      var formId = form.id.replace('gform_', '');
  
      var key = 'gf_ud_' + formId;
      var data = {};
      try { data = JSON.parse(window.sessionStorage.getItem(key) || '{}'); } catch (err) {}
  
      if (el.type === 'email') data.email = el.value.trim().toLowerCase();
      if (el.type === 'tel') data.phone_number = el.value.replace(/[^\d+]/g, '');
  
      try { window.sessionStorage.setItem(key, JSON.stringify(data)); } catch (err) {}
    }, true);
  })();
  </script>

The confirmation script earlier reads this back and adds user_data to the gf_lead push, then deletes it. For Redirect confirmations, add the same read to the thank-you page tag. In the Google Ads conversion tag, turn on user-provided data and point a User-Provided Data variable at the email and phone Data Layer Variables. Phone numbers need E.164 format, so if the form does not collect a country code, either add it or send email only. Do not send user_data into a GA4 event parameter. The full setup, including the Google Ads account settings, is in our enhanced conversions setup guide.

Spam, payments and other edge cases

Spam submissions

Gravity Forms' spam settings decide what happens to a flagged entry: Create an entry and mark it as spam (the default) or Do not create an entry. Notifications, add-on feeds and your configured confirmations are not processed for spam. The visitor still sees a message, either a generic default or a Spam Confirmation you enable with Custom Spam Confirmation.

For tracking this means:

  • Redirect confirmations are safer. A spam submission gets a text message, not your thank-you URL, so it never reaches your conversion tag.
  • AJAX Text confirmations can count spam. The spam message is still a confirmation on screen. If you track Text confirmations, enable Custom Spam Confirmation and test whether your listener fires on it. If it does, move real leads to a Redirect.

Stripe and other payment forms

Payment add-ons that send the visitor off-site to pay break the in-page approach. Gravity Forms users have reported that tracking fires with Stripe's embedded card field but not with the Stripe payment page mode, because the visitor leaves the site and returns later. For any off-site payment flow, use a Redirect confirmation to a thank-you URL with the entry ID, and test with a real low-value payment.

Other things that break tracking

  • Save and Continue. If the form allows saving progress, click Save and Continue in testing and confirm your lead event does not fire.
  • Popups and modals. Forms inside page builder popups often load after the page. The listeners above are bound on document, so they still work.
  • Consent banners. If the banner blocks GTM until consent, the Window Loaded tag may run late or not at all. Make sure the listener tag runs, and let Consent Mode govern the tags that send data.
  • Optimization plugins. Delaying or combining JavaScript can load jQuery after your tag. Exclude Gravity Forms scripts and jQuery from delay, or retry binding briefly if window.jQuery is missing.

Server-side alternative: gform_after_submission

Browser tracking misses some conversions because of ad blockers, consent and closed tabs. Gravity Forms has a PHP hook that runs on the server for every saved entry. The gform_after_submission reference says it runs at the end of the submission process, after the entry is created, and that it also runs for entries marked as spam. So check the status first.

The most useful server-side job for Google Ads is storing click IDs on the entry, then importing qualified leads later. Add hidden fields for gclid and the GA client ID. Fill them with JavaScript from a cookie, because a PHP filter like gform_field_value_gclid runs when the page renders and gives every visitor the same value on a cached page. Gravity Forms input IDs follow the pattern input_FORMID_FIELDID, so field 7 on form 3 is #input_3_7.

If you also want a GA4 event from the server, send it with the Measurement Protocol:

add_action( 'gform_after_submission_3', 'agency_gf_send_mp', 10, 2 );
  
  function agency_gf_send_mp( $entry, $form ) {
      if ( rgar( $entry, 'status' ) === 'spam' ) {
          return;
      }
  
      $client_id = rgar( $entry, '7' ); // hidden field holding the GA client ID
      if ( empty( $client_id ) ) {
          return;
      }
  
      $url = 'https://www.google-analytics.com/mp/collect'
          . '?measurement_id=G-XXXXXXXXXX&api_secret=YOUR_API_SECRET';
  
      $body = array(
          'client_id' => $client_id,
          'events'    => array(
              array(
                  'name'   => 'gf_lead_server',
                  'params' => array(
                      'form_id'  => (string) $form['id'],
                      'entry_id' => (string) $entry['id'],
                  ),
              ),
          ),
      );
  
      wp_remote_post( $url, array(
          'headers'  => array( 'Content-Type' => 'application/json' ),
          'body'     => wp_json_encode( $body ),
          'timeout'  => 5,
          'blocking' => false,
      ) );
  }

A few rules for this:

  • Do not send the same event from both sides. GA4 has no deduplication for lead events. If the browser sends generate_lead and the server sends generate_lead, you get two. Use a different name, or pick one source.
  • It augments, not replaces. Google's Measurement Protocol documentation describes it as a way to add to tag-based collection. Without a real client ID from the browser, the event cannot join the user's session.
  • For Google Ads, import instead. Store the gclid, push the entry to the CRM, and upload qualified leads. Our offline conversion import guide covers that flow, and server-side GTM is the next step if the client needs more.

Gravity Forms add-ons for tracking: use them or not?

Gravity Forms has an official Google Analytics Add-On, offered on higher license tiers. It connects using Google Measurement Protocol, Google Analytics, Google Tag Manager or Manual Configuration, and you set up a feed per form for submission events and a separate form setting for pagination events. In Tag Manager mode, it pushes the dataLayer trigger you choose in the feed. Gravity Forms' own examples use GFTrackEvent.

  • When it helps. Sites with many forms where nobody wants to maintain GTM code, and Measurement Protocol mode for events that do not depend on page JavaScript.
  • When it hurts. If the add-on also outputs the GA or GTM script while another plugin or the theme already loads it, you get double page views and double events. The add-on has a setting to stop it outputting the script. Turn it off if GTM is already installed.
  • Never both. Pick the add-on or your own listener for each form. Running both fires two lead events per submission.

Third-party event tracking plugins for Gravity Forms work in a similar way. Before installing one, check what the site already has. The most common double count we find is a plugin and a GTM listener both pushing a lead event.

Testing Gravity Forms conversion tracking in GTM

  1. GTM Preview. Submit each form on each page it lives on. Confirm one gf_lead event with the right gf_form_id, and that the GA4 and Ads tags fire on it.
  2. Fail validation first. Leave a required field empty and submit. Nothing should fire.
  3. Reload the confirmation. Refresh the thank-you page or the AJAX confirmation. No second gf_lead.
  4. Go back and resubmit. A real second submission should create a new entry ID and fire once more. That is correct.
  5. Multi-page. Go forward, back and forward. Confirm gf_step values match the page numbers.
  6. GA4 DebugView. Confirm generate_lead arrives with form_id.
  7. Entries vs conversions. After a week, compare non-spam entries in Gravity Forms with GA4 lead events and Google Ads conversions for the same forms. Ads will be lower because it only counts ad clicks, but GA4 should be close to the entry count.

Getting it fixed for a client

Most broken Gravity Forms setups we see fall into one of four patterns: a thank-you page counted on every visit, gform_post_render used as a conversion, a tracking add-on running next to a GTM listener, or a Text confirmation that changed to a Redirect while nobody updated GTM. Each one is quick to fix once you know which it is. If you want a second pair of eyes on a client's forms before the next ad spend review, request a free tracking check and we will tell you what is counting, what is missing and what is counted twice.

Just one quick fix, not a whole account? Our founder takes small fixed-price jobs on Fiverr: GA4 and Google Tag Manager tracking fix

Frequently asked questions

Does gform_confirmation_loaded fire on non-AJAX forms?

No. Gravity Forms documents it as firing on AJAX-enabled forms when the confirmation message is displayed. On a non-AJAX form the page reloads with the confirmation already in the HTML, so detect the element with the class gform_confirmation_message when the page loads, or switch to a Redirect confirmation.

Why are my Gravity Forms conversions counted twice in Google Ads?

The usual causes are a thank-you page that fires on every visit or reload, a tracking add-on and a GTM listener both pushing a lead event, or a listener bound twice. Require the entry ID in the thank-you URL, pass it as the Google Ads transaction ID, and use one tracking source per form.

Can I use the GTM Form Submission trigger for Gravity Forms?

It is not reliable. AJAX forms do not submit through a normal page navigation, and the trigger fires on attempts that fail validation or are flagged as spam. Track the confirmation or the thank-you page instead.

How do I track each page of a multi-page Gravity Form?

Enable AJAX on the embed and listen for gform_page_loaded, or gform/ajax/post_page_change on Gravity Forms 2.9 and later, but not both. Push the form ID and page number as a normal GA4 event, and never mark step events as conversions.

Does gform_after_submission run for spam entries?

Yes. The Gravity Forms docs say the hook also runs for entries marked as spam. Check rgar( $entry, 'status' ) and return early when it equals spam before sending anything to GA4, Google Ads or a CRM.

Muhammad Qitmeer

Written by

Muhammad Qitmeer, founder of Augere Labs

Augere Labs is the white-label tracking partner behind marketing agencies. If a client account has numbers you don't trust, I'm happy to look at it with you and tell you straight what's wrong.

Connect on LinkedIn