Skip to content

Commit

Permalink
feat(telemetry): measure served placement types (#10708)
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner authored Mar 18, 2024
1 parent a951216 commit e90e4e3
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions client/src/placement-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,32 @@ export interface PlacementContextData
status: Status;
}

const PLACEMENT_MAP: Record<PlacementType, RegExp> = {
side: /\/[^/]+\/(play|docs\/|blog\/|curriculum\/[^$]|search$)/i,
top: /\/[^/]+\/(?!$|_homepage$).*/i,
hpMain: /\/[^/]+\/($|_homepage$)/i,
hpFooter: /\/[^/]+\/($|_homepage$)/i,
bottom: /\/[^/]+\/docs\//i,
const PLACEMENT_MAP: Record<PlacementType, { typ: string; pattern: RegExp }> = {
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[];
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e90e4e3

Please sign in to comment.