diff --git a/src/app/hooks/useGlean.ts b/src/app/hooks/useGlean.ts index a749280e21e..e4d2b55c838 100644 --- a/src/app/hooks/useGlean.ts +++ b/src/app/hooks/useGlean.ts @@ -49,17 +49,17 @@ export const useGlean = () => { typeof experimentData["Enrollments"] !== "undefined" ) { (data as GleanMetricMap["button"]["click"]).nimbus_user_id = - experimentData["Enrollments"]["nimbus_user_id"]; + experimentData["Enrollments"][0]?.nimbus_user_id; (data as GleanMetricMap["button"]["click"]).nimbus_app_id = - experimentData["Enrollments"]["app_id"]; + experimentData["Enrollments"][0]?.app_id; (data as GleanMetricMap["button"]["click"]).nimbus_experiment = - experimentData["Enrollments"]["experiment"]; + experimentData["Enrollments"][0]?.experiment; (data as GleanMetricMap["button"]["click"]).nimbus_branch = - experimentData["Enrollments"]["branch"]; + experimentData["Enrollments"][0]?.branch; (data as GleanMetricMap["button"]["click"]).nimbus_experiment_type = - experimentData["Enrollments"]["experiment_type"]; + experimentData["Enrollments"][0]?.experiment_type; (data as GleanMetricMap["button"]["click"]).nimbus_is_preview = - experimentData["Enrollments"]["is_preview"].toString(); + experimentData["Enrollments"][0]?.is_preview.toString(); } else { console.warn("No experiment data available for Glean"); } diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 1c22765a892..71c7260cb56 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -72,7 +72,7 @@ export default async function RootLayout({ previewMode: nimbusPreviewMode === "true", }); - const nimbus_user_id = experimentData["Enrollments"]?.nimbus_user_id; + const nimbus_user_id = experimentData["Enrollments"]?.[0]?.nimbus_user_id; if ( typeof nimbus_user_id !== "undefined" && nimbus_user_id !== experimentationId diff --git a/src/scripts/build/nimbusTypes.js b/src/scripts/build/nimbusTypes.js index b5bdbde5d94..2e6b9ab9abc 100644 --- a/src/scripts/build/nimbusTypes.js +++ b/src/scripts/build/nimbusTypes.js @@ -96,17 +96,19 @@ function getFallbackObject(nimbusConfig) { ); const defaultExperimentData = ` - "Features": { + Features: { ${featureFallbackDefs.join("\n")} }, - "Enrollments": { - "nimbus_user_id": "-1", - "app_id": "-1", - "experiment": "-1", - "branch": "-1", - "experiment_type": "-1", - "is_preview": false - }`; + Enrollments: [ + { + nimbus_user_id: "-1", + app_id: "-1", + experiment: "-1", + branch: "-1", + experiment_type: "-1", + is_preview: false + } + ]`; return `export const defaultExperimentData: ExperimentData = {\n${defaultExperimentData}};\n`; } @@ -129,17 +131,19 @@ function getLocalOverrides(nimbusConfig) { ); const localExperimentData = ` - "Features": { + Features: { ${featureLocalOverridesDefs.join("\n")} }, - "Enrollments": { - "nimbus_user_id": "-1", - "app_id": "-1", - "experiment": "-1", - "branch": "-1", - "experiment_type": "-1", - "is_preview": false - }`; + Enrollments: [ + { + nimbus_user_id: "-1", + app_id: "-1", + experiment: "-1", + branch: "-1", + experiment_type: "-1", + is_preview: false + } + ]`; return `export const localExperimentData: ExperimentData = {\n${localExperimentData}};\n`; } @@ -160,15 +164,15 @@ function getFeaturesTypeDef(nimbusConfig) { }); const experimentDataType = `{ - "Features": {${featureDefs.join("")}}; - "Enrollments": { - "nimbus_user_id": string, - "app_id": string, - "experiment": string, - "branch": string, - "experiment_type": string, - "is_preview": boolean - }; + Features: {${featureDefs.join("")}}; + Enrollments: Array<{ + nimbus_user_id: string, + app_id: string, + experiment: string, + branch: string, + experiment_type: string, + is_preview: boolean + }>; };`; const experimentDataTypeDef = `/** Status of experiments, as setup in Experimenter */\nexport type ExperimentData = ${experimentDataType}`;