@@ -14,8 +14,8 @@ import SettingsDropdown from 'components/buySell/SettingsDropdown'
1414import useSwapEstimator from 'hooks/useSwapEstimator'
1515import withIsMobile from 'hoc/withIsMobile'
1616import ApproveSwap from 'components/buySell/ApproveSwap'
17- import analytics from 'utils/analytics'
1817import { formatCurrencyMinMaxDecimals , removeCommas } from '../../utils/math'
18+ import { event } from '../../../lib/gtm'
1919
2020const lastUserSelectedCoinKey = 'last_user_selected_coin'
2121const lastSelectedSwapModeKey = 'last_user_selected_swap_mode'
@@ -205,14 +205,16 @@ const SwapHomepage = ({
205205 }
206206
207207 const onSwapOusd = async ( ) => {
208- analytics . track (
209- swapMode === 'mint' ? 'On Swap to OUSD' : 'On Swap from OUSD' ,
210- {
211- category : 'swap' ,
212- label : swapMetadata . stablecoinUsed ,
213- value : swapMetadata . swapAmount ,
214- }
215- )
208+ const swapTokenUsed =
209+ swapMode === 'mint' ? selectedBuyCoin : selectedRedeemCoin
210+ const swapTokenAmount =
211+ swapMode === 'mint' ? selectedBuyCoinAmount : selectedRedeemCoinAmount
212+
213+ event ( {
214+ event : 'swap_started' ,
215+ swap_token : swapTokenUsed ,
216+ swap_amount : swapTokenAmount ,
217+ } )
216218
217219 const metadata = swapMetadata ( )
218220
@@ -255,23 +257,29 @@ const SwapHomepage = ({
255257 setSelectedRedeemCoinAmount ( '' )
256258
257259 await rpcProvider . waitForTransaction ( result . hash )
258- analytics . track ( 'Swap succeeded' , {
259- category : 'swap' ,
260- label : metadata . stablecoinUsed ,
261- value : metadata . swapAmount ,
260+ event ( {
261+ event : 'swap_complete' ,
262+ swap_type : swapMode ,
263+ swap_token : swapTokenUsed ,
264+ swap_amount : swapTokenAmount ,
262265 } )
263266 } catch ( e ) {
264267 const metadata = swapMetadata ( )
265268 // 4001 code happens when a user rejects the transaction
266269 if ( e . code !== 4001 ) {
267270 await storeTransactionError ( swapMode , selectedBuyCoin )
268- analytics . track ( 'Swap failed' , {
269- category : 'swap' ,
270- label : e . message ,
271+ event ( {
272+ event : 'swap_failed' ,
273+ swap_type : swapMode ,
274+ swap_token : swapTokenUsed ,
275+ swap_amount : swapTokenAmount ,
271276 } )
272277 } else {
273- analytics . track ( 'Swap canceled' , {
274- category : 'swap' ,
278+ event ( {
279+ event : 'swap_rejected' ,
280+ swap_type : swapMode ,
281+ swap_token : swapTokenUsed ,
282+ swap_amount : swapTokenAmount ,
275283 } )
276284 }
277285
@@ -311,6 +319,12 @@ const SwapHomepage = ({
311319 onAmountChange = { async ( amount ) => {
312320 setSelectedBuyCoinAmount ( amount )
313321 setSelectedRedeemCoinAmount ( amount )
322+ if ( amount > 0 ) {
323+ event ( {
324+ event : 'change_input_amount' ,
325+ change_amount_to : amount ,
326+ } )
327+ }
314328 } }
315329 coinValue = {
316330 swapMode === 'mint'
0 commit comments