Skip to content

Commit

Permalink
feat(telemetry): measure interactive-examples actions (#8337)
Browse files Browse the repository at this point in the history
Handle interaction events that bob posts,
and forward them with Glean.
  • Loading branch information
caugner authored Mar 15, 2023
1 parent b0f3938 commit 786290f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client/src/document/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import "./index.scss";
import "./interactive-examples.scss";
import { DocumentSurvey } from "../ui/molecules/document-survey";
import { useIncrementFrequentlyViewed } from "../plus/collections/frequently-viewed";
import { useInteractiveExamplesActionHandler as useInteractiveExamplesTelemetry } from "../telemetry/interactive-examples";
// import { useUIStatus } from "../ui-context";

// Lazy sub-components
Expand Down Expand Up @@ -111,8 +112,10 @@ export function Document(props /* TODO: define a TS interface for this */) {
refreshInterval: CRUD_MODE ? 500 : 0,
}
);

useIncrementFrequentlyViewed(doc);
useCopyExamplesToClipboard(doc);
useInteractiveExamplesTelemetry();

React.useEffect(() => {
if (!doc && !error) {
Expand Down
26 changes: 26 additions & 0 deletions client/src/telemetry/interactive-examples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEffect } from "react";
import { useGleanClick } from "./glean-context";
import { IEX_DOMAIN } from "../env";

/**
* Forwards user interactions with interactive-examples to Glean.
*/
export function useInteractiveExamplesActionHandler() {
const gleanClick = useGleanClick();

useEffect(() => {
const listener = (event: MessageEvent) => {
if (
event.origin === IEX_DOMAIN &&
typeof event.data === "object" &&
event.data.type === "action"
) {
gleanClick(`interactive-examples: ${event.data.source}`);
}
};

window.addEventListener("message", listener);

return () => window.removeEventListener("message", listener);
}, [gleanClick]);
}

0 comments on commit 786290f

Please sign in to comment.