Skip to content

Track custom post type usage - #26100

Merged
crazytonyli merged 5 commits into
trunkfrom
task/cmm-2450-custom-post-type-usage-tracking
Nov 16, 2026
Merged

crazytonyli merged 5 commits into
trunkfrom
task/cmm-2450-custom-post-type-usage-tracking

Conversation

@crazytonyli

@crazytonyli crazytonyli commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes https://linear.app/a8c/issue/CMM-2450

To measure which custom post types sites use:

  1. Send custom_post_types_fetched after syncing post types, once per site per app process. Include counts and slugs for types the app lists and hidden plugin or theme types, plus hosting type.
  2. Add site properties to custom post list events and use the actual post type slug for post_type. This changes values from posts, pages, or custom to post, page, or a custom slug such as product.

Both include blog_id when available and site_type. Slug lists are JSON strings because Tracks rejects array properties.

Example properties for the new custom_post_types_fetched event on a Jetpack-connected site:

{
  "custom_post_type_count": 2,
  "custom_post_type_slugs": "[\"job_listing\",\"product\"]",
  "hidden_post_type_count": 1,
  "hidden_post_type_slugs": "[\"give_forms\"]",
  "blog_type": "jetpack",
  "blog_id": 42,
  "site_type": "blog"
}

Example properties for the updated cpt_post_list_opened event:

{
  "post_type": "product", // Changed from "custom" to the actual post type slug.
  "tab": "all",
  "page_size": 20,
  "hierarchy_eligible": false,
  "has_cached_content": false,
  "blog_id": 42, // Added when the site has a WordPress.com ID.
  "site_type": "blog" // Added: "blog" or "p2".
}

cpt_post_list_load_finished receives the same slug and site properties alongside its existing load metrics.

Testing instructions

  • Refresh a site's post types twice. Confirm custom_post_types_fetched fires once, then fires again after restarting the app and refreshing.
  • Open post, page, and custom post lists. Check the events include the correct post_type slug and site properties.

@dangermattic

dangermattic commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@crazytonyli crazytonyli added this to the 27.4 milestone Sep 28, 2026
@crazytonyli
crazytonyli marked this pull request as ready for review September 28, 2026 23:02
@wpmobilebot

wpmobilebot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number36122
VersionPR #26100
Bundle IDcom.jetpack.alpha
Commit3105171
Installation URL4dvh6pdsqjo2g
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number36122
VersionPR #26100
Bundle IDorg.wordpress.alpha
Commit3105171
Installation URL00fi8oqcfss20
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@crazytonyli
crazytonyli marked this pull request as draft October 15, 2026 00:14
@crazytonyli

Copy link
Copy Markdown
Contributor Author

I'll tweak the solution due to new changes in the trunk branch.

Send custom_post_types_fetched once per site per app process with the counts and slugs of the custom post types the app lists and of the hidden plugin or theme types, plus the hosting type and site identity. The custom predicate is shared with the site menu query.
@crazytonyli
crazytonyli force-pushed the task/cmm-2450-custom-post-type-usage-tracking branch from 48bc9f3 to 449ff4f Compare October 15, 2026 02:05
@crazytonyli
crazytonyli marked this pull request as ready for review October 15, 2026 02:05
@wpmobilebot wpmobilebot modified the milestones: 27.4, 27.5 Oct 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.4 has now entered code-freeze, so the milestone of this PR has been updated to 27.5.

@jkmassel jkmassel 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.

From Claude: Two suggestions that make the post_type change additive. They depend on each other, so apply them as one batch. Built with both applied; CustomPostListAnalyticsTests, CustomPostTypeUsageTrackerTests and PostTypeClassificationTests pass (18 tests) on an iOS 27.2 simulator, and swift-format / SwiftLint are clean.

If this is taken, the description's item 2, the cpt_post_list_opened example and the second testing step need updating to say post_type_slug.

Comment on lines +167 to +168
return [
"post_type": endpoint == .posts ? "posts" : (isPages ? "pages" : "custom"),
"post_type": details.slug,

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.

Finding from Claude:

This changes post_type on cpt_post_list_opened and cpt_post_list_load_finished, which shipped in 27.4. Old app versions send posts / pages / custom, and new ones would send the slug (post, page, product, …) in the same column. Last week (Nov 8–14) that was about 11,600 cpt_post_list_opened events across both apps, all with the old values, so any query or dashboard grouping on them would split at rollout.

Suggest keeping post_type as it is and sending the slug as a new post_type_slug property:

Suggested change
return [
"post_type": endpoint == .posts ? "posts" : (isPages ? "pages" : "custom"),
"post_type": details.slug,
let postType: String
switch details.toPostEndpointType() {
case .posts: postType = "posts"
case .pages: postType = "pages"
default: postType = "custom"
}
return [
"post_type": postType,
"post_type_slug": details.slug,

Comment on lines +17 to +30
@Test(arguments: [
("post", "posts"),
("page", "pages"),
("job_listing", "job_listing")
])
func postTypeIsSlug(slug: String, restBase: String) {
let properties = CustomPostListViewModel.analyticsProperties(
details: .fixture(slug: slug, restBase: restBase),
filter: CustomPostListFilter(tab: .all),
hierarchyEligible: false,
hasCachedContent: false
)
#expect(properties["post_type"] as? String == slug)
}

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.

Finding from Claude:

Test update to match the suggestion above (apply both together):

Suggested change
@Test(arguments: [
("post", "posts"),
("page", "pages"),
("job_listing", "job_listing")
])
func postTypeIsSlug(slug: String, restBase: String) {
let properties = CustomPostListViewModel.analyticsProperties(
details: .fixture(slug: slug, restBase: restBase),
filter: CustomPostListFilter(tab: .all),
hierarchyEligible: false,
hasCachedContent: false
)
#expect(properties["post_type"] as? String == slug)
}
@Test(arguments: [
("post", "posts", "posts"),
("page", "pages", "pages"),
("job_listing", "job_listing", "custom")
])
func postTypeKeepsCategoryAndAddsSlug(slug: String, restBase: String, category: String) {
let properties = CustomPostListViewModel.analyticsProperties(
details: .fixture(slug: slug, restBase: restBase),
filter: CustomPostListFilter(tab: .all),
hierarchyEligible: false,
hasCachedContent: false
)
#expect(properties["post_type"] as? String == category)
#expect(properties["post_type_slug"] as? String == slug)
}

@wpmobilebot

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@crazytonyli
crazytonyli added this pull request to the merge queue Nov 16, 2026
Merged via the queue into trunk with commit a25481c Nov 16, 2026
21 checks passed
@crazytonyli
crazytonyli deleted the task/cmm-2450-custom-post-type-usage-tracking branch November 16, 2026 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants