-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add telemetry for wallet connection events (#274)
- Loading branch information
Showing
14 changed files
with
234 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Mixpanel from 'mixpanel-browser' | ||
import { trackWalletConnected, trackWalletDiscoveryRequest } from './telemetry' | ||
import { TelemetryDataClient } from './types' | ||
|
||
let mixpanel: any = null | ||
|
||
export function getTelemetryClient(baseData: TelemetryDataClient) { | ||
if (process.env.NEXT_PUBLIC_MIXPANEL_ID && !mixpanel) { | ||
mixpanel = Mixpanel.init(process.env.NEXT_PUBLIC_MIXPANEL_ID) | ||
} | ||
|
||
return { | ||
trackWalletDiscoveryRequest: trackWalletDiscoveryRequest( | ||
mixpanel, | ||
baseData, | ||
), | ||
trackWalletConnected: trackWalletConnected(mixpanel, baseData), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Mixpanel from 'mixpanel' | ||
import { TelemetryDataServer } from './types' | ||
import { trackWalletConnected, trackWalletDiscoveryRequest } from './telemetry' | ||
|
||
let mixpanel: Mixpanel.Mixpanel | null = null | ||
|
||
export function getTelemetryServer(baseData: TelemetryDataServer) { | ||
if (process.env.NEXT_PUBLIC_MIXPANEL_ID && !mixpanel) { | ||
mixpanel = Mixpanel.init(process.env.NEXT_PUBLIC_MIXPANEL_ID) | ||
} | ||
|
||
return { | ||
trackWalletDiscoveryRequest: trackWalletDiscoveryRequest( | ||
mixpanel, | ||
baseData, | ||
), | ||
trackWalletConnected: trackWalletConnected(mixpanel, baseData), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Mixpanel from 'mixpanel' | ||
import { FCL_SERVICE_METHODS } from '../constants' | ||
|
||
export function trackWalletDiscoveryRequest( | ||
mixpanel: Mixpanel.Mixpanel, | ||
baseData: any, | ||
) { | ||
return () => { | ||
mixpanel?.track('Wallet Discovery Request', baseData) | ||
} | ||
} | ||
|
||
export function trackWalletConnected( | ||
mixpanel: Mixpanel.Mixpanel, | ||
baseData: any, | ||
) { | ||
return (walletUid: string, serviceMethod: FCL_SERVICE_METHODS) => { | ||
mixpanel?.track('Wallet Connected', { | ||
walletUid: walletUid, | ||
method: serviceMethod, | ||
...baseData, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export type TelemetryData = { | ||
fclVersion: string | ||
type: 'UI' | 'API' | ||
network: string | ||
} | ||
|
||
export type TelemetryDataServer = TelemetryData & { | ||
origin?: string | ||
} | ||
|
||
export type TelemetryDataClient = TelemetryData & { | ||
parent: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useConfig } from '../contexts/FclContext' | ||
import { getTelemetryClient } from '../helpers/telemetry/telemetry.client' | ||
|
||
export function useTelemetry() { | ||
const cfg = useConfig() | ||
return getTelemetryClient({ | ||
network: cfg.network, | ||
type: 'UI', | ||
fclVersion: cfg.appVersion, | ||
parent: | ||
window.location != window.parent.location ? document.referrer : undefined, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.