Skip to content

Commit

Permalink
fix(telemetry): set page props on click
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Dec 4, 2024
1 parent 72fb3c4 commit 3f6bf3b
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions client/src/telemetry/glean-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ export type PageEventProps = {

export type ElementClickedProps = {
source: string;
subscriptionType: string;
};

export type GleanAnalytics = {
page: (arg: PageProps) => () => void;
click: (arg: ElementClickedProps) => void;
page: (page: PageProps) => () => void;
click: (page: PageProps, element: ElementClickedProps) => void;
};

const FIRST_PARTY_DATA_OPT_OUT_COOKIE_NAME = "moz-1st-party-data-opt-out";
Expand All @@ -79,7 +78,7 @@ function glean(): GleanAnalytics {
//SSR return noop.
return {
page: (page: PageProps) => () => {},
click: (element: ElementClickedProps) => {},
click: (page: PageProps, element: ElementClickedProps) => {},
};
}
const userIsOptedOut = document.cookie
Expand Down Expand Up @@ -137,11 +136,11 @@ function glean(): GleanAnalytics {
updatePageMetrics(page);
return () => pings.page.submit();
},
click: (event: ElementClickedProps) => {
const { source, subscriptionType: subscription_type } = event;
click: (page: PageProps, event: ElementClickedProps) => {
updatePageMetrics(page);
const { source } = event;
elementMetric.clicked.record({
source,
subscription_type,
});
pings.action.submit();
},
Expand Down Expand Up @@ -262,12 +261,11 @@ export function useGleanClick() {
console.log({ gleanClick: source });
}

glean.click({
glean.click(getPageProps(userData), {
source,
subscriptionType: userData?.subscriptionType || "none",
});
},
[glean, userData?.subscriptionType]
[glean, userData]
);
}

Expand Down

0 comments on commit 3f6bf3b

Please sign in to comment.