diff --git a/src/app/hooks/useGlean.ts b/src/app/hooks/useGlean.ts index 490e84370e9..1897997ffe9 100644 --- a/src/app/hooks/useGlean.ts +++ b/src/app/hooks/useGlean.ts @@ -13,7 +13,7 @@ import { useExperiments } from "../../contextProviders/experiments"; export const useGlean = () => { const session = useSession(); - const experimentData = useExperiments(); + const experiments = useExperiments(); // Telemetry recording is mocked in our unit tests, therefore we // do not have test coverage for this method. /* c8 ignore start */ @@ -44,38 +44,19 @@ export const useGlean = () => { // Record the `nimbus_*` keys on all events. // `nimbus_*` is set on every metric, but it's too much work for TypeScript // to infer that — hence the type assertion. - if ( - experimentData && - typeof experimentData["Enrollments"] !== "undefined" - ) { - (data as GleanMetricMap["button"]["click"]).nimbus_user_ids = - experimentData["Enrollments"].map( - (enrollment) => enrollment.nimbus_user_id, - ); - (data as GleanMetricMap["button"]["click"]).nimbus_app_ids = - experimentData["Enrollments"].map((enrollment) => enrollment.app_id); - (data as GleanMetricMap["button"]["click"]).nimbus_experiments = - experimentData["Enrollments"].map( - (enrollment) => enrollment.experiment, - ); - (data as GleanMetricMap["button"]["click"]).nimbus_branches = - experimentData["Enrollments"].map((enrollment) => enrollment.branch); - (data as GleanMetricMap["button"]["click"]).nimbus_experiment_types = - experimentData["Enrollments"].map( - (enrollment) => enrollment.experiment_type, - ); - (data as GleanMetricMap["button"]["click"]).nimbus_are_previews = - experimentData["Enrollments"].map( - (enrollment) => enrollment.is_preview, - ); + if (experiments === null) { + console.warn( + "`useGlean` is used in a component that is not a (grand)child of ", + ); } else { - console.warn("No experiment data available for Glean"); + (data as GleanMetricMap["button"]["click"]).nimbus_user_id = + experiments.experimentationId; } // eslint-disable-next-line @typescript-eslint/no-explicit-any mod[event].record(data as any); }, - [isPremiumUser, experimentData], + [isPremiumUser, experiments], ); /* c8 ignore end */ diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 71c7260cb56..372d9f153b7 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -91,7 +91,10 @@ export default async function RootLayout({ data-ga4-measurement-id={CONST_GA4_MEASUREMENT_ID} data-node-env={process.env.NODE_ENV} > - + {children} diff --git a/src/contextProviders/experiments.test.tsx b/src/contextProviders/experiments.test.tsx index d26fe044f3a..bd029d114b2 100644 --- a/src/contextProviders/experiments.test.tsx +++ b/src/contextProviders/experiments.test.tsx @@ -14,7 +14,10 @@ describe("Experiment context provider", () => { return
; }; const { container } = render( - + , ); diff --git a/src/contextProviders/experiments.tsx b/src/contextProviders/experiments.tsx index 875dd555c17..ae11b8008bc 100644 --- a/src/contextProviders/experiments.tsx +++ b/src/contextProviders/experiments.tsx @@ -10,18 +10,23 @@ import { ExperimentData_V2_Or_V2LikeV1 } from "../app/functions/server/getExperi interface ExperimentsProviderProps { children: ReactNode; experimentData: ExperimentData_V2_Or_V2LikeV1; + experimentationId: string; } -export const ExperimentsContext = - createContext(null); +export const ExperimentsContext = createContext<{ + experimentData: ExperimentData_V2_Or_V2LikeV1; + experimentationId: string; +} | null>(null); -export const ExperimentsProvider = ({ - children, - experimentData, -}: ExperimentsProviderProps) => { +export const ExperimentsProvider = (props: ExperimentsProviderProps) => { return ( - - {children} + + {props.children} ); }; diff --git a/src/telemetry/metrics.yaml b/src/telemetry/metrics.yaml index 4a1d2041a91..d6d709d3cc1 100644 --- a/src/telemetry/metrics.yaml +++ b/src/telemetry/metrics.yaml @@ -56,36 +56,9 @@ page: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string dashboard: view: @@ -132,36 +105,9 @@ dashboard: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string popup: view: @@ -195,36 +141,9 @@ popup: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string exit: type: event @@ -257,36 +176,9 @@ popup: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string banner: view: @@ -320,36 +212,9 @@ banner: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string button: click: @@ -383,36 +248,9 @@ button: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string field: focus: @@ -446,36 +284,9 @@ field: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string link: click: @@ -509,36 +320,9 @@ link: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string upgrade_intent: click: @@ -572,36 +356,9 @@ upgrade_intent: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string success: type: event @@ -632,36 +389,9 @@ upgrade_intent: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string expand: click: @@ -695,36 +425,9 @@ expand: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string collapse: click: @@ -758,36 +461,9 @@ collapse: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string cta_button: click: @@ -821,36 +497,9 @@ cta_button: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string view: type: event @@ -883,36 +532,9 @@ cta_button: plan_tier: description: Which tier of plan the user is on [Free, Plus] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string csat_survey: view: @@ -946,36 +568,9 @@ csat_survey: automated_removal_period: description: The time period since the first automated removal for the user. [initial, 3-months, 6-months, 12-months] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string dismiss: type: event @@ -1008,36 +603,9 @@ csat_survey: automated_removal_period: description: The time period since the first automated removal for the user. [initial, 3-months, 6-months, 12-months] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string click: type: event @@ -1073,33 +641,6 @@ csat_survey: automated_removal_period: description: The time period since the first automated removal for the user. [initial, 3-months, 6-months, 12-months] type: string - nimbus_user_ids: + nimbus_user_id: description: Nimbus user ID - type: array - items: - type: string - nimbus_app_ids: - description: Nimbus application ID - type: array - items: - type: string - nimbus_experiments: - description: Nimbus experiment name - type: array - items: - type: string - nimbus_branches: - description: Nimbus branch - type: array - items: - type: string - nimbus_experiment_types: - description: Nimbus experiment type - type: array - items: - type: string - nimbus_are_previews: - description: Nimbus preview mode enabled - type: array - items: - type: boolean + type: string