-
Notifications
You must be signed in to change notification settings - Fork 61
Amp 149661 form abandoned #1563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
daniel-graham-amplitude
wants to merge
7
commits into
main
Choose a base branch
from
AMP-149661-form-abandoned
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c25e2a6
feat(analytics-browser): add Form Abandoned
daniel-graham-amplitude 8564a11
feat(analytics-browser): add Form Abandoned
daniel-graham-amplitude c10a323
fix: PW test fix
daniel-graham-amplitude c6c00ca
again
daniel-graham-amplitude d38c524
feat: gate abandoned behind experimental flag
daniel-graham-amplitude d11caac
pr refinements
daniel-graham-amplitude 4829e1c
again
daniel-graham-amplitude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
| import { test, expect } from '@playwright/test'; | ||
|
|
||
| const FORM_STARTED_EVENT = '[Amplitude] Form Started'; | ||
|
|
||
| test.describe('Form Interactions Page', () => { | ||
| let requests: any[] = []; | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| requests = []; | ||
| await page.route('https://api2.amplitude.com/2/httpapi', async (route) => { | ||
| const request = route.request(); | ||
| const postData = request.postData(); | ||
| if (postData) { | ||
| const data = JSON.parse(postData); | ||
| requests.push(data); | ||
| } | ||
| await route.continue(); | ||
| }); | ||
| }); | ||
|
|
||
| test('should track form started events', async ({ page }) => { | ||
| await page.goto('/form-interactions/form-interactions.html'); | ||
| await page.waitForLoadState('networkidle'); | ||
|
|
||
| // Trigger form started by changing a form field (first interaction) and then navigate away to trigger pagehide/beforeunload → form abandoned | ||
| await page.fill('#name', 'Test User'); | ||
| await page.fill('#email', 'test@example.com'); | ||
| // mock dispatch pagehide event | ||
| await page.evaluate(() => window.dispatchEvent(new Event('beforeunload'))); | ||
| await page.waitForTimeout(2000); | ||
|
|
||
| // Wait for the form started event to be sent | ||
| await expect(async () => { | ||
| const allEvents = requests.flatMap((r) => r.events || []).filter((e: any) => e.event_type !== '$identify'); | ||
| expect(allEvents.some((e: any) => e.event_type === FORM_STARTED_EVENT)).toBe(true); | ||
| }).toPass({ timeout: 5000 }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Form Interactions Test</title> | ||
| </head> | ||
| <body> | ||
| <h1>Form Interactions Test</h1> | ||
| <p>This page initializes Amplitude with autocapture.formInteractions enabled.</p> | ||
|
|
||
| <form name="contact" action="#" method="post"> | ||
| <p> | ||
| <label for="name">Name</label> | ||
| <input type="text" id="name" name="name"> | ||
| </p> | ||
| <p> | ||
| <label for="email">Email</label> | ||
| <input type="email" id="email" name="email"> | ||
| </p> | ||
| <p> | ||
| <label for="message">Message</label> | ||
| <textarea id="message" name="message"></textarea> | ||
| </p> | ||
| <p> | ||
| <button type="submit">Submit</button> | ||
| </p> | ||
| </form> | ||
|
|
||
| <script type="module"> | ||
| import * as amplitude from '@amplitude/analytics-browser'; | ||
|
|
||
| window.amplitude = amplitude; | ||
|
|
||
| amplitude.init(import.meta.env.VITE_AMPLITUDE_API_KEY, undefined, { | ||
| fetchRemoteConfig: false, | ||
| autocapture: { | ||
| pageViews: false, | ||
| sessions: false, | ||
| formInteractions: { | ||
| shouldTrackAbandoned: true, | ||
| }, | ||
| }, | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasFormAbandonednever resets, blocking repeated abandon trackingMedium Severity
hasFormAbandonedis set totrueintrackFormAbandonedbut is never reset tofalse. After an abandon event fires (e.g.,beforeunloadthat gets canceled by another handler, orpagehidewhen the page enters bfcache and is later restored), the flag permanently prevents any future Form Abandoned events. Meanwhile,hasFormChangedis reset tofalse, so a subsequent form change triggers a new Form Started event — creating an asymmetry where forms can be "started" multiple times but only "abandoned" once. Thechangehandler needs to resethasFormAbandonedwhen re-engaging with the form.Additional Locations (1)
packages/analytics-browser/src/plugins/form-interaction-tracking.ts#L103-L114