Skip to content

feat(analytics-browser): add shouldTrackSubmit for custom form validation#1500

Merged
Mercy811 merged 8 commits intomainfrom
AMP-147416-form-submissions-fired-on-empty-form-submission
Jan 23, 2026
Merged

feat(analytics-browser): add shouldTrackSubmit for custom form validation#1500
Mercy811 merged 8 commits intomainfrom
AMP-147416-form-submissions-fired-on-empty-form-submission

Conversation

@Mercy811
Copy link
Copy Markdown
Contributor

@Mercy811 Mercy811 commented Jan 19, 2026

Summary

Adds a new shouldTrackSubmit callback option to form interaction config to control when [Amplitude] Form Submitted events are tracked. This is particularly useful for forms with the novalidate attribute where teams want full control over validation before tracking. Previously, [Amplitude] Form Submitted was fired on every form submit event regardless of form validation state.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

Note

Introduces configurable form submit gating.

  • Adds FormInteractionsOptions.shouldTrackSubmit type in analytics-core and exports it; updates BrowserConfig/AutocaptureOptions to allow formInteractions: boolean | FormInteractionsOptions.
  • Implements getFormInteractionsConfig and integrates it in the form interaction plugin to conditionally track [Amplitude] Form Submitted (checks SubmitEvent, handles errors, keeps [Amplitude] Form Started logic unchanged).
  • Extends tests for default-tracking and form interaction plugin covering allow/deny/error paths; updates test server page to novalidate and demonstrates custom validation usage; minor experiment test adds version assertion.

Written by Cursor Bugbot for commit b6cda67. Configure here.

@Mercy811
Copy link
Copy Markdown
Contributor Author

bugbot run

@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Jan 19, 2026

Add FormInteractionTracking gating of [Amplitude] Form Submitted via DefaultTrackingOptions.formInteractions.shouldTrackSubmit and expose FormInteractionsOptions types

Introduce a typed FormInteractionsOptions with shouldTrackSubmit(event) and wire it into the form interaction enrichment plugin, including a getFormInteractionsConfig helper and updated event handler signatures; add tests and export types.

🖇️ Linked Issues

Addresses AMP-147416 by allowing invalid or empty submissions to be excluded from “Form Submitted” via a callback; contributes to the ongoing maintenance tracked under AMP-95968 and AMP-93905.

📍Where to Start

Start in the plugin setup and submit handler in packages/analytics-browser/src/plugins/form-interaction-tracking.ts, then review the config helper in packages/analytics-browser/src/default-tracking.ts.


Macroscope summarized b6cda67.

@Mercy811 Mercy811 changed the title Amp 147416 form submissions fired on empty form submission feat(analytics-browser): add shouldTrackSubmit for custom form validation Jan 19, 2026
cursor Bot pushed a commit to amplitude/amplitude-docs that referenced this pull request Jan 19, 2026
…king

- Update formInteractions config to accept boolean | FormInteractionsOptions
- Add documentation for shouldTrackSubmit callback to control form submit event tracking
- Include examples for custom validation and form filtering use cases
- Particularly useful for forms with novalidate attribute

Relates to: amplitude/Amplitude-TypeScript#1500

Co-authored-by: xinyi.ye <xinyi.ye@amplitude.com>
cursor[bot]

This comment was marked as outdated.

@Mercy811
Copy link
Copy Markdown
Contributor Author

bugbot run

Comment thread packages/analytics-browser/src/plugins/form-interaction-tracking.ts Outdated
Comment thread packages/analytics-browser/src/plugins/form-interaction-tracking.ts Outdated
@Mercy811
Copy link
Copy Markdown
Contributor Author

bugbot run

Comment thread packages/analytics-browser/src/plugins/form-interaction-tracking.ts Outdated
cursor[bot]

This comment was marked as outdated.

…ng.ts

Co-authored-by: macroscopeapp[bot] <170038800+macroscopeapp[bot]@users.noreply.github.com>
Comment thread packages/analytics-browser/src/plugins/form-interaction-tracking.ts
…ion' of github.com:amplitude/Amplitude-TypeScript into AMP-147416-form-submissions-fired-on-empty-form-submission
@Mercy811
Copy link
Copy Markdown
Contributor Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Copy link
Copy Markdown
Collaborator

@daniel-graham-amplitude daniel-graham-amplitude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

@Mercy811 Mercy811 merged commit 1d76745 into main Jan 23, 2026
11 checks passed
@Mercy811 Mercy811 deleted the AMP-147416-form-submissions-fired-on-empty-form-submission branch January 23, 2026 23:09
Mercy811 added a commit to amplitude/amplitude-docs that referenced this pull request Jan 26, 2026
* docs: add shouldTrackSubmit callback option for form interaction tracking

- Update formInteractions config to accept boolean | FormInteractionsOptions
- Add documentation for shouldTrackSubmit callback to control form submit event tracking
- Include examples for custom validation and form filtering use cases
- Particularly useful for forms with novalidate attribute

Relates to: amplitude/Amplitude-TypeScript#1500

Co-authored-by: xinyi.ye <xinyi.ye@amplitude.com>

* docs: simplify form tracking examples to single use case

Co-authored-by: xinyi.ye <xinyi.ye@amplitude.com>

* Update minimum SDK version requirement for shouldTrackSubmit to 2.34.5

Co-authored-by: xinyi.ye <xinyi.ye@amplitude.com>

* Update minimum SDK version for shouldTrackSubmit to 2.34.0

Co-authored-by: xinyi.ye <xinyi.ye@amplitude.com>

* Add context about novalidate attribute and why shouldTrackSubmit is needed

Co-authored-by: xinyi.ye <xinyi.ye@amplitude.com>

* Update content/collections/browser_sdk/en/browser-sdk-2.md

Co-authored-by: JeffScattini-amplitude <jeff.scattini@amplitude.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: JeffScattini-amplitude <jeff.scattini@amplitude.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants