Skip to content

Conversation

@enejb
Copy link
Member

@enejb enejb commented Nov 6, 2025

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:

  • Add a new feedback field that we store and return the date in seconds.
  • Start recording the data as soon as the user focuses in to the form. And record the time when they submit the form.
  • Store the data on the feedback class.
  • Add the data to the end point so that we can display it to the user when they view it.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

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.

@enejb enejb requested review from a team and Copilot November 6, 2025 06:06
@enejb enejb added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. [Status] Needs Testing We need to add this change to the testing call for this month's release [Package] Forms labels Nov 6, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the add/forms-submit-timer branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/forms-submit-timer

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Feature] Contact Form [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels Nov 6, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

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:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: December 2, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link
Contributor

Copilot AI left a 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.

Comment on lines +469 to +479
// 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;
}
}
}
Copy link

Copilot AI Nov 6, 2025

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.

Copilot uses AI. Check for mistakes.
'type' => array( 'integer', 'null' ),
'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array(
'sanitize_callback' => 'absint',
Copy link

Copilot AI Nov 6, 2025

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.

Suggested change
'sanitize_callback' => 'absint',

Copilot uses AI. Check for mistakes.
@jp-launch-control
Copy link

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/modules/form/view.js 0/283 (0.00%) 0.00% 10 💔
projects/packages/forms/src/contact-form/class-contact-form-endpoint.php 767/895 (85.70%) 0.18% 0 💚
projects/packages/forms/src/contact-form/class-contact-form.php 835/1208 (69.12%) 0.03% 0 💚
projects/packages/forms/src/contact-form/class-feedback.php 653/687 (95.05%) 0.03% 0 💚

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Contact Form [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] Needs Review This PR is ready for review. [Status] Needs Testing We need to add this change to the testing call for this month's release [Tests] Includes Tests [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants