Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import BlockingSpinner from 'src/components/common/BlockingSpinner';
import useAcceleratorConsole from 'src/hooks/useAcceleratorConsole';
import { useAppVersion } from 'src/hooks/useAppVersion';
import { MixpanelUserProfile } from 'src/mixpanelEvents';
import { useLocalization, useUser } from 'src/providers';
import { useLocalization, useOrganization, useUser } from 'src/providers';
import { store } from 'src/redux/store';
import AcceleratorRouter from 'src/scenes/AcceleratorRouter';
import FunderRouter from 'src/scenes/FunderRouter';
Expand Down Expand Up @@ -44,6 +44,7 @@ function AppContent() {
useAppVersion();
const { isDesktop, type } = useDeviceInfo();
const { user, isAllowed } = useUser();
const { selectedOrganization } = useOrganization();
const { isAcceleratorRoute } = useAcceleratorConsole();
const { isApplicationPortal } = useApplicationPortal();
const { isFunderRoute } = useFunderPortal();
Expand Down Expand Up @@ -81,6 +82,21 @@ function AppContent() {
}
}, [user, mixpanel]);

// Keep org context registered as super properties whenever the active
// organization changes. Re-registering with new values overwrites the old
// ones so every subsequent event (including auto-pageviews, which
// `useTrackEvent` can't reach) carries the current org.
useEffect(() => {
if (user && mixpanel && user.cookiesConsented === true) {
mixpanel.register({
organization_id: selectedOrganization?.id,
organization_role: selectedOrganization?.role,
user_type: user.userType,
is_internal_user: user.globalRoles.length > 0,
});
}
}, [user, mixpanel, selectedOrganization]);

useEffect(() => {
if (type === 'mobile' || type === 'tablet') {
setShowNavBar(false);
Expand Down
6 changes: 1 addition & 5 deletions src/mixpanelEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export enum MIXPANEL_EVENTS {

// --- Planting & plants ---
PLANTING_SITE_CREATED = 'Planting Site Created',
SURVIVAL_RATE_VIEWED = 'Survival Rate Viewed',

// --- Observations ---
OBSERVATION_SCHEDULED = 'Observation Scheduled',
Expand Down Expand Up @@ -118,9 +117,6 @@ export type MixpanelEventPropertyMap = {
num_strata?: number;
has_boundary: boolean;
};
[MIXPANEL_EVENTS.SURVIVAL_RATE_VIEWED]: {
is_project_view: boolean;
};
[MIXPANEL_EVENTS.OBSERVATION_SCHEDULED]: {
duration_days?: number;
};
Expand All @@ -139,7 +135,7 @@ export type MixpanelEventPropertyMap = {
new_role: string;
};
[MIXPANEL_EVENTS.REPORT_VIEWED]: {
is_funder_view: boolean;
viewer_persona: 'accelerator_admin' | 'funder' | 'forester';
};
[MIXPANEL_EVENTS.REPORT_DOWNLOADED]: {
report_type: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ReportView = () => {
const trackEvent = useTrackEvent();

useEffect(() => {
trackEvent(MIXPANEL_EVENTS.REPORT_VIEWED, { is_funder_view: false });
trackEvent(MIXPANEL_EVENTS.REPORT_VIEWED, { viewer_persona: 'accelerator_admin' });
}, [trackEvent]);
const [showApproveDialog, , openApprovalDialog, closeApproveDialog] = useBoolean(false);
const [showRejectDialog, , openRejectDialog, closeRejectDialog] = useBoolean(false);
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/FunderReport/FunderReportView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const FunderReportView = ({ selectedProjectId, selectedReport }: FunderReportVie
// (as a published-preview), that parent already fires REPORT_VIEWED.
useEffect(() => {
if (isFunderRoute) {
trackEvent(MIXPANEL_EVENTS.REPORT_VIEWED, { is_funder_view: true });
trackEvent(MIXPANEL_EVENTS.REPORT_VIEWED, { viewer_persona: 'funder' });
}
}, [isFunderRoute, trackEvent]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { type JSX, useEffect, useMemo } from 'react';
import React, { type JSX, useMemo } from 'react';

import { Box, Typography, useTheme } from '@mui/material';
import { Icon, Tooltip } from '@terraware/web-components';
Expand All @@ -10,9 +10,7 @@ import Link from 'src/components/common/Link';
import { APP_PATHS } from 'src/constants';
import isEnabled from 'src/features';
import useProjectSiteObservationSummaries from 'src/hooks/useProjectSiteObservationSummaries';
import { useTrackEvent } from 'src/hooks/useTrackEvent';
import { useKnowledgeBaseLinks } from 'src/knowledgeBaseLinks';
import { MIXPANEL_EVENTS } from 'src/mixpanelEvents';
import { useListObservationSummariesQuery } from 'src/queries/generated/observations';
import strings from 'src/strings';

Expand All @@ -31,11 +29,6 @@ export default function SurvivalRateCard({ plantingSiteId, projectId }: Survival
const isWeightedSurvivalRatesEnabled = isEnabled('Weighted Survival Rates');
const isProjectView = !plantingSiteId && projectId;
const knowledgeBaseLinks = useKnowledgeBaseLinks();
const trackEvent = useTrackEvent();

useEffect(() => {
trackEvent(MIXPANEL_EVENTS.SURVIVAL_RATE_VIEWED, { is_project_view: !!isProjectView });
}, [isProjectView, trackEvent]);

const observationSummariesQuery = useListObservationSummariesQuery(
{ plantingSiteId: plantingSiteId || -1 },
Expand Down
7 changes: 7 additions & 0 deletions src/scenes/Reports/AcceleratorReportView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import Card from 'src/components/common/Card';
import TitleBar from 'src/components/common/TitleBar';
import { APP_PATHS } from 'src/constants';
import useNavigateTo from 'src/hooks/useNavigateTo';
import { useTrackEvent } from 'src/hooks/useTrackEvent';
import { MIXPANEL_EVENTS } from 'src/mixpanelEvents';
import { useLocalization } from 'src/providers';
import { useParticipantData } from 'src/providers/Participant/ParticipantContext';
import { useGetAcceleratorReportQuery, useSubmitAcceleratorReportMutation } from 'src/queries/generated/reports';
Expand All @@ -31,6 +33,11 @@ const AcceleratorReportView = () => {
const { strings } = useLocalization();
const { currentAcceleratorProject, setCurrentAcceleratorProject } = useParticipantData();
const theme = useTheme();
const trackEvent = useTrackEvent();

useEffect(() => {
trackEvent(MIXPANEL_EVENTS.REPORT_VIEWED, { viewer_persona: 'forester' });
}, [trackEvent]);

const { goToAcceleratorReportEdit } = useNavigateTo();

Expand Down