Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable impression logging of survey events #1411

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions querybook/webapp/components/Survey/Survey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import clsx from 'clsx';
import React from 'react';
import toast, { Toast } from 'react-hot-toast';

import { ComponentType } from 'const/analytics';
import {
ISurvey,
IUpdateSurveyFormData,
SurveySurfaceType,
SurveyTypeToQuestion,
} from 'const/survey';
import { useTrackView } from 'hooks/useTrackView';
import { saveSurveyRespondRecord } from 'lib/survey/triggerLogic';
import { SurveyResource } from 'resource/survey';
import { TextButton } from 'ui/Button/Button';
Expand All @@ -28,6 +30,11 @@ export const Survey: React.FC<ISurveyProps> = ({
surfaceMeta = {},
toastProps,
}) => {
useTrackView(ComponentType.SURVEY, undefined, {
surface,
meta: surfaceMeta,
});

const [survey, setSurvey] = React.useState<ISurvey | null>(null);
const handleDismiss = React.useCallback(() => {
toast.dismiss(toastProps.id);
Expand Down
1 change: 1 addition & 0 deletions querybook/webapp/const/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum ComponentType {
TABLE_DETAIL_VIEW = 'TABLE_DETAIL_VIEW',
TABLE_NAVIGATOR_SEARCH = 'TABLE_NAVIGATOR_SEARCH',
AI_ASSISTANT = 'AI_ASSISTANT',
SURVEY = 'SURVEY',
}

export enum ElementType {
Expand Down
12 changes: 8 additions & 4 deletions querybook/webapp/hooks/useTrackView.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { useEffect } from 'react';

import { ComponentType } from 'const/analytics';
import { ComponentType, ElementType } from 'const/analytics';
import { trackView } from 'lib/analytics';

export function useTrackView(component: ComponentType) {
export function useTrackView(
component: ComponentType,
element?: ElementType,
aux?: object
) {
useEffect(() => {
trackView(component);
}, [component]);
trackView(component, element, aux);
}, [component, element, aux]);
}