Added better support for GTM, improved accesibility

This commit is contained in:
2026-10-11 14:46:47 +02:00
parent fd6fb426b3
commit 6be783bc5a
53 changed files with 849 additions and 110 deletions
+24
View File
@@ -0,0 +1,24 @@
/**
* Pushes an event onto the GTM `window.dataLayer`. SSR-safe (no-op on the
* server), and tolerant of GTM not being present yet — the array is created so
* the event is buffered and picked up once GTM loads.
*
* The bridge between the form engine and GTM: fire a `form_submit` event after
* a successful submit so a Meta Pixel / GA "Lead" tag can trigger on it.
*
* import { pushDataLayer } from '@intecion/ipal-kit/client'
* const f = useContactForm({
* submitAction,
* onSuccess: (_r, v) => pushDataLayer('form_submit', { form_name: v.topic || 'kontakt' }),
* })
*
* The GTM "Lead" tag then reads `form_name` via a Data Layer Variable
* (`DLV – form_name`) and fires on the custom event `form_submit`. Consent still
* gates the tag in GTM (ad_storage) — this only emits the event.
*/
export function pushDataLayer(event: string, params: Record<string, unknown> = {}): void {
if (typeof window === 'undefined') return
const w = window as unknown as { dataLayer?: unknown[] }
w.dataLayer = w.dataLayer || []
w.dataLayer.push({ event, ...params })
}