Skip to content

Commit

Permalink
Pass the experimentation ID to Glean
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Helmer <rhelmer@mozilla.com>
  • Loading branch information
Vinnl and rhelmer committed Apr 26, 2024
1 parent 15c0af4 commit 1519b6b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export type TabData = {

export const View = (props: Props) => {
const l10n = useL10n();
const recordTelemetry = useTelemetry();
const recordTelemetry = useTelemetry(props.telemetryId);
const countryCode = useContext(CountryCodeContext);

const adjustedScanResults = props.userScanData.results.map((scanResult) => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/client/PageLoadEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const PageLoadEvent = (props: Props) => {
]);
const pathname = usePathname();

const recordTelemetry = useTelemetry();
const recordTelemetry = useTelemetry(props.userId);

const userId: GleanMetricMap["page"]["view"]["user_id"] = useMemo(() => {
// If the user is not logged in, use randomly-generated user ID and store in cookie.
Expand Down
3 changes: 2 additions & 1 deletion src/app/hooks/useGlean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import EventMetricType from "@mozilla/glean/private/metrics/event";
import type { GleanMetricMap } from "../../telemetry/generated/_map";
import { PublicEnvContext } from "../../contextProviders/public-env";

export const useGlean = () => {
export const useGlean = (experimentationId?: string) => {
const { PUBLIC_APP_ENV } = useContext(PublicEnvContext);

// Initialize Glean only on the first render of our custom hook.
Expand Down Expand Up @@ -42,6 +42,7 @@ export const useGlean = () => {
maxEvents: 1,
channel: PUBLIC_APP_ENV,
enableAutoPageLoadEvents: true,
experimentationId: experimentationId,
});
// This effect should only run once
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
4 changes: 2 additions & 2 deletions src/app/hooks/useTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const TelemetryPlatforms = {
Ga: "ga",
} as const;

export const useTelemetry = () => {
export const useTelemetry = (experimentationId?: string) => {
const path = usePathname();
const recordGlean = useGlean();
const recordGlean = useGlean(experimentationId);

const { Glean, Ga } = TelemetryPlatforms;
const recordTelemetry = <
Expand Down

0 comments on commit 1519b6b

Please sign in to comment.