import type { Field } from 'payload' /** * Panel fields that let an EDITOR configure a form's analytics event — the GTM * `dataLayer` push fired on successful submit — without any code change. Add * them to the Forms collection via the plugin's `formOverrides`: * * ipalKit({ * forms: { * formOverrides: { * fields: ({ defaultFields }) => [...defaultFields, ...buildFormAnalyticsFields()], * }, * }, * }) * * The front reads this config and emits the event automatically via * `formAnalyticsOnSuccess` (see forms.md) — so adding a tracked form, or * changing its event name/params, is panel-only. The GTM side (the Lead/Pixel * tag, its trigger and consent gate) stays in GTM, which is itself a no-code * panel for tags. */ export function buildFormAnalyticsFields(): Field[] { return [ { name: 'analytics', type: 'group', admin: { description: { en: 'Sent to Google Tag Manager after a successful submission.', pl: 'Wysyłane do Google Tag Manager po udanym wysłaniu formularza.', }, }, fields: [ { name: 'event', type: 'text', admin: { description: { en: 'Leave empty to send nothing.', pl: 'Zostaw puste, aby nic nie wysyłać.' }, }, defaultValue: 'form_submit', label: { en: 'Event name', pl: 'Nazwa zdarzenia' }, }, { name: 'params', type: 'array', admin: { description: { en: 'A value starting with $ is taken from a form field, e.g. $topic.', pl: 'Wartość zaczynająca się od $ pochodzi z pola formularza, np. $topic.', }, }, fields: [ { name: 'key', type: 'text', label: { en: 'Key', pl: 'Klucz' }, required: true }, { name: 'value', type: 'text', label: { en: 'Value', pl: 'Wartość' }, required: true }, ], label: { en: 'Event parameters', pl: 'Parametry zdarzenia' }, labels: { plural: { en: 'Parameters', pl: 'Parametry' }, singular: { en: 'Parameter', pl: 'Parametr' } }, }, ], label: { en: 'Analytics event', pl: 'Zdarzenie analityki' }, }, ] }