Skip to content

Commit

Permalink
chore: manually assign custom domain referrer [OTE-516] (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam authored Jul 17, 2024
1 parent d622be0 commit f4b9533
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/constants/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ import { TransferNotificationTypes } from './notifications';
import type { TradeTypes } from './trade';
import type { DydxAddress, EvmAddress, WalletConnectionType, WalletType } from './wallets';

type AnalyticsEventDataWithReferrer<T extends AnalyticsEventTypes> = AnalyticsEventPayloads[T] & {
referrer: string;
};
export type AnalyticsEventTrackMeta<T extends AnalyticsEventTypes> = {
detail: {
eventType: T;
eventData: AnalyticsEventDataWithReferrer<T>;
eventData: AnalyticsEventPayloads[T];
};
};
export type AnalyticsEventIdentifyMeta<T extends AnalyticsUserPropertyTypes> = {
Expand Down Expand Up @@ -46,6 +43,8 @@ export const customTrackEvent = <T extends AnalyticsEventTypes>(
// User properties
export const AnalyticsUserProperties = unionize(
{
// Referrer
CustomDomainReferrer: ofType<string | null>(),
// Environment
Locale: ofType<SupportedLocales>(),
Breakpoint: ofType<
Expand Down Expand Up @@ -76,6 +75,7 @@ export const AnalyticsUserPropertyLoggableTypes = {
Breakpoint: 'breakpoint',
Version: 'version',
StatsigFlags: 'statsigFlags',
CustomDomainReferrer: 'customDomainReferrer',
Network: 'network',
WalletType: 'walletType',
WalletConnectionType: 'walletConnectionType',
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export const useAnalytics = () => {
? 'DESKTOP_LARGE'
: 'UNSUPPORTED';

useEffect(() => {
identify(AnalyticsUserProperties.CustomDomainReferrer(document.referrer));
}, []);

useEffect(() => {
identify(AnalyticsUserProperties.Breakpoint(breakpoint));
}, [breakpoint]);
Expand Down
7 changes: 2 additions & 5 deletions src/lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
type AnalyticsUserProperty,
} from '@/constants/analytics';

import { testFlags } from './testFlags';

const DEBUG_ANALYTICS = false;

export const identify = (property: AnalyticsUserProperty) => {
Expand All @@ -26,13 +24,12 @@ export const identify = (property: AnalyticsUserProperty) => {
};

export const track = (event: AnalyticsEvent) => {
const eventDataWithReferrer = { ...(event.payload ?? {}), referrer: testFlags.referrer };
if (DEBUG_ANALYTICS) {
// eslint-disable-next-line no-console
console.log(`[Analytics] ${event.type}`, eventDataWithReferrer);
console.log(`[Analytics] ${event.type}`, event.payload);
}
const customEvent = customTrackEvent({
detail: { eventType: event.type, eventData: eventDataWithReferrer },
detail: { eventType: event.type, eventData: event.payload },
});

globalThis.dispatchEvent(customEvent);
Expand Down

0 comments on commit f4b9533

Please sign in to comment.