Skip to content

Feature: Form Infrastructure & Compatibility#227

Open
alaca wants to merge 7 commits into
developfrom
feature/220-form-identity
Open

Feature: Form Infrastructure & Compatibility#227
alaca wants to merge 7 commits into
developfrom
feature/220-form-identity

Conversation

@alaca

@alaca alaca commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

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_forms registry table so the dashboard can label per-form data later.

Closes #220

How to test the Change

  • Add a Mailchimp block to a new post and publish.
  • View the post and inspect the :
  • it has data-form-id="<uuid>" and a hidden <input name="mailchimp_sf_form_id"> with the same value.
  • Run wp db query SELECT * FROM wp_mailchimp_sf_forms, there's a row for the form, titled from the "Form name" field
  • Reload the post and confirm the data-form-id value is unchanged.
  • Edit the block's Form name in the sidebar, save, and confirm the title updates in wp_mailchimp_sf_forms.

Changelog Entry

Credits

Props @username, @username2, ...

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@github-actions github-actions Bot added this to the 2.2.0 milestone Jun 30, 2026
@github-actions github-actions Bot added the needs:feedback This requires reporter feedback to better understand the request. label Jun 30, 2026
@github-actions

Copy link
Copy Markdown

@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?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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) and formTitle block attributes, generating a UUID on block mount and exposing “Form name” in the editor sidebar.
  • Wires form_id through 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_post sync 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.

Comment on lines +130 to +134
// 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 );
}
Comment on lines +58 to +59
created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
Comment thread includes/class-mailchimp-forms-registry.php
Comment on lines +46 to +63
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 iamdharmesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

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

Labels

needs:feedback This requires reporter feedback to better understand the request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Form Infrastructure & Compatibility

3 participants