From e90e4e3356aeb898fcd17cb14458bd93eff2097b Mon Sep 17 00:00:00 2001 From: Claas Augner <495429+caugner@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:08:32 +0100 Subject: [PATCH] feat(telemetry): measure served placement types (#10708) --- client/src/placement-context.tsx | 36 +++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/client/src/placement-context.tsx b/client/src/placement-context.tsx index 405e1693bb41..f7b4d969b2dd 100644 --- a/client/src/placement-context.tsx +++ b/client/src/placement-context.tsx @@ -20,17 +20,32 @@ export interface PlacementContextData status: Status; } -const PLACEMENT_MAP: Record = { - side: /\/[^/]+\/(play|docs\/|blog\/|curriculum\/[^$]|search$)/i, - top: /\/[^/]+\/(?!$|_homepage$).*/i, - hpMain: /\/[^/]+\/($|_homepage$)/i, - hpFooter: /\/[^/]+\/($|_homepage$)/i, - bottom: /\/[^/]+\/docs\//i, +const PLACEMENT_MAP: Record = { + side: { + typ: "side", + pattern: /\/[^/]+\/(play|docs\/|blog\/|curriculum\/[^$]|search$)/i, + }, + top: { + typ: "top-banner", + pattern: /\/[^/]+\/(?!$|_homepage$).*/i, + }, + hpMain: { + typ: "hp-main", + pattern: /\/[^/]+\/($|_homepage$)/i, + }, + hpFooter: { + typ: "hp-footer", + pattern: /\/[^/]+\/($|_homepage$)/i, + }, + bottom: { + typ: "bottom-banner", + pattern: /\/[^/]+\/docs\//i, + }, }; function placementTypes(pathname: string): string[] { return Object.entries(PLACEMENT_MAP) - .map(([k, re]) => re.test(pathname) && k) + .map(([k, { pattern: re }]) => re.test(pathname) && k) .filter(Boolean) as string[]; } @@ -74,7 +89,12 @@ export function PlacementProvider(props: { children: React.ReactNode }) { try { const placementResponse: PlacementContextData = await response.json(); - gleanClick(`pong: pong->status ${placementResponse.side?.status}`); + const typs = Object.entries(PLACEMENT_MAP) + .filter(([key]) => key in placementResponse) + .map(([, { typ }]) => typ); + if (typs.length) { + gleanClick(`pong: pong->served ${typs.join()}`); + } return placementResponse; } catch (e) { throw Error(response.statusText);