Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/App/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { REFERRAL_CODE_QUERY_PARAM, getAppBaseUrl } from "lib/legacy";
import { useAccountInitedMetric, useOpenAppMetric } from "lib/metrics";
import { useConfigureMetrics } from "lib/metrics/useConfigureMetrics";
import { useHashQueryParams } from "lib/useHashQueryParams";
import { sendEarnPageViewEvent } from "lib/userAnalytics/earnEvents";
import { useConfigureUserAnalyticsProfile } from "lib/userAnalytics/useConfigureUserAnalyticsProfile";
import { useWalletConnectedUserAnalyticsEvent } from "lib/userAnalytics/useWalletConnectedEvent";
import useRouteQuery from "lib/useRouteQuery";
Expand Down Expand Up @@ -114,6 +115,13 @@ export function AppRoutes() {
}
}, [urlParams, history]);

const isEarnPage = history.location.pathname.startsWith("/earn");
useEffect(() => {
if (isEarnPage) {
sendEarnPageViewEvent();
}
}, [isEarnPage]);

useRealChainIdWarning();
useNonEoaAccountChainWarning();

Expand Down
26 changes: 11 additions & 15 deletions src/lib/userAnalytics/earnEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ export type EarnAnalyticsTab = "discover" | "portfolio" | "additionalOpportuniti

export type EarnPageViewEvent = {
event: "EarnPageView";
data: {
tab: EarnAnalyticsTab;
};
data: {};
};

export type EarnPageActionEvent = {
Expand All @@ -20,7 +18,7 @@ export type EarnPageActionEvent = {
export type EarnRecommendationContext = "AboutTokens" | "YieldLandscape" | "PortfolioRecommendations";
export type EarnRecommendationToken = "GM" | "GLV" | "GMX";
export type EarnPageRecommendationClickedEvent = {
event: "EarnPage";
event: "EarnPageAction";
data: {
action: "RecommendationClicked";
activeTab: EarnAnalyticsTab;
Expand All @@ -32,7 +30,7 @@ export type EarnPageRecommendationClickedEvent = {
export type EarnPagePortfolioItem = "GMX" | "esGMX" | "GLV" | "GM";
export type EarnPagePortfolioItemType = "stake" | "vest" | "buy" | "sell" | "details";
export type EarnPagePortfolioItemClickEvent = {
event: "EarnPage";
event: "EarnPageAction";
data: {
action: "PortfolioItemClick";
item: EarnPagePortfolioItem;
Expand All @@ -50,27 +48,25 @@ export type EarnPageOpportunitiesAnalyticsFilter =
| "YieldTrading";

export type EarnPageOpportunitiesFilterAppliedEvent = {
event: "EarnPage";
event: "EarnPageAction";
data: {
action: "OpportunitiesFilterApplied";
filter: EarnPageOpportunitiesAnalyticsFilter;
};
};

export type EarnPageOpportunityClickedEvent = {
event: "EarnPage";
event: "EarnPageAction";
data: {
action: "OpportunityClicked";
name: string;
};
};

export function sendEarnPageViewEvent(tab: EarnAnalyticsTab) {
export function sendEarnPageViewEvent() {
userAnalytics.pushEvent<EarnPageViewEvent>({
event: "EarnPageView",
data: {
tab,
},
data: {},
});
}

Expand All @@ -94,7 +90,7 @@ export function sendEarnRecommendationClickedEvent({
token: EarnRecommendationToken;
}) {
userAnalytics.pushEvent<EarnPageRecommendationClickedEvent>({
event: "EarnPage",
event: "EarnPageAction",
data: {
action: "RecommendationClicked",
activeTab,
Expand All @@ -112,7 +108,7 @@ export function sendEarnPortfolioItemClickEvent({
type: EarnPagePortfolioItemType;
}) {
userAnalytics.pushEvent<EarnPagePortfolioItemClickEvent>({
event: "EarnPage",
event: "EarnPageAction",
data: {
action: "PortfolioItemClick",
item,
Expand All @@ -123,7 +119,7 @@ export function sendEarnPortfolioItemClickEvent({

export function sendEarnOpportunitiesFilterAppliedEvent(filter: EarnPageOpportunitiesAnalyticsFilter) {
userAnalytics.pushEvent<EarnPageOpportunitiesFilterAppliedEvent>({
event: "EarnPage",
event: "EarnPageAction",
data: {
action: "OpportunitiesFilterApplied",
filter,
Expand All @@ -133,7 +129,7 @@ export function sendEarnOpportunitiesFilterAppliedEvent(filter: EarnPageOpportun

export function sendEarnOpportunityClickedEvent(name: string) {
userAnalytics.pushEvent<EarnPageOpportunityClickedEvent>({
event: "EarnPage",
event: "EarnPageAction",
data: {
action: "OpportunityClicked",
name,
Expand Down
3 changes: 1 addition & 2 deletions src/pages/Earn/EarnPageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useLocation } from "react-router-dom";

import { LAST_EARN_TAB_KEY } from "config/localStorage";
import { useLocalStorageSerializeKey } from "lib/localStorage";
import { sendEarnPageTabViewEvent, sendEarnPageViewEvent, EarnAnalyticsTab } from "lib/userAnalytics/earnEvents";
import { sendEarnPageTabViewEvent, EarnAnalyticsTab } from "lib/userAnalytics/earnEvents";

import AppPageLayout from "components/AppPageLayout/AppPageLayout";
import Button from "components/Button/Button";
Expand Down Expand Up @@ -73,7 +73,6 @@ export default function EarnPageLayout({ children }: EarnPageLayoutProps) {
return;
}

sendEarnPageViewEvent(analyticsTab);
sendEarnPageTabViewEvent(analyticsTab);
}, [analyticsTab]);

Expand Down