Commit 4ef3746a authored by Moody Salem's avatar Moody Salem Committed by GitHub

Add GA instrumentation to v2 (#769)

parent d2462af8
import React, { useState, useCallback, useEffect, useContext } from 'react' import React, { useState, useCallback, useEffect, useContext } from 'react'
import ReactGA from 'react-ga'
import { ThemeContext } from 'styled-components' import { ThemeContext } from 'styled-components'
import { parseEther, parseUnits } from '@ethersproject/units' import { parseEther, parseUnits } from '@ethersproject/units'
import { JSBI, Percent, TokenAmount, TradeType, WETH, Fraction } from '@uniswap/sdk' import { JSBI, Percent, TokenAmount, TradeType, WETH, Fraction } from '@uniswap/sdk'
...@@ -75,7 +76,7 @@ const DEFAULT_DEADLINE_FROM_NOW = 60 * 20 ...@@ -75,7 +76,7 @@ const DEFAULT_DEADLINE_FROM_NOW = 60 * 20
const ALLOWED_SLIPPAGE_MEDIUM = 100 const ALLOWED_SLIPPAGE_MEDIUM = 100
const ALLOWED_SLIPPAGE_HIGH = 500 const ALLOWED_SLIPPAGE_HIGH = 500
interface ExchangePageProps extends RouteComponentProps<{}> { interface ExchangePageProps extends RouteComponentProps {
sendingInput: boolean sendingInput: boolean
params: QueryParams params: QueryParams
} }
...@@ -384,6 +385,7 @@ function ExchangePage({ sendingInput = false, history, params }: ExchangePagePro ...@@ -384,6 +385,7 @@ function ExchangePage({ sendingInput = false, history, params }: ExchangePagePro
.sendTransaction({ to: recipient.toString(), value: BigNumber.from(parsedAmounts[Field.INPUT].raw.toString()) }) .sendTransaction({ to: recipient.toString(), value: BigNumber.from(parsedAmounts[Field.INPUT].raw.toString()) })
.then(response => { .then(response => {
setTxHash(response.hash) setTxHash(response.hash)
ReactGA.event({ category: 'ExchangePage', action: 'Send', label: tokens[Field.INPUT]?.symbol })
addTransaction(response, { addTransaction(response, {
summary: summary:
'Send ' + 'Send ' +
...@@ -520,6 +522,11 @@ function ExchangePage({ sendingInput = false, history, params }: ExchangePagePro ...@@ -520,6 +522,11 @@ function ExchangePage({ sendingInput = false, history, params }: ExchangePagePro
gasLimit: calculateGasMargin(estimatedGasLimit) gasLimit: calculateGasMargin(estimatedGasLimit)
}).then(response => { }).then(response => {
setTxHash(response.hash) setTxHash(response.hash)
ReactGA.event({
category: 'ExchangePage',
label: sending && recipient !== account ? 'Swap w/ Send' : 'Swap',
action: [tokens[Field.INPUT]?.symbol, tokens[Field.OUTPUT]?.symbol].join(';')
})
addTransaction(response, { addTransaction(response, {
summary: summary:
'Swap ' + 'Swap ' +
......
import React, { useCallback, useState } from 'react' import React, { useCallback, useState } from 'react'
import { AlertCircle, CheckCircle } from 'react-feather' import { AlertCircle, CheckCircle } from 'react-feather'
import styled from 'styled-components' import styled from 'styled-components'
......
...@@ -33,8 +33,6 @@ if (process.env.NODE_ENV === 'production') { ...@@ -33,8 +33,6 @@ if (process.env.NODE_ENV === 'production') {
ReactGA.initialize('test', { testMode: true, debug: true }) ReactGA.initialize('test', { testMode: true, debug: true })
} }
ReactGA.pageview(window.location.pathname + window.location.search)
function Updaters() { function Updaters() {
return ( return (
<> <>
......
import React, { Suspense } from 'react' import React, { Suspense, useEffect } from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import { BrowserRouter, Redirect, Route, Switch } from 'react-router-dom' import ReactGA from 'react-ga'
import { BrowserRouter, Redirect, Route, RouteComponentProps, Switch } from 'react-router-dom'
import Header from '../components/Header' import Header from '../components/Header'
import Footer from '../components/Footer' import Footer from '../components/Footer'
...@@ -91,6 +92,14 @@ const StyledRed = styled.div` ...@@ -91,6 +92,14 @@ const StyledRed = styled.div`
} }
` `
// fires a GA pageview every time the route changes
function GoogleAnalyticsReporter({ location: { pathname, search } }: RouteComponentProps) {
useEffect(() => {
ReactGA.pageview(`${pathname}${search}`)
}, [pathname, search])
return null
}
export default function App() { export default function App() {
const params = getAllQueryParams() const params = getAllQueryParams()
...@@ -98,6 +107,7 @@ export default function App() { ...@@ -98,6 +107,7 @@ export default function App() {
<> <>
<Suspense fallback={null}> <Suspense fallback={null}>
<BrowserRouter> <BrowserRouter>
<Route component={GoogleAnalyticsReporter} />
<AppWrapper> <AppWrapper>
<HeaderWrapper> <HeaderWrapper>
<Header /> <Header />
......
import React, { useReducer, useState, useCallback, useEffect, useContext } from 'react' import React, { useReducer, useState, useCallback, useEffect, useContext } from 'react'
import ReactGA from 'react-ga'
import styled, { ThemeContext } from 'styled-components' import styled, { ThemeContext } from 'styled-components'
import { RouteComponentProps, withRouter } from 'react-router-dom' import { RouteComponentProps, withRouter } from 'react-router-dom'
import { parseUnits, parseEther } from '@ethersproject/units' import { parseUnits, parseEther } from '@ethersproject/units'
...@@ -497,6 +498,11 @@ function AddLiquidity({ token0, token1 }: AddLiquidityProps) { ...@@ -497,6 +498,11 @@ function AddLiquidity({ token0, token1 }: AddLiquidityProps) {
...(value ? { value } : {}), ...(value ? { value } : {}),
gasLimit: calculateGasMargin(estimatedGasLimit) gasLimit: calculateGasMargin(estimatedGasLimit)
}).then(response => { }).then(response => {
ReactGA.event({
category: 'Liquidity',
action: 'Add',
label: [tokens[Field.INPUT]?.symbol, tokens[Field.OUTPUT]?.symbol].join(';')
})
setTxHash(response.hash) setTxHash(response.hash)
addTransaction(response, { addTransaction(response, {
summary: summary:
......
import React, { useReducer, useState, useCallback, useEffect, useContext } from 'react' import React, { useReducer, useState, useCallback, useEffect, useContext } from 'react'
import ReactGA from 'react-ga'
import styled, { ThemeContext } from 'styled-components' import styled, { ThemeContext } from 'styled-components'
import { parseUnits } from '@ethersproject/units' import { parseUnits } from '@ethersproject/units'
import { Contract } from '@ethersproject/contracts' import { Contract } from '@ethersproject/contracts'
...@@ -490,6 +491,11 @@ export default function RemoveLiquidity({ token0, token1 }: { token0: string; to ...@@ -490,6 +491,11 @@ export default function RemoveLiquidity({ token0, token1 }: { token0: string; to
method(...args, { method(...args, {
gasLimit: calculateGasMargin(estimatedGasLimit) gasLimit: calculateGasMargin(estimatedGasLimit)
}).then(response => { }).then(response => {
ReactGA.event({
category: 'Liquidity',
action: 'Remove',
label: [tokens[Field.TOKEN0]?.symbol, tokens[Field.TOKEN1]?.symbol].join(';')
})
setPendingConfirmation(false) setPendingConfirmation(false)
setTxHash(response.hash) setTxHash(response.hash)
addTransaction(response, { addTransaction(response, {
......
import React, { HTMLProps, useCallback } from 'react'
import ReactGA from 'react-ga'
import styled, { keyframes } from 'styled-components' import styled, { keyframes } from 'styled-components'
import { darken } from 'polished' import { darken } from 'polished'
import { X } from 'react-feather' import { X } from 'react-feather'
...@@ -36,10 +38,7 @@ export const CloseIcon = styled(X)<{ onClick: () => void }>` ...@@ -36,10 +38,7 @@ export const CloseIcon = styled(X)<{ onClick: () => void }>`
cursor: pointer; cursor: pointer;
` `
export const Link = styled.a.attrs({ const StyledLink = styled.a`
target: '_blank',
rel: 'noopener noreferrer'
})`
text-decoration: none; text-decoration: none;
cursor: pointer; cursor: pointer;
color: ${({ theme }) => theme.primary1}; color: ${({ theme }) => theme.primary1};
...@@ -59,6 +58,31 @@ export const Link = styled.a.attrs({ ...@@ -59,6 +58,31 @@ export const Link = styled.a.attrs({
} }
` `
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function Link({ onClick, as, ref, target, href, rel, ...rest }: HTMLProps<HTMLAnchorElement>) {
const handleClick = useCallback(
(event: React.MouseEvent<HTMLAnchorElement>) => {
onClick && onClick(event) // first call back into the original onClick
if (!href) return
event.preventDefault()
// send a ReactGA event and then trigger a location change
ReactGA.outboundLink({ label: href }, () => {
window.location.href = href
})
},
[href, onClick]
)
return (
<StyledLink
target={target ?? '_blank'}
rel={rel ?? 'noopener noreferrer'}
href={href}
onClick={handleClick}
{...rest}
/>
)
}
const rotate = keyframes` const rotate = keyframes`
from { from {
transform: rotate(0deg); transform: rotate(0deg);
......
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