Feature: Form Infrastructure & Compatibility#227
Conversation
…orms registry and tracking
|
@alaca thanks for the PR! Could you please fill out the PR template with description, changelog, and credits information so that we can properly review and merge this? |
There was a problem hiding this comment.
Pull request overview
This PR introduces stable per-form analytics identity for the block-based Mailchimp signup form, enabling analytics attribution per individual form instance (not just per list) and creating a registry table to map form IDs to human-readable titles for future dashboard labeling.
Changes:
- Adds
formId(UUID) andformTitleblock attributes, generating a UUID on block mount and exposing “Form name” in the editor sidebar. - Wires
form_idthrough front-end view tracking and form submissions (markup hidden input + AJAX tracking payload + analytics increment methods). - Adds a new forms registry table and a
save_postsync that upserts discovered forms into that table.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/cypress/e2e/block.test.js | Adds E2E coverage asserting stable data-form-id, hidden input wiring, view ping inclusion, and registry row existence. |
| mailchimp.php | Boots the new forms registry class during plugin load. |
| mailchimp_upgrade.php | Adds table creation routine for the new forms registry schema via plugins_loaded. |
| includes/class-mailchimp-forms-registry.php | Introduces the forms registry table schema, UUID sanitization, and save_post upsert syncing. |
| includes/class-mailchimp-form-submission.php | Includes form_id from POST in the “submission success” action for downstream analytics tracking. |
| includes/class-mailchimp-analytics-data.php | Reads/sanitizes form_id for view tracking and submissions; passes it into analytics increments. |
| includes/blocks/mailchimp/markup.php | Renders data-form-id and a hidden mailchimp_sf_form_id input when a valid UUID is present. |
| includes/blocks/mailchimp/edit.js | Generates stable UUID on mount and adds an Analytics panel with “Form name” control. |
| includes/blocks/mailchimp/block.json | Declares new formId and formTitle attributes. |
| assets/js/mailchimp.js | Sends form_id with the view tracking request and dedupes tracking by (listId, formId) instead of list-only. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Fall back to the form header when no title is set. | ||
| $title = $attrs['formTitle'] ?? ''; | ||
| $title = '' !== $title ? $title : ( $attrs['header'] ?? '' ); | ||
| $forms[ $form_id ] = sanitize_text_field( $title ); | ||
| } |
| created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| cy.intercept('POST', '**/admin-ajax.php').as('ajax'); | ||
| cy.visit(`/?p=${postId}`); | ||
|
|
||
| // Rendered form carries a UUID data-form-id and a matching hidden input. | ||
| cy.get('.mc_signup_form') | ||
| .should('have.attr', 'data-form-id') | ||
| .and('match', uuid); | ||
|
|
||
| cy.get('.mc_signup_form') | ||
| .invoke('attr', 'data-form-id') | ||
| .then((formId) => { | ||
| cy.get('input[name="mailchimp_sf_form_id"]').should('have.value', formId); | ||
|
|
||
| // The view ping includes the form_id. | ||
| cy.wait('@ajax').then((interception) => { | ||
| expect(interception.request.body).to.include('mailchimp_sf_track_form_view'); | ||
| expect(interception.request.body).to.include(formId); | ||
| }); |
iamdharmesh
left a comment
There was a problem hiding this comment.
Thanks for the PR @alaca. This looks great overall. However, it is worth looking at things flagged by the copilot and 1 newly added failing E2E test. Otherwise, we are good to go once it is resolved.
Description of the Change
Gives each block-based Mailchimp signup form a stable identity so analytics can be attributed per form instead of only per list.
When a Mailchimp block is added, the editor assigns it a permanent formId (UUID) and an editable "Form name". That ID is rendered into the form, sent with the view-tracking ping and the submission, and stored in a new
wp_mailchimp_sf_formsregistry table so the dashboard can label per-form data later.Closes #220
How to test the Change
data-form-id="<uuid>"and a hidden<input name="mailchimp_sf_form_id">with the same value.SELECT * FROM wp_mailchimp_sf_forms, there's a row for the form, titled from the "Form name" fielddata-form-idvalue is unchanged.wp_mailchimp_sf_forms.Changelog Entry
Credits
Props @username, @username2, ...
Checklist: