feat: amplitude proxy (#5026)

* configure amplitude sdk to send events to Uniswap reverse proxy
This commit is contained in:
blairmason 2022-10-27 13:33:10 -07:00 committed by GitHub
parent 02d25daa4c
commit 58c94b7279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 17 deletions

4
.env

@ -1,8 +1,8 @@
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_ACCESS_KEY="AKIAYJJWW6AQ47ODATHN"
REACT_APP_AWS_API_ACCESS_SECRET="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"
REACT_APP_AWS_X_API_KEY="z9dReS5UtHu7iTrUsTuWRozLthi3AxOZlvobrIdr14"
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"

@ -1,5 +1,4 @@
REACT_APP_AMPLITUDE_KEY="b8f7dabddb1c3b03b394619767972160"
REACT_APP_AMPLITUDE_TEST_KEY="1c694b28cd089acc2c386d518f93a775"
REACT_APP_AMPLITUDE_PROXY_URL="https://api.uniswap.org/v1/amplitude-proxy"
REACT_APP_INFURA_KEY="099fc58e0de9451d80b18d7c74caa7c1"
REACT_APP_FORTMATIC_KEY="pk_live_F937DF033A1666BF"
REACT_APP_GOOGLE_ANALYTICS_ID="G-KDP9B6W4H8"

@ -1,29 +1,29 @@
import { Identify, identify, init, track } from '@amplitude/analytics-browser'
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.
*
* Uniswap has two Amplitude projects: test and production. You must be a
* member of the organization on Amplitude to view details.
* 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
* member of the organization on Amplitude to view logged events.
*/
export function initializeAnalytics() {
if (typeof API_KEY === 'undefined') {
const keyName = isProductionEnv() ? 'REACT_APP_AMPLITUDE_KEY' : 'REACT_APP_AMPLITUDE_TEST_KEY'
console.error(`${keyName} is undefined, Amplitude analytics will not run.`)
if (typeof PROXY_URL === 'undefined') {
console.error('REACT_APP_AMPLITUDE_PROXY_URL is undefined, Amplitude analytics will not run.')
return
}
init(
API_KEY,
DUMMY_KEY,
/* userId= */ undefined, // User ID should be undefined to let Amplitude default to Device ID
/* options= */
{
// Configure the SDK to work with alternate endpoint
serverUrl: PROXY_URL,
// Disable tracking of private user information by Amplitude
trackingOptions: {
// IP is being dropped before ingestion on Amplitude side, only being used to determine country.
ipAddress: isProductionEnv() ? false : true,
ipAddress: false,
carrier: false,
city: false,
region: false,
@ -35,8 +35,7 @@ export function initializeAnalytics() {
/** Sends an event to Amplitude. */
export function sendAnalyticsEvent(eventName: string, eventProperties?: Record<string, unknown>) {
const origin = window.location.origin
if (!API_KEY) {
if (!PROXY_URL) {
console.log(`[analytics(${eventName})]: ${JSON.stringify(eventProperties)}`)
return
}