Skip to content

feat(integrations): implement profile metadata (identity, registration, engagement)#4624

Open
chickenn00dle wants to merge 4 commits intotrunkfrom
feat/add-profile-metadata
Open

feat(integrations): implement profile metadata (identity, registration, engagement)#4624
chickenn00dle wants to merge 4 commits intotrunkfrom
feat/add-profile-metadata

Conversation

@chickenn00dle
Copy link
Copy Markdown
Contributor

@chickenn00dle chickenn00dle commented Apr 2, 2026

All Submissions:

Changes proposed in this Pull Request:

Implements get_metadata() for the three profile contact metadata classes that were previously returning empty arrays: Identity, Registration, and Engagement.

Identity (7 fields):

  • first_name, last_name, email — from WordPress user data
  • Account — WordPress user ID
  • User_Role — first WordPress role assigned to the user
  • verified — whether the reader has verified their email (from np_reader_email_verified user meta)
  • Connected_Account — SSO provider used to register, if any (from np_reader_connected_account user meta)

Registration (6 fields):

  • Registration_Date — account creation date, formatted as Y-m-d H:i:s
  • Registration_Page — URL where the reader registered (from user meta)
  • Registration_Strategy — how the reader registered: newsletter, checkout, registration-wall, etc. (from user meta)
  • Registration_UTM_Source, Registration_UTM_Medium, Registration_UTM_Campaign — parsed from the registration page URL query parameters

Engagement (10 fields):

  • First_Visit_Date, Last_Active — from the Reader Data store (JS millisecond timestamps converted to Y-m-d H:i:s)
  • Paywall_Hits — integer count from the Reader Data store
  • Favorite_Categories — category IDs from the Reader Data store, converted to a comma-separated string of category names
  • Payment_Page — URL of the most recent checkout page (from the latest completed WC order's _newspack_referer meta)
  • Payment_UTM_Source, Payment_UTM_Medium, Payment_UTM_Campaign — UTM data from the latest completed WC order
  • Total_Paid — lifetime total spent via WC_Customer::get_total_spent()

Closes https://linear.app/a8c/issue/NPPD-1389/implement-profile-fields-identity-engagement-registration

How to test the changes in this Pull Request:

  1. Enable the new metadata system in wp-config.php:
    define( 'NEWSPACK_LOG_LEVEL', 3 );
    define( 'NEWSPACK_SYNC_METADATA_VERSION', '1.0' );
    define( 'NEWSPACK_INTEGRATIONS_SETTINGS_ENABLED', true );
  2. Navigate to Audience > Integrations > ESP and confirm the Identity, Registration, and Engagement fields appear in the outgoing metadata section
  3. Check all fields and save, confirm they persist on reload
  4. Register a new reader on a page with UTM parameters (e.g. ?utm_source=test&utm_medium=email&utm_campaign=spring)
  5. Check the logs — verify registration metadata includes the date, page, strategy, and UTM values
  6. As that reader, browse several articles and trigger a paywall hit
  7. Make a WooCommerce subscription or donation purchase
  8. Verify that engagement fields (First_Visit_Date, Last_Active, Paywall_Hits, Favorite_Categories, Payment_Page, Payment_UTM_*, and Total_Paid) are synced
  9. Run the unit tests:
    n test-php --group=Identity_Metadata,Registration_Metadata,Engagement_Metadata

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@chickenn00dle chickenn00dle force-pushed the feat/add-profile-metadata branch from 2e3b777 to c11dc18 Compare April 2, 2026 19:56
@chickenn00dle chickenn00dle force-pushed the feat/add-profile-metadata branch from 973af86 to c2dab85 Compare April 2, 2026 20:42
@chickenn00dle chickenn00dle marked this pull request as ready for review April 2, 2026 21:40
@chickenn00dle chickenn00dle requested a review from a team as a code owner April 2, 2026 21:40
Copilot AI review requested due to automatic review settings April 2, 2026 21:40
Copy link
Copy Markdown
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

Implements real metadata export for Reader Activation “profile” contact metadata by populating Identity, Registration, and Engagement metadata classes, and adds unit tests to validate the new behaviors.

Changes:

  • Implemented get_metadata() for Identity, Registration, and Engagement contact metadata classes (including new registration UTM persistence).
  • Updated sync metadata class list to use the new metadata sections and improved integration-specific sync logging.
  • Added unit tests covering Identity/Registration/Engagement metadata output.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/unit-tests/class-test-registration-metadata.php Adds unit coverage for Registration metadata fields (date, page, strategy, UTM).
tests/unit-tests/class-test-identity-metadata.php Adds unit coverage for Identity fields (name/email/account/role/verified/connected account).
tests/unit-tests/class-test-engagement-metadata.php Adds unit coverage for Engagement fields (timestamps, paywall hits, favorite categories, payment fields, total paid).
src/blocks/reader-registration/index.php Adjusts referer URL handling for reCAPTCHA and stored registration metadata.
includes/reader-activation/sync/contact-metadata/class-registration.php Implements Registration metadata (including UTM meta lookup).
includes/reader-activation/sync/contact-metadata/class-identity.php Implements Identity metadata from WP user fields and user meta.
includes/reader-activation/sync/contact-metadata/class-engagement.php Implements Engagement metadata from Reader Data and WooCommerce order/customer data.
includes/reader-activation/sync/class-metadata.php Switches non-legacy metadata class list to Identity/Registration/Engagement + others.
includes/reader-activation/sync/class-contact-sync.php Moves debug logging into integration loop and logs integration-prepared payloads.
includes/reader-activation/sync/class-contact-metadata.php Updates date formatting docblock to match current formatter behavior.
includes/reader-activation/class-reader-activation.php Captures/saves registration UTM params; minor formatting change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@chickenn00dle chickenn00dle added the [Status] Needs Review The issue or pull request needs to be reviewed label Apr 6, 2026
Copy link
Copy Markdown
Contributor

@leogermani leogermani left a comment

Choose a reason for hiding this comment

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

Looks great. I left one minor comment/request and have one question.

I see that you are now storing the registration UTMs as user meta. This is nice, but should we add a fallback and look for utms in the URL if the meta is not there? I'm thinking on the situation of syncing users that registered before this change. Not sure if we need something similar for payment_page utm...

'email' => $this->user->user_email,
'Account' => (string) $this->user->ID,
'User_Role' => ! empty( $roles ) ? reset( $roles ) : '',
'verified' => (bool) \get_user_meta( $this->user->ID, Reader_Activation::EMAIL_VERIFIED, true ),
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.

Let's use Reader_Activation::is_reader_verified instead?

@github-actions github-actions bot added the [Status] Needs Changes or Feedback The issue or pull request needs action from the original creator label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Changes or Feedback The issue or pull request needs action from the original creator [Status] Needs Review The issue or pull request needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants