@teamnovu/nuxt-statamic-formbuilder 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "1.2.0",
7
+ "version": "1.3.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -2,6 +2,7 @@ import { useRuntimeConfig } from "#imports";
2
2
  import { useI18n } from "vue-i18n";
3
3
  import { computed, ref, toValue } from "vue";
4
4
  import { isDisplayOrSpacerField, isMultiValueField } from "../../types.js";
5
+ import { pushFormSubmissionDataLayer } from "../../utils/pushFormSubmissionDataLayer.js";
5
6
  import { submitStatamicForm } from "../../utils/submitStatamicForm.js";
6
7
  function flattenFields(form) {
7
8
  if ("fields" in form) {
@@ -52,6 +53,7 @@ export function useFormBuilder(formBuilderConfiguration, serverUrlOrOptions) {
52
53
  locale: locale.value
53
54
  });
54
55
  requestState.value = "success";
56
+ pushFormSubmissionDataLayer(formBuilderConfiguration);
55
57
  return result;
56
58
  } catch (error) {
57
59
  requestState.value = "error";
@@ -93,6 +93,8 @@ export type DefaultInputField = {
93
93
  export type defaultInputField = DefaultInputField;
94
94
  export type FormBuilderConfiguration = {
95
95
  handle: string;
96
+ /** CMS form title (Statamic GraphQL `title`). Used for analytics. */
97
+ title?: string | null;
96
98
  honeypot: string | null;
97
99
  rules: {
98
100
  [key: string]: string;
@@ -0,0 +1,11 @@
1
+ import type { FormBuilderConfiguration } from '../types.js';
2
+ export type FormSubmissionDataLayerEvent = {
3
+ event: 'form_submission';
4
+ form_id: string;
5
+ form_name: string;
6
+ };
7
+ /**
8
+ * Push a GTM-compatible form_submission event after a successful submit.
9
+ * No-op on the server and when `window` is unavailable.
10
+ */
11
+ export declare function pushFormSubmissionDataLayer(form: FormBuilderConfiguration): void;
@@ -0,0 +1,16 @@
1
+ function getDataLayer() {
2
+ const win = window;
3
+ win.dataLayer ??= [];
4
+ return win.dataLayer;
5
+ }
6
+ export function pushFormSubmissionDataLayer(form) {
7
+ if (typeof window === "undefined") {
8
+ return;
9
+ }
10
+ const event = {
11
+ event: "form_submission",
12
+ form_id: form.handle,
13
+ form_name: form.title ?? ""
14
+ };
15
+ getDataLayer().push(event);
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamnovu/nuxt-statamic-formbuilder",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Headless Nuxt form builder with Statamic submit adapter",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/teamnovu/nuxt-statamic-formbuilder#readme",