Commit 58c94b72 authored by blairmason's avatar blairmason Committed by GitHub

feat: amplitude proxy (#5026)

* configure amplitude sdk to send events to Uniswap reverse proxy
parent 02d25daa
REACT_APP_INFURA_KEY="4bf032f2d38a4ed6bb975b80d6340847" REACT_APP_INFURA_KEY="4bf032f2d38a4ed6bb975b80d6340847"
REACT_APP_AMPLITUDE_TEST_KEY="add-the-real-test-key-if-you-need-to-test-amplitude-events" REACT_APP_AMPLITUDE_PROXY_URL="https://api.uniswap.org/v1/amplitude-proxy"
REACT_APP_AWS_API_REGION="us-east-2" REACT_APP_AWS_API_REGION="us-east-2"
REACT_APP_AWS_API_ACCESS_KEY="AKIAYJJWW6AQ47ODATHN" REACT_APP_AWS_API_ACCESS_KEY="AKIAYJJWW6AQ47ODATHN"
REACT_APP_AWS_API_ACCESS_SECRET="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" REACT_APP_AWS_API_ACCESS_SECRET="V9PoU0FhBP3cX760rPs9jMG/MIuDNLX6hYvVcaYO"
REACT_APP_AWS_X_API_KEY="z9dReS5UtHu7iTrUsTuWRozLthi3AxOZlvobrIdr14" REACT_APP_AWS_X_API_KEY="z9dReS5UtHu7iTrUsTuWRozLthi3AxOZlvobrIdr14"
REACT_APP_AWS_API_ENDPOINT="https://beta.api.uniswap.org/v1/graphql" REACT_APP_AWS_API_ENDPOINT="https://beta.api.uniswap.org/v1/graphql"
REACT_APP_TEMP_API_URL="https://temp.api.uniswap.org/v1" REACT_APP_TEMP_API_URL="https://temp.api.uniswap.org/v1"
\ No newline at end of file
REACT_APP_AMPLITUDE_KEY="b8f7dabddb1c3b03b394619767972160" REACT_APP_AMPLITUDE_PROXY_URL="https://api.uniswap.org/v1/amplitude-proxy"
REACT_APP_AMPLITUDE_TEST_KEY="1c694b28cd089acc2c386d518f93a775"
REACT_APP_INFURA_KEY="099fc58e0de9451d80b18d7c74caa7c1" REACT_APP_INFURA_KEY="099fc58e0de9451d80b18d7c74caa7c1"
REACT_APP_FORTMATIC_KEY="pk_live_F937DF033A1666BF" REACT_APP_FORTMATIC_KEY="pk_live_F937DF033A1666BF"
REACT_APP_GOOGLE_ANALYTICS_ID="G-KDP9B6W4H8" REACT_APP_GOOGLE_ANALYTICS_ID="G-KDP9B6W4H8"
......
import { Identify, identify, init, track } from '@amplitude/analytics-browser' import { Identify, identify, init, track } from '@amplitude/analytics-browser'
import { isProductionEnv } from 'utils/env' import { isProductionEnv } from 'utils/env'
const API_KEY = isProductionEnv() ? process.env.REACT_APP_AMPLITUDE_KEY : process.env.REACT_APP_AMPLITUDE_TEST_KEY const DUMMY_KEY = '00000000000000000000000000000000'
const PROXY_URL = process.env.REACT_APP_AMPLITUDE_PROXY_URL
/** /**
* Initializes Amplitude with API key for project. * Initializes Amplitude SDK and configures it to send events to a Uniswap reverse proxy,
* * which relays to events to relevant Amplitude endpoints. You must be a
* Uniswap has two Amplitude projects: test and production. You must be a * member of the organization on Amplitude to view logged events.
* member of the organization on Amplitude to view details.
*/ */
export function initializeAnalytics() { export function initializeAnalytics() {
if (typeof API_KEY === 'undefined') { if (typeof PROXY_URL === 'undefined') {
const keyName = isProductionEnv() ? 'REACT_APP_AMPLITUDE_KEY' : 'REACT_APP_AMPLITUDE_TEST_KEY' console.error('REACT_APP_AMPLITUDE_PROXY_URL is undefined, Amplitude analytics will not run.')
console.error(`${keyName} is undefined, Amplitude analytics will not run.`)
return return
} }
init( init(
API_KEY, DUMMY_KEY,
/* userId= */ undefined, // User ID should be undefined to let Amplitude default to Device ID /* userId= */ undefined, // User ID should be undefined to let Amplitude default to Device ID
/* options= */ /* options= */
{ {
// Configure the SDK to work with alternate endpoint
serverUrl: PROXY_URL,
// Disable tracking of private user information by Amplitude // Disable tracking of private user information by Amplitude
trackingOptions: { trackingOptions: {
// IP is being dropped before ingestion on Amplitude side, only being used to determine country. ipAddress: false,
ipAddress: isProductionEnv() ? false : true,
carrier: false, carrier: false,
city: false, city: false,
region: false, region: false,
...@@ -35,8 +35,7 @@ export function initializeAnalytics() { ...@@ -35,8 +35,7 @@ export function initializeAnalytics() {
/** Sends an event to Amplitude. */ /** Sends an event to Amplitude. */
export function sendAnalyticsEvent(eventName: string, eventProperties?: Record<string, unknown>) { export function sendAnalyticsEvent(eventName: string, eventProperties?: Record<string, unknown>) {
const origin = window.location.origin if (!PROXY_URL) {
if (!API_KEY) {
console.log(`[analytics(${eventName})]: ${JSON.stringify(eventProperties)}`) console.log(`[analytics(${eventName})]: ${JSON.stringify(eventProperties)}`)
return return
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment