Search by

concept7 / statamic-data-layer-connector

concept7

Push Google Tag Manager dataLayer events after Statamic form submissions, configured per form in the Control Panel.

Package info

github.com/concept7/statamic-data-layer-connector

Type:statamic-addon

pkg:composer/concept7/statamic-data-layer-connector

Statistics

Installs: 60

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.0 2026-12-03 14:53 UTC

This package is auto-updated.

Last update: 2026-12-03 14:54:20 UTC


README

Push form submissions to Google Tag Manager

Push Google Tag Manager dataLayer events after Statamic form submissions. Marketers configure the events per form in the Control Panel, without touching templates.

The addon adds a Data Layer connector to Statamic's form connections (Forms → your form → Connect), next to Email, Webhook and the Forms Pro integrations.

Requirements

  • PHP 8.4+
  • Statamic 6.44+

Installation

composer require concept7/statamic-data-layer-connector

Add the {{ datalayer }} tag once to your layout. Put it inside <body>, inside {{ nocache }}, and after your Google Tag Manager or consent snippet:

<body>
    {{# Google Tag Manager / cookie consent snippet #}}

    {{ nocache }}
        {{ datalayer }}
    {{ /nocache }}

    ...
</body>

Placing it after the consent snippet keeps the Consent Mode default (gtag('consent', 'default', …)) ahead of your events. The push itself waits for the window load event: consent tools such as Cookie Notice and Cookiebot send their gtag('consent', 'update', …) for a returning visitor before then, so GA4 and Ads receive the event with the visitor's actual consent. The tag only pushes to window.dataLayer; whether tags fire stays up to Google Tag Manager and the visitor's consent.

Content Security Policy

The tag prints an inline <script>. Under a policy without 'unsafe-inline', it needs a nonce. The tag takes the first one it finds:

  1. the nonce parameter: {{ datalayer nonce="..." }};
  2. Laravel's Vite::cspNonce(), which any CSP setup can fill with Vite::useCspNonce();
  3. the csp-nonce binding of spatie/laravel-csp, so that package needs no configuration beyond CSP_NONCE_ENABLED=true.

Setting up events

A visitor submits a form, the connector builds the event, the next page pushes it to the dataLayer

Open a form in the Control Panel, go to Connect and choose Data Layer. Each event you add is one dataLayer.push():

  • Event name: the name a Custom Event trigger in Google Tag Manager listens for.
  • Payload: rows of key → value. Type @ in a value to insert a form field, or one of the system values Submission ID and Form handle. Plain text is pushed as typed.
    • Type: Text or Number. A number row is pushed as a number, and left out when the value is not numeric.
    • Hash: pushes the SHA-256 hash of the lowercased, trimmed value. Off by default, so an @email value is pushed as entered.
    • A key with dots becomes a nested object: user_data.sha256_email_address → { "user_data": { "sha256_email_address": "…" } }.
  • Conditions: push the event only when the submission matches, for example when Brochure type equals By post. Disable an event with its toggle.

Users need permission to configure forms to edit connections.

Result

After a successful submit, the visitor lands on the form's redirect page, or back on the form's page when there is none. On a multi-page form (Forms Pro), this happens after the last page only. That page view renders:

<script>
    window.dataLayer = window.dataLayer || [];
    window.addEventListener('load', () => window.dataLayer.push({"event":"brochure_request","email":"jane@example.com","gclid":"Cj0KCQ…"}));
</script>

The events are flashed to the session, so a refresh or back navigation does not push them again. A page that pushes events is never stored in the static cache.

Not supported

  • Full static caching (full strategy). Use no static caching or the half strategy.
  • AJAX submissions. Forms submitted with JavaScript get a JSON response and no redirect, so no event is pushed. Push those yourself from your submit handler.
  • External redirects set with Form::redirect(), including a redirect to another site of a multisite. The visitor leaves the site before any page view could push the event.
  • Forms Pro Automagic Forms success pages. They do not use your layout.
  • Submissions finalized from the Control Panel (for example Mark as not spam) never push.

Testing

composer install
vendor/bin/pest

License

Data Layer Connector is commercial software. It requires a license from the Statamic Marketplace for use in production; local development is free. See LICENSE.md.