-
Notifications
You must be signed in to change notification settings - Fork 841
Forms: Add form fill duration to feedback #45786
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
base: trunk
Are you sure you want to change the base?
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
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.
Pull Request Overview
This PR adds form fill duration tracking to Jetpack forms, measuring the time from a user's first interaction with a form to submission. This feature provides valuable analytics data for form optimization.
- Tracks form fill duration in seconds from first user interaction to submission
- Persists duration data in feedback entries and exposes it via REST API
- Adds frontend JavaScript tracking and backend PHP support
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/plugins/jetpack/changelog/add-forms-submit-timer | Changelog entry for Jetpack plugin |
| projects/packages/forms/changelog/add-forms-submit-timer | Changelog entry for forms package |
| projects/packages/forms/src/contact-form/class-feedback.php | Adds form_fill_duration property and getter method |
| projects/packages/forms/src/contact-form/class-contact-form.php | Adds hidden input field and focusin event handler |
| projects/packages/forms/src/contact-form/class-contact-form-endpoint.php | Adds form_fill_duration to REST API schema and response |
| projects/packages/forms/src/modules/form/view.js | Implements JavaScript tracking logic for form interaction timing |
| projects/packages/forms/tests/php/contact-form/class-utility.php | Updates test utility to support form_fill_duration in test requests |
| projects/packages/forms/tests/php/contact-form/Feedback_Test.php | Adds test for form_fill_duration persistence |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Calculate and set the form fill duration before submission | ||
| if ( context.formFirstInteractionTime ) { | ||
| const duration = Math.round( ( Date.now() - context.formFirstInteractionTime ) / 1000 ); // Duration in seconds | ||
| const form = document.getElementById( 'jp-form-' + context.formHash ); | ||
| if ( form ) { | ||
| const durationField = form.querySelector( 'input[name="form_fill_duration"]' ); | ||
| if ( durationField ) { | ||
| durationField.value = duration; | ||
| } | ||
| } | ||
| } |
Copilot
AI
Nov 6, 2025
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.
The form fill duration is only calculated when context.useAjax is true (line 464). For non-AJAX form submissions, the duration field will remain at its default value of '0'. The duration calculation logic should be moved before the if ( context.useAjax ) check (after line 462) to ensure it works for both AJAX and non-AJAX submissions.
| 'type' => array( 'integer', 'null' ), | ||
| 'context' => array( 'view', 'edit', 'embed' ), | ||
| 'arg_options' => array( | ||
| 'sanitize_callback' => 'absint', |
Copilot
AI
Nov 6, 2025
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.
The sanitize_callback 'absint' will convert null values to 0, which is inconsistent with the schema type that allows null. This will prevent null values from being properly represented in the API response for older submissions. Consider using a custom sanitization callback that preserves null values or removing the sanitize_callback since the field is readonly and already sanitized during storage.
| 'sanitize_callback' => 'absint', |
Code Coverage SummaryCoverage changed in 4 files.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
This PR add a form fill duration to each of the form responses.
We start the timer when the user interacts with the for for the first time.
This is done so that we can track ow long the form take to fill out.
Proposed changes:
Other information:
Jetpack product discussion
See p1762390969490259-slack-C086RGTJT1D
Does this pull request change what data or activity we track or use?
Yes, we track how long it takes the user to submit the form.
Testing instructions:
Create a form.
Fill it out. Test this across browser and different devices. Also test out form fields such as file upload.
Notice that we have the data recorded as expected.