Elementor Form dataLayer

Simple • Lightweight • No dependencies

Push Elementor Pro submissions to dataLayer — plus dynamic Thank-You detection

A tiny interceptor that listens to Elementor Pro form submits (via admin-ajax.php), pushes elementor_form_submit immediately, and (optionally) fires elementor_form_thank_you on the actual redirect page detected from the AJAX response.

Example dataLayer push
{
  event: "elementor_form_submit",
  user_data: {
    action: "elementor_pro_forms_send_form",
    form_id: "fc941d8",
    post_id: "5",
    first_name: "Test",
    last_name: "User",
    email: "info@example.com",
    message: "Hello"
  }
}

What this code does

Benefits

Cleaner attribution

Consistent submit & thank-you events make GA4/Ads/Meta conversions straightforward and de-duplicated.

No plugin edits

Drop-in script—works alongside Elementor Pro without touching form settings.

Future-proofed

Handles varied Elementor response shapes and many thank-you URLs per form.

How it works

  1. Form is submitted to /wp-admin/admin-ajax.php.
  2. On success response, the script pushes elementor_form_submit with parsed fields.
  3. The script extracts the redirect URL and stores its pathname for that form.
  4. On any page load, if the current path matches a stored thank-you pathname, it pushes elementor_form_thank_you.

Install in 2 steps

1) Add Config (before main script)

<script>
var eleFormDLConfig = {
  storeData: true,
  oncePerUser: false,
  pushDataLayerOnThankYouPage: true,
  checkUserDataOnThankYouPage: true,
  removeDataAfterDataLayerPush: true,
  useDynamicThankYou: true,
  pushThankYouImmediatelyIfUnknown: true,
  // thankYouPages: ["/thank-you/"], // use if useDynamicThankYou = false
  maxTyPathsPerForm: 10
};
</script>

2) Add the Main Script

Paste the repository’s main JS right after the config (theme, code snippet plugin, or GTM Custom HTML on All Pages).

GTM: Make sure the Config tag fires before the Main tag.

Key configuration

Option Type Default Description
storeData boolean true Save last payload to localStorage for use on TY page.
oncePerUser boolean false After first success, skip both submit & TY pushes.
pushDataLayerOnThankYouPage boolean true Enable TY push on the actual redirect page.
checkUserDataOnThankYouPage boolean true Only push TY if stored data exists.
removeDataAfterDataLayerPush boolean true Clean up localStorage after push.
useDynamicThankYou boolean true Learn redirect URLs from AJAX. Use static thankYouPages if false.
pushThankYouImmediatelyIfUnknown boolean true Push TY pre-redirect if redirect URL can’t be detected (useful for cross-domain TY).
thankYouPages string[] Static path snippets when not using dynamic detection.
maxTyPathsPerForm number 10 How many learned TY paths to keep per form.

dataLayer events

Submit

Fires immediately on successful AJAX response.

{
  event: "elementor_form_submit",
  user_data: { ...fields, form_id, post_id, first_name, last_name }
}

Thank-You

Fires on the actual thank-you page (dynamic) or pre-redirect (fallback).

{
  event: "elementor_form_thank_you",
  user_data: { ...same as submit payload }
}

Use these events as GTM triggers to send GA4 / Google Ads / Meta conversions and enhanced conversions.

About the Author

Alif Mahmud — Freelancer Data-Driven Marketer & Web Analytics Expert.
I build reliable tracking systems with Google Tag Manager, GA4, Conversion APIs, and custom JavaScript for e-commerce and lead-gen brands.

MIT License. Attribution appreciated — “tracking setup by: alifmahmud.com”.