From 14d3198b8589f408c104bcc9804b2f6fab7c0a4b Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Nov 2025 09:21:46 +0000 Subject: [PATCH] Emit contentType field as content_type in page events (#58325) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: felicitymay <1877141+felicitymay@users.noreply.github.com> --- src/events/components/events.ts | 1 + src/events/lib/schema.ts | 6 +++++ src/events/tests/middleware.ts | 25 ++++++++++++++++++++ src/events/types.ts | 1 + src/frame/components/DefaultLayout.tsx | 1 + src/frame/components/context/MainContext.tsx | 2 ++ src/types.ts | 3 +++ 7 files changed, 39 insertions(+) diff --git a/src/events/components/events.ts b/src/events/components/events.ts index 6a57c39ca8..b0a59990ba 100644 --- a/src/events/components/events.ts +++ b/src/events/components/events.ts @@ -110,6 +110,7 @@ export function sendEvent({ path_article: getMetaContent('path-article'), page_document_type: getMetaContent('page-document-type'), page_type: getMetaContent('page-type'), + content_type: getMetaContent('page-content-type'), status: Number(getMetaContent('status') || 0), is_logged_in: isLoggedIn(), diff --git a/src/events/lib/schema.ts b/src/events/lib/schema.ts index 92e72c7511..3f1bb45ccd 100644 --- a/src/events/lib/schema.ts +++ b/src/events/lib/schema.ts @@ -2,6 +2,7 @@ import { languageKeys } from '@/languages/lib/languages-server' import { allVersionKeys } from '@/versions/lib/all-versions' import { productIds } from '@/products/lib/all-products' import { allTools } from '@/tools/lib/all-tools' +import { contentTypesEnum } from '@/frame/lib/frontmatter' const versionPattern = '^\\d+(\\.\\d+)?(\\.\\d+)?$' @@ -100,6 +101,11 @@ const context = { description: 'Optional page type from the content frontmatter.', enum: ['overview', 'quick_start', 'tutorial', 'how_to', 'reference', 'rai'], // frontmatter.ts }, + content_type: { + type: 'string', + description: 'Optional content type from the content frontmatter (EDI content models).', + enum: contentTypesEnum, + }, status: { type: 'number', description: 'The HTTP response status code of the main page HTML.', diff --git a/src/events/tests/middleware.ts b/src/events/tests/middleware.ts index a485892aa6..a450878436 100644 --- a/src/events/tests/middleware.ts +++ b/src/events/tests/middleware.ts @@ -1,6 +1,7 @@ import { describe, expect, test, vi } from 'vitest' import { post } from '@/tests/helpers/e2etest' +import { contentTypesEnum } from '@/frame/lib/frontmatter' describe('POST /events', () => { vi.setConfig({ testTimeout: 60 * 1000 }) @@ -163,4 +164,28 @@ describe('POST /events', () => { }) expect(statusCode).toBe(400) }) + + test('should accept content_type field', async () => { + const { statusCode } = await checkEvent({ + ...pageExample, + context: { + ...pageExample.context, + content_type: 'how-tos', + }, + }) + expect(statusCode).toBe(200) + }) + + test('should accept valid content_type values from EDI content models', async () => { + for (const contentType of contentTypesEnum) { + const { statusCode } = await checkEvent({ + ...pageExample, + context: { + ...pageExample.context, + content_type: contentType, + }, + }) + expect(statusCode).toBe(200) + } + }) }) diff --git a/src/events/types.ts b/src/events/types.ts index 5ce0be05c8..36e63d0dc7 100644 --- a/src/events/types.ts +++ b/src/events/types.ts @@ -36,6 +36,7 @@ export type EventProps = { path_article: string page_document_type: string page_type: string + content_type: string status: number is_logged_in: boolean dotcom_user: string diff --git a/src/frame/components/DefaultLayout.tsx b/src/frame/components/DefaultLayout.tsx index a23a377995..b57e727d68 100644 --- a/src/frame/components/DefaultLayout.tsx +++ b/src/frame/components/DefaultLayout.tsx @@ -119,6 +119,7 @@ export const DefaultLayout = (props: Props) => { /> )} {page.type && } + {page.contentType && } {page.documentType && } {status && } diff --git a/src/frame/components/context/MainContext.tsx b/src/frame/components/context/MainContext.tsx index f90691cd4d..10fcb7a42b 100644 --- a/src/frame/components/context/MainContext.tsx +++ b/src/frame/components/context/MainContext.tsx @@ -118,6 +118,7 @@ export type MainContextT = { page: { documentType: string type?: string + contentType?: string topics: Array title: string fullTitle?: string @@ -217,6 +218,7 @@ export const getMainContext = async (req: any, res: any): Promise (page && { documentType, type: req.context.page.type || null, + contentType: req.context.page.contentType || null, title: req.context.page.title, fullTitle: req.context.page.fullTitle || null, topics: req.context.page.topics || [], diff --git a/src/types.ts b/src/types.ts index 3c39cac805..b398963269 100644 --- a/src/types.ts +++ b/src/types.ts @@ -51,6 +51,7 @@ export type PageFrontmatter = { featuredLinks?: FeaturedLinks changelog?: ChangeLog type?: string + contentType?: string topics?: string[] includeGuides?: string[] learningTracks?: string[] @@ -380,6 +381,8 @@ export type Page = { complexity?: string[] industry?: string[] sidebarLink?: SidebarLink + type?: string + contentType?: string } export type SidebarLink = {