Gravity Forms自定义事件无法通过Google Tag Manager触发问题排查
Hey there, let's dig into why your custom formSubmission event isn't triggering your tag after submitting a Gravity Forms form and landing on the thank you page. Here are the most likely culprits and fixes to try:
1. Your Code Runs Too Early (Before the Page is Ready)
If your custom HTML tag fires immediately when the page loads (via the All Pages trigger), it might run before the thank you page's elements are fully loaded—or even before Gravity Forms confirms the submission context exists. That means your event never gets pushed to the data layer.
Fix: Wrap your code in a DOM-ready handler, and first verify you're actually on a Gravity Forms thank you page. Here's a corrected snippet:
// Wait for the entire page to load before running document.addEventListener('DOMContentLoaded', function() { // Check if we're on a Gravity Forms thank you page (look for the confirmation wrapper) const thankYouElement = document.querySelector('.gform_confirmation_wrapper'); if (thankYouElement) { // Push the custom event to the data layer window.dataLayer.push({ 'event': 'formSubmission' }); } });
2. Typos or Incorrect Data Layer Syntax
Even a tiny typo can break things! Double-check:
- You're using the exact event name
formSubmission(it's case-sensitive—FormSubmissionorform_submissionwon't match your trigger). - Your data layer push is formatted correctly (no missing commas, curly braces, or quotes). Using
window.dataLayer.pushinstead of justdataLayer.pushis safer for edge cases.
3. Trigger Configuration is Off
Make sure your custom event trigger is set up correctly:
- Trigger Type: Custom Event
- Event Name:
formSubmission(use "Exact Match" unless you intentionally want regex) - This Trigger Fires On: All Custom Events (or narrow it to just your thank you page URL for better targeting)
4. Redirected Thank You Page is Excluded from the Trigger
If your form redirects to a separate thank you page (instead of showing an inline confirmation), ensure your All Pages trigger includes that specific URL. It's easy to forget to add the redirect page to the trigger's firing conditions!
5. Check for JavaScript Errors
Open your browser's DevTools (hit F12) and go to the Console tab. Look for any red error messages from your custom HTML tag—things like undefined variables or syntax mistakes will stop your code dead in its tracks.
Pro Testing Tip
Use GTM's Preview mode to debug step-by-step:
- Load your form page, submit it, and navigate to the thank you page.
- In the GTM Preview panel, check the "Events" tab—you should see
formSubmissionlisted if it fired. - If not, head to the "Tags" tab to see if your custom HTML tag fired, and read the explanation for why it didn't (e.g., "Trigger not fired" or "Error in tag").
内容的提问来源于stack exchange,提问作者pdas

