Skip to content

Newsletter: add Tracks analytics to settings page#47100

Open
dsas wants to merge 7 commits intotrunkfrom
dotcom-15397-ensure-tracking-events-are-in-place
Open

Newsletter: add Tracks analytics to settings page#47100
dsas wants to merge 7 commits intotrunkfrom
dotcom-15397-ensure-tracking-events-are-in-place

Conversation

@dsas
Copy link
Contributor

@dsas dsas commented Feb 12, 2026

Fixes DOTCOM-15397

Proposed changes:

  • Add Tracks analytics to the newsletter settings page to track user interactions
  • Track module toggle, setting changes, link clicks, and section saves
  • Include site type (simple, atomic, jetpack) on all events for segmentation
  • Initialize analytics with user data from Jetpack_Tracks_Client

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

peKye1-1Z1-p2

Does this pull request change what data or activity we track or use?

No - this consolidates existing tracking from the Jetpack and Calypso newsletter settings implementations into unified event names with the jetpack_newsletter_* prefix.

Testing instructions:

  • Enable the newsletter settings page filter: add_filter( 'jetpack_wp_admin_newsletter_settings_enabled', '__return_true' );
  • Go to Jetpack → Newsletter in wp-admin
  • Open browser DevTools Network tab and filter by pixel.wp.com
  • Interact with settings (toggle options, change values, click links, save sections)
  • Verify that Tracks events are being sent to pixel.wp.com with the expected event names and properties
  • Test on different site types if possible (Simple, Atomic, Jetpack) to verify site_type property

Use Tracks to track interactions on the newsletter settings page. Events
capture the module toggle, settings toggles, section saves and link
clicks. The type of site is recorded on all events.

This breaks compatibility of event names for both the calypso and
previous jetpack setting screens. The former as this is no longer
calypso and is applicable more widely than just simple sites, and the
latter as it uses a very generic naming system that is specific to the
jetpack settings screen.
Copilot AI review requested due to automatic review settings February 12, 2026 20:44
@dsas dsas added the [Status] Needs Review This PR is ready for review. label Feb 12, 2026
@dsas dsas self-assigned this Feb 12, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

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 or WordPress.com Site Helper), and enable the dotcom-15397-ensure-tracking-events-are-in-place branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack dotcom-15397-ensure-tracking-events-are-in-place
bin/jetpack-downloader test jetpack-mu-wpcom-plugin dotcom-15397-ensure-tracking-events-are-in-place

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
Copy link
Contributor

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 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!

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 Tracks analytics instrumentation to the Newsletter settings wp-admin UI so user interactions can be measured consistently across site types (simple/atomic/jetpack).

Changes:

  • Introduce a Newsletter settings analytics helper (analytics.ts) and add site_type to tracked events.
  • Track key interactions: module toggle, specific setting changes, section saves, and relevant link/button clicks.
  • Wire Tracks identity data from PHP (Jetpack_Tracks_Client) and enqueue the Tracks script; add @automattic/jetpack-analytics dependency.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
projects/packages/newsletter/src/settings/types.ts Adds tracksUserData to the PHP-provided settings typings.
projects/packages/newsletter/src/settings/sections/welcome-email-section.tsx Tracks “welcome email” section save clicks with site_type.
projects/packages/newsletter/src/settings/sections/subscriptions-section.tsx Tracks subscriptions section saves; passes siteType into editor-link toggles.
projects/packages/newsletter/src/settings/sections/paid-newsletter-section.tsx Tracks paid plans CTA clicks and varies button text based on plan state.
projects/packages/newsletter/src/settings/sections/newsletter-section.tsx Tracks newsletter module toggle and “manage subscribers” link clicks.
projects/packages/newsletter/src/settings/sections/newsletter-categories-section.tsx Tracks newsletter categories section save clicks.
projects/packages/newsletter/src/settings/sections/email-sender-settings-section.tsx Tracks sender settings section save clicks.
projects/packages/newsletter/src/settings/index.tsx Initializes analytics, tracks auto-saved setting changes, and passes plan state into Paid section.
projects/packages/newsletter/src/settings/components/toggle-with-link.tsx Adds a hook to track “preview and edit” link clicks via onLinkClick.
projects/packages/newsletter/src/settings/analytics.ts New centralized tracking helpers and getSiteType() utility.
projects/packages/newsletter/src/class-settings.php Enqueues Tracks script and exposes Tracks identity data to JS.
projects/packages/newsletter/package.json Adds @automattic/jetpack-analytics dependency.
projects/packages/newsletter/changelog/dotcom-15397-ensure-tracking-events-are-in-place Adds changelog entry for analytics addition.
pnpm-lock.yaml Locks the new workspace dependency.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

@jp-launch-control
Copy link

jp-launch-control bot commented Feb 12, 2026

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/newsletter/src/class-settings.php 0/112 (0.00%) 0.00% 2 ❤️‍🩹

Full summary · PHP report · JS report

Copilot AI review requested due to automatic review settings February 12, 2026 22:38
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

Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Replace manually maintained BOOLEAN_SETTINGS and STRING_SETTINGS arrays
with runtime typeof checks. New settings are now automatically tracked
based on their value type without requiring code changes.
@@ -0,0 +1,129 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm slightly unsure about this big utility file.

AFAICS, all these track* functions, with the exception of trackSectionSave, are used only once, and with scant opportunities of being reused elsewhere.

I'd probably just call analytics.tracks.recordEvent directly from the various event handlers, leaving just getSiteType as a shared function — which then might be nice to move somewhere it can be used across the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, I was a bit on the fence about the big file myself.

getSiteType can be temporarily shifted elsewhere. I spotted an opportunity for some more code reuse across the package yesterday but didn't want to bloat this pr.

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICS similar getSiteTypes are present in two other packages:

/**
* Get the site type from environment
*
* @return Site type
*/
function getSiteType() {
if ( isWoASite() ) {
return 'atomic';
}
if ( isSimpleSite() ) {
return 'simple';
}
return 'jetpack';
}

const getSiteType = () => {
if ( isWoASite() ) {
return 'atomic';
}
if ( isSimpleSite() ) {
return 'simple';
}
return 'jetpack';
};

I don't know whether those isWoASite and isSimpleSite are available in our case, but not having to rely on jetpackSettings would let us call the function directly where it's needed, instead of prop-drilling. 🤔

didn't want to bloat this pr

Agreed! IMHO let's just see if there are opportunities to simplify this package, and consider extracting the function elsewhere in a nice-to-have follow up.

FWIW my comment here is mostly about having these events searchable directly, rather than finding the function first, and then having to look for where they are used. Very minor, anyway! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to extract this getSiteType anywhere, i'll just throw it in utilities or something for now.

I'll open a separate PR to make better use of the assets php package and script-data js package, they have utility functions like this, and already provide some of the data that window.jetpackNewsletterSettings does.

Replace single-use tracking wrapper functions with direct
analytics.tracks.recordEvent calls. Keep only getSiteType
as a utility function in the renamed utils.ts file.
Copilot AI review requested due to automatic review settings February 13, 2026 16:57
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

Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

// Initialize analytics with user data
useEffect( () => {
const tracksUserData = jetpackSettings?.tracksUserData;
if ( tracksUserData && typeof tracksUserData === 'object' ) {
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The check typeof tracksUserData === 'object' will incorrectly pass if tracksUserData is null (since typeof null === 'object' in JavaScript). While the PHP function returns false rather than null, it's better to be defensive. Consider using a more explicit check like tracksUserData && tracksUserData !== false or restructuring the condition to be more explicit about what's expected.

Copilot uses AI. Check for mistakes.
// Initialize analytics with user data
useEffect( () => {
const tracksUserData = jetpackSettings?.tracksUserData;
if ( tracksUserData && typeof tracksUserData === 'object' ) {
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The analytics initialization should verify that the required properties exist before calling analytics.initialize(). Following the pattern used in other parts of the codebase (e.g., projects/js-packages/idc/tools/tracking.jsx), add checks for userid and username properties using Object.hasOwn() to ensure they exist before passing them to the initialization function. This prevents potential runtime errors if the tracksUserData object structure is unexpected.

Suggested change
if ( tracksUserData && typeof tracksUserData === 'object' ) {
if (
tracksUserData &&
typeof tracksUserData === 'object' &&
Object.hasOwn( tracksUserData, 'userid' ) &&
Object.hasOwn( tracksUserData, 'username' )
) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants