Type alias FormLifecycleEvent

FormLifecycleEvent: {
    formId: string;
    formName: string;
    type: typeof Shown;
} | {
    formId: string;
    formName: string;
    type: typeof Dismissed;
} | {
    buttonLabel: string;
    deepLinkUrl: string;
    formId: string;
    formName: string;
    type: typeof CtaClicked;
}

Discriminated union representing a form lifecycle event.

Each variant carries contextual data about the form, and the type field serves as the discriminant. Use a switch on event.type to narrow the type and access variant-specific fields like buttonLabel and deepLinkUrl.

Example usage:

Klaviyo.registerFormLifecycleHandler((event) => {
switch (event.type) {
case FormLifecycleEventType.Shown:
console.log(`Form shown: ${event.formId}`);
break;
case FormLifecycleEventType.Dismissed:
console.log(`Form dismissed: ${event.formId}`);
break;
case FormLifecycleEventType.CtaClicked:
console.log(`CTA clicked: ${event.buttonLabel}, deep link: ${event.deepLinkUrl}`);
break;
}
});

Type declaration

  • formId: string
  • formName: string
  • type: typeof Shown

Type declaration

  • formId: string
  • formName: string
  • type: typeof Dismissed

Type declaration

  • buttonLabel: string

    Label of the tapped CTA button. May be an empty string when the button has no visible label configured.

  • deepLinkUrl: string

    Deep link URL configured for the tapped CTA. Always present and non-empty — this event is not emitted when no deep link is configured.

  • formId: string
  • formName: string
  • type: typeof CtaClicked