Skip to content

Commit

Permalink
Revert "MNTOR-3814 - use context to fetch experiment data from Cirrus (
Browse files Browse the repository at this point in the history
…#5440)" (#5505)

This reverts commit 780dfd4.
  • Loading branch information
rhelmer authored Jan 15, 2025
1 parent 4de104f commit 80e7178
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 420 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default async function DashboardPage({ params, searchParams }: Props) {
totalNumberOfPerformedScans={profileStats?.total}
isNewUser={isNewUser}
elapsedTimeInDaysSinceInitialScan={elapsedTimeInDaysSinceInitialScan}
experimentData={experimentData["Features"]}
experimentData={experimentData}
activeTab={activeTab}
hasFirstMonitoringScan={hasFirstMonitoringScan}
signInCount={signInCount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default async function SettingsPage({ params, searchParams }: Props) {
yearlySubscriptionUrl={`${yearlySubscriptionUrl}&${additionalSubplatParams.toString()}`}
subscriptionBillingAmount={getSubscriptionBillingAmount()}
enabledFeatureFlags={enabledFeatureFlags}
experimentData={experimentData["Features"]}
experimentData={experimentData}
lastScanDate={lastOneRepScan?.created_at}
isMonthlySubscriber={isMonthlySubscriber}
activeTab={activeTab}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default async function Onboarding({ params, searchParams }: Props) {
breachesTotalCount={allBreachesCount}
stepId={firstSlug === FreeScanSlug ? "enterInfo" : "getStarted"}
previousRoute={previousRoute}
experimentData={experimentData["Features"]}
experimentData={experimentData}
/>
);
}
20 changes: 9 additions & 11 deletions src/app/(proper_react)/(redesign)/(public)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,41 +59,39 @@ export default async function Page({ searchParams }: Props) {
oneRepActivations > monthlySubscribersQuota;
return (
<AccountsMetricsFlowProvider
enabled={experimentData["Features"]["landing-page-free-scan-cta"].enabled}
enabled={experimentData["landing-page-free-scan-cta"].enabled}
metricsFlowParams={{
entrypoint: CONST_URL_MONITOR_LANDING_PAGE_ID,
entrypoint_experiment: "landing-page-free-scan-cta",
entrypoint_variation:
experimentData["Features"]["landing-page-free-scan-cta"].variant,
experimentData["landing-page-free-scan-cta"].variant,
form_type:
experimentData["Features"]["landing-page-free-scan-cta"].variant ===
experimentData["landing-page-free-scan-cta"].variant ===
"ctaWithEmail"
? "email"
: "button",
service: process.env.OAUTH_CLIENT_ID as string,
}}
>
{enabledFeatureFlags.includes("LandingPageRedesign") &&
experimentData["Features"][
"landing-page-redesign-plus-eligible-experiment"
].enabled &&
experimentData["Features"][
"landing-page-redesign-plus-eligible-experiment"
].variant === "redesign" ? (
experimentData["landing-page-redesign-plus-eligible-experiment"]
.enabled &&
experimentData["landing-page-redesign-plus-eligible-experiment"]
.variant === "redesign" ? (
<LandingViewRedesign
eligibleForPremium={eligibleForPremium}
l10n={getL10n()}
countryCode={countryCode}
scanLimitReached={scanLimitReached}
experimentData={experimentData["Features"]}
experimentData={experimentData}
/>
) : (
<LandingView
eligibleForPremium={eligibleForPremium}
l10n={getL10n()}
countryCode={countryCode}
scanLimitReached={scanLimitReached}
experimentData={experimentData["Features"]}
experimentData={experimentData}
/>
)}
</AccountsMetricsFlowProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/v1/user/welcome-scan/create/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function POST(
previewMode: searchParams.get("nimbus_preview") === "true",
});
const optionalInfoExperimentData =
experimentData["Features"]["welcome-scan-optional-info"];
experimentData["welcome-scan-optional-info"];

const profileData: CreateProfileRequest = {
first_name: firstName,
Expand Down
11 changes: 7 additions & 4 deletions src/app/functions/server/getExperiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export async function getExperiments(params: {
locale: string;
countryCode: string;
previewMode: boolean;
}): Promise<ExperimentData> {
}): Promise<ExperimentData["Features"]> {
if (["local"].includes(process.env.APP_ENV ?? "local")) {
return localExperimentData;
return localExperimentData["Features"];
}

if (!process.env.NIMBUS_SIDECAR_URL) {
Expand Down Expand Up @@ -87,7 +87,10 @@ export async function getExperiments(params: {
experimentData = json;
}

return (experimentData as ExperimentData) ?? defaultExperimentData;
return (
(experimentData as ExperimentData["Features"]) ??
defaultExperimentData["Features"]
);
} catch (ex) {
logger.error("Could not connect to Cirrus", {
serverUrl,
Expand All @@ -96,6 +99,6 @@ export async function getExperiments(params: {
params,
});
captureException(ex);
return defaultExperimentData;
return defaultExperimentData["Features"];
}
}
27 changes: 1 addition & 26 deletions src/app/hooks/useGlean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ import EventMetricType from "@mozilla/glean/private/metrics/event";
import type { GleanMetricMap } from "../../telemetry/generated/_map";
import { useSession } from "next-auth/react";
import { hasPremium } from "../functions/universal/user";
import { useExperiments } from "../../contextProviders/experiments";

export const useGlean = () => {
const session = useSession();
const experimentData = useExperiments();
// Telemetry recording is mocked in our unit tests, therefore we
// do not have test coverage for this method.
/* c8 ignore start */
const isPremiumUser = hasPremium(session.data?.user);
const record = useCallback(
async <
Expand All @@ -41,30 +36,10 @@ export const useGlean = () => {
? "Plus"
: "Free";

// 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) {
(data as GleanMetricMap["button"]["click"]).nimbus_user_id =
experimentData["Enrollments"]["nimbus_user_id"];
(data as GleanMetricMap["button"]["click"]).nimbus_app_id =
experimentData["Enrollments"]["app_id"];
(data as GleanMetricMap["button"]["click"]).nimbus_experiment =
experimentData["Enrollments"]["experiment"];
(data as GleanMetricMap["button"]["click"]).nimbus_branch =
experimentData["Enrollments"]["branch"];
(data as GleanMetricMap["button"]["click"]).nimbus_experiment_type =
experimentData["Enrollments"]["experiment_type"];
(data as GleanMetricMap["button"]["click"]).nimbus_is_preview =
experimentData["Enrollments"]["is_preview"].toString();
} else {
console.warn("No experiment data available for Glean");
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
mod[event].record(data as any);
},
[isPremiumUser, experimentData],
[isPremiumUser],
);
/* c8 ignore end */

Expand Down
30 changes: 2 additions & 28 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import { GoogleAnalyticsWorkaround } from "./components/client/GoogleAnalyticsWo
import StripeScript from "./components/client/StripeScript";
import { GleanScript } from "./components/client/GleanScript";
import { getExperimentationId } from "./functions/server/getExperimentationId";
import { getExperiments } from "./functions/server/getExperiments";
import { getCountryCode } from "./functions/server/getCountryCode";
import { ExperimentsProvider } from "../contextProviders/experiments";
import * as Sentry from "@sentry/nextjs";

const inter = Inter({ subsets: ["latin"], variable: "--font-inter" });

Expand Down Expand Up @@ -58,26 +54,6 @@ export default async function RootLayout({
const nonce = headers().get("x-nonce") ?? "";
const currentLocale = getLocale(getL10nBundles());
const session = await getServerSession();
const headersList = headers();
const countryCode = getCountryCode(headersList);

// Check for Nimbus preview mode. Note that this requires a full page reload
// to activate: https://nextjs.org/docs/app/api-reference/file-conventions/layout#caveats
const nimbusPreviewMode = headers().get("x-nimbus-preview-mode");
const experimentationId = getExperimentationId(session?.user ?? null);
const experimentData = await getExperiments({
experimentationId: experimentationId,
countryCode: countryCode,
locale: currentLocale,
previewMode: nimbusPreviewMode === "true",
});

const nimbus_user_id = experimentData["Enrollments"]?.nimbus_user_id ?? "";
if (nimbus_user_id !== experimentationId) {
Sentry.captureMessage(
`Nimbus user ID from Cirrus: [${nimbus_user_id}] did not match experimentationId: [${experimentationId}]`,
);
}

return (
<html lang={currentLocale}>
Expand All @@ -88,14 +64,12 @@ export default async function RootLayout({
data-ga4-measurement-id={CONST_GA4_MEASUREMENT_ID}
data-node-env={process.env.NODE_ENV}
>
<ExperimentsProvider experimentData={experimentData}>
<SessionProvider session={session}>{children}</SessionProvider>
</ExperimentsProvider>
<SessionProvider session={session}>{children}</SessionProvider>
</body>
<StripeScript />
<GleanScript
channel={process.env.APP_ENV ?? ""}
experimentationId={experimentationId}
experimentationId={getExperimentationId(session?.user ?? null)}
/>
{headers().get("DNT") !== "1" && (
<GoogleAnalyticsWorkaround
Expand Down
31 changes: 0 additions & 31 deletions src/contextProviders/experiments.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ export function middleware(request: NextRequest) {
existingExperimentationId?.value ?? `guest-${crypto.randomUUID()}`;
requestHeaders.set("x-experimentation-id", experimentationId);

// Check for Nimbus preview mode. Note that this requires a full page reload
// to activate: https://nextjs.org/docs/app/api-reference/file-conventions/layout#caveats
const nimbusPreviewMode = request.nextUrl.searchParams.get("nimbus_preview");
requestHeaders.set(
"x-nimbus-preview-mode",
nimbusPreviewMode === "true" ? "true" : "false",
);

const response = NextResponse.next({
request: {
headers: requestHeaders,
Expand Down
Loading

0 comments on commit 80e7178

Please sign in to comment.