Skip to content

Commit

Permalink
feat(telemetry): measure survey interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Jun 7, 2024
1 parent 8c015b5 commit b68b330
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ export const BASELINE = Object.freeze({
export const CLIENT_SIDE_NAVIGATION = "client_side_nav";
export const LANGUAGE = "language";
export const THEME_SWITCHER = "theme_switcher";
export const SURVEY = "survey";
8 changes: 7 additions & 1 deletion client/src/ui/molecules/document-survey/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { useIsServer } from "../../../hooks";
import { Icon } from "../../atoms/icon";
import { useLocation } from "react-router";
import { DEV_MODE, WRITER_MODE } from "../../../env";
import { useGleanClick } from "../../../telemetry/glean-context";
import { SURVEY } from "../../../telemetry/constants";

const FORCE_SURVEY_PREFIX = "#FORCE_SURVEY=";

Expand Down Expand Up @@ -49,6 +51,7 @@ export function DocumentSurvey({ doc }: { doc: Doc }) {
}

function SurveyDisplay({ survey, force }: { survey: Survey; force: boolean }) {
const gleanClick = useGleanClick();
const details = React.useRef<HTMLDetailsElement | null>(null);

const [originalState] = React.useState(() => getSurveyState(survey.bucket));
Expand All @@ -63,13 +66,15 @@ function SurveyDisplay({ survey, force }: { survey: Survey; force: boolean }) {
...state,
dismissed_at: Date.now(),
});
gleanClick(`${SURVEY}: dismissed ${survey.bucket}`);
}

function submitted() {
setState({
...state,
submitted_at: Date.now(),
});
gleanClick(`${SURVEY}: submitted ${survey.bucket}`);
}

React.useEffect(() => {
Expand Down Expand Up @@ -98,8 +103,9 @@ function SurveyDisplay({ survey, force }: { survey: Survey; force: boolean }) {
...state,
seen_at: Date.now(),
});
gleanClick(`${SURVEY}: seen ${survey.bucket}`);
}
}, [state]);
}, [state, gleanClick, survey.bucket]);

React.useEffect(() => {
// For this to work, the Survey needs this JavaScript action:
Expand Down

0 comments on commit b68b330

Please sign in to comment.