Files
web/packages/common/tracking/form.ts
Hrishikesh Vaipurkar 8e333cc7fd Merged in chore/SW-3379-move-useformtracking-to-common (pull request #2754)
chore(SW-3379): Moved useFormTracking to common

* chore(SW-3379): Moved useFormTracking to common


Approved-by: Anton Gunnarsson
2025-09-03 12:42:27 +00:00

104 lines
2.3 KiB
TypeScript

import { trackEvent } from "./base"
export type FormType = "checkout" | "signup"
export function trackFormInputStarted(type: FormType, nameSuffix?: string) {
if (type === "checkout") {
trackEvent({
event: "formStart",
form: {
action: "checkout form start",
name: "checkout enter detail" + nameSuffix,
type: type,
},
})
} else if (type === "signup") {
trackEvent({
event: "formStart",
form: {
action: "signup form start",
name: "member registration" + nameSuffix,
type: type,
},
})
}
}
export function trackFormAbandonment(
type: FormType,
lastAccessedField: string,
nameSuffix?: string
) {
if (type === "checkout") {
trackEvent({
event: "formAbandonment",
form: {
action: "checkout form abandonment",
name: "checkout enter detail" + nameSuffix,
type: type,
lastAccessedField,
},
})
} else if (type === "signup") {
trackEvent({
event: "formAbandonment",
form: {
action: "signup form abandonment",
name: "member registration" + nameSuffix,
type: type,
lastAccessedField,
},
})
}
}
export function trackFormValidationError(
type: FormType,
errorMessage: string,
nameSuffix?: string
) {
if (type === "checkout") {
trackEvent({
event: "formError",
form: {
action: "checkout form error",
name: "checkout enter detail" + nameSuffix,
type: type,
errorMessage,
},
})
} else if (type === "signup") {
trackEvent({
event: "formError",
form: {
action: "signup form error",
name: "member registration" + nameSuffix,
type: type,
errorMessage,
},
})
}
}
export function trackFormCompletion(type: FormType, nameSuffix?: string) {
if (type === "checkout") {
trackEvent({
event: "formCompletion",
form: {
action: "checkout form completion",
name: "checkout enter detail" + nameSuffix,
type: type,
},
})
} else if (type === "signup") {
trackEvent({
event: "formCompletion",
form: {
action: "signup form completion",
name: "member registration" + nameSuffix,
type: type,
},
})
}
}