Commit 7786537c authored by Ian Lapham's avatar Ian Lapham Committed by GitHub

add txn hash to analytics (#632)

parent 518f3842
......@@ -15,7 +15,6 @@ import { useTransactionAdder } from '../../contexts/Transactions'
import { useAddressBalance, useExchangeReserves } from '../../contexts/Balances'
import { useAddressAllowance } from '../../contexts/Allowances'
import { useWalletModalToggle } from '../../contexts/Application'
import { useETHPriceInUSD } from '../../contexts/Balances'
import { Button } from '../../theme'
import CurrencyInputPanel from '../CurrencyInputPanel'
......@@ -262,9 +261,6 @@ export default function ExchangePage({ initialCurrency, sending = false, params
urlAddedTokens[initialCurrency] = true
}
// BigNumber.js instance
const ethPrice = useETHPriceInUSD()
const addTransaction = useTransactionAdder()
// check if URL specifies valid slippage, if so use as default
......@@ -633,16 +629,16 @@ export default function ExchangePage({ initialCurrency, sending = false, params
if (inputCurrency !== 'ETH') {
inputEthPerToken = inputReserveToken && inputReserveETH ? inputReserveETH / inputReserveToken : null
}
let usdTransactionSize = ethPrice * inputEthPerToken * inputValueFormatted
let ethTransactionSize = inputEthPerToken * inputValueFormatted
// params for GA event
let action = ''
let label = ''
if (independentField === INPUT) {
// general details about transaction
ReactGA.event({
category: 'Transaction',
action: sending ? 'SendInput' : 'SwapInput',
label: outputCurrency,
value: usdTransactionSize
})
// set GA params
action = sending ? 'SendInput' : 'SwapInput'
label = outputCurrency
if (swapType === ETH_TO_TOKEN) {
estimate = sending ? contract.estimate.ethToTokenTransferInput : contract.estimate.ethToTokenSwapInput
......@@ -672,13 +668,9 @@ export default function ExchangePage({ initialCurrency, sending = false, params
value = ethers.constants.Zero
}
} else if (independentField === OUTPUT) {
// general details about transaction
ReactGA.event({
category: 'Transaction',
action: sending ? 'SendOutput' : 'SwapOutput',
label: outputCurrency,
value: usdTransactionSize
})
// set GA params
action = sending ? 'SendOutput' : 'SwapOutput'
label = outputCurrency
if (swapType === ETH_TO_TOKEN) {
estimate = sending ? contract.estimate.ethToTokenTransferOutput : contract.estimate.ethToTokenSwapOutput
......@@ -715,6 +707,18 @@ export default function ExchangePage({ initialCurrency, sending = false, params
gasLimit: calculateGasMargin(estimatedGasLimit, GAS_MARGIN)
}).then(response => {
addTransaction(response)
ReactGA.event({
category: 'Transaction',
action: action,
label: label,
value: ethTransactionSize,
dimension1: response.hash
})
ReactGA.event({
category: 'Hash',
action: response.hash,
label: ethTransactionSize.toString()
})
})
}
......
......@@ -17,7 +17,7 @@ import { brokenTokens } from '../../constants'
import { amountFormatter, calculateGasMargin } from '../../utils'
import { useTransactionAdder } from '../../contexts/Transactions'
import { useTokenDetails, INITIAL_TOKENS_CONTEXT } from '../../contexts/Tokens'
import { useAddressBalance, useExchangeReserves, useETHPriceInUSD } from '../../contexts/Balances'
import { useAddressBalance, useExchangeReserves } from '../../contexts/Balances'
import { useAddressAllowance } from '../../contexts/Allowances'
const INPUT = 0
......@@ -202,9 +202,6 @@ export default function AddLiquidity({ params }) {
const { t } = useTranslation()
const { library, account, active, chainId } = useWeb3React()
// BigNumber.js instance
const ethPrice = useETHPriceInUSD()
const urlAddedTokens = {}
if (params.token) {
urlAddedTokens[params.token] = true
......@@ -390,15 +387,7 @@ export default function AddLiquidity({ params }) {
async function onAddLiquidity() {
// take ETH amount, multiplied by ETH rate and 2 for total tx size
let usdTransactionSize = ethPrice * (inputValueParsed / 1e18) * 2
// log pool added to and total usd amount
ReactGA.event({
category: 'Transaction',
action: 'Add Liquidity',
label: outputCurrency,
value: usdTransactionSize
})
let ethTransactionSize = (inputValueParsed / 1e18) * 2
const deadline = Math.ceil(Date.now() / 1000) + DEADLINE_FROM_NOW
......@@ -424,6 +413,19 @@ export default function AddLiquidity({ params }) {
}
)
.then(response => {
// log pool added to and total usd amount
ReactGA.event({
category: 'Transaction',
action: 'Add Liquidity',
label: outputCurrency,
value: ethTransactionSize,
dimension1: response.hash
})
ReactGA.event({
category: 'Hash',
action: response.hash,
label: ethTransactionSize.toString()
})
addTransaction(response)
})
}
......
......@@ -8,7 +8,7 @@ import styled from 'styled-components'
import { useWeb3React, useExchangeContract } from '../../hooks'
import { useTransactionAdder } from '../../contexts/Transactions'
import { useTokenDetails, INITIAL_TOKENS_CONTEXT } from '../../contexts/Tokens'
import { useAddressBalance, useETHPriceInUSD } from '../../contexts/Balances'
import { useAddressBalance } from '../../contexts/Balances'
import { calculateGasMargin, amountFormatter } from '../../utils'
import { brokenTokens } from '../../constants'
......@@ -268,18 +268,9 @@ export default function RemoveLiquidity({ params }) {
}
}, [fetchPoolTokens, library])
// BigNumber.js instance
const ethPrice = useETHPriceInUSD()
async function onRemoveLiquidity() {
// take ETH amount, multiplied by ETH rate and 2 for total tx size
let usdTransactionSize = ethPrice * (ethWithdrawn / 1e18) * 2
ReactGA.event({
category: 'Transaction',
action: 'Remove Liquidity',
label: outputCurrency,
value: usdTransactionSize
})
let ethTransactionSize = (ethWithdrawn / 1e18) * 2
const deadline = Math.ceil(Date.now() / 1000) + DEADLINE_FROM_NOW
......@@ -295,6 +286,19 @@ export default function RemoveLiquidity({ params }) {
gasLimit: calculateGasMargin(estimatedGasLimit, GAS_MARGIN)
})
.then(response => {
ReactGA.event({
category: 'Transaction',
action: 'Remove Liquidity',
label: outputCurrency,
value: ethTransactionSize,
dimension1: response.hash
})
ReactGA.event({
category: 'Hash',
action: response.hash,
label: ethTransactionSize.toString(),
value: ethTransactionSize
})
addTransaction(response)
})
}
......
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