Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log all types of withdrawals as a single analytics event #151

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/trading-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhedge/trading-widget",
"version": "3.3.4",
"version": "3.3.5",
"license": "MIT",
"type": "module",
"main": "index.js",
Expand Down
27 changes: 26 additions & 1 deletion packages/trading-widget/src/core-kit/const/logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { TransactionAction } from 'core-kit/types'

export const TRADING_PANEL_LOG_EVENT = {
INVEST_INPUT_FOCUS: 'invest_input_focus',
APPROVED_TOKEN: 'approved_token',
Expand All @@ -13,10 +15,33 @@ export const TRADING_PANEL_LOG_EVENT = {
INFINITE_ALLOWANCE_CHANGE: 'infinite_allowance_change',
}

export const LOG_EVENT_BY_TRANSACTION_ACTION_MAP: Record<
TransactionAction,
string[]
> = {
approve: [TRADING_PANEL_LOG_EVENT.APPROVED_TOKEN],
oraclesUpdate: [TRADING_PANEL_LOG_EVENT.UPDATE_ORACLES],
deposit: [TRADING_PANEL_LOG_EVENT.DEPOSIT],
multi_withdraw: [
TRADING_PANEL_LOG_EVENT.WITHDRAWAL,
TRADING_PANEL_LOG_EVENT.MULTI_ASSET_WITHDRAW,
],
single_withdraw: [
TRADING_PANEL_LOG_EVENT.WITHDRAWAL,
TRADING_PANEL_LOG_EVENT.SINGLE_ASSET_WITHDRAW,
],
single_withdraw_and_claim: [
TRADING_PANEL_LOG_EVENT.WITHDRAWAL,
TRADING_PANEL_LOG_EVENT.SINGLE_ASSET_WITHDRAW_AND_CLAIM,
],
claim: [TRADING_PANEL_LOG_EVENT.CLAIM],
swap: [TRADING_PANEL_LOG_EVENT.SWAP],
}

/**
* Limits: Up to 50 custom event parameters per project;
* 40 must be numeric and 10 textual
* Parameter names can be up to 40 characters long alfanumeric with underscores
* Parameter names can be up to 40 characters long alphanumeric with underscores
* Parameter textual values can be up to 100 characters long
*/
export const TRADING_LOG_EVENT_PARAM = {
Expand Down
32 changes: 5 additions & 27 deletions packages/trading-widget/src/core-kit/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
LOG_EVENT_BY_TRANSACTION_ACTION_MAP,
TRADING_LOG_EVENT_PARAM,
TRADING_PANEL_LOG_EVENT,
} from 'core-kit/const'
import type {
TradingPanelActionsState,
Expand Down Expand Up @@ -38,30 +38,8 @@ export const logTransactionByActionType = ({
[TRADING_LOG_EVENT_PARAM.ADDRESS.NAME]:
transformAddressForAnalytics(vaultAddress),
}
switch (action) {
case 'approve':
log?.(TRADING_PANEL_LOG_EVENT.APPROVED_TOKEN, payload)
break
case 'oraclesUpdate':
log?.(TRADING_PANEL_LOG_EVENT.UPDATE_ORACLES, payload)
break
case 'deposit':
log?.(TRADING_PANEL_LOG_EVENT.DEPOSIT, payload)
break
case 'multi_withdraw':
log?.(TRADING_PANEL_LOG_EVENT.MULTI_ASSET_WITHDRAW, payload)
break
case 'single_withdraw':
log?.(TRADING_PANEL_LOG_EVENT.SINGLE_ASSET_WITHDRAW, payload)
break
case 'single_withdraw_and_claim':
log?.(TRADING_PANEL_LOG_EVENT.SINGLE_ASSET_WITHDRAW_AND_CLAIM, payload)
break
case 'claim':
log?.(TRADING_PANEL_LOG_EVENT.CLAIM, payload)
break
case 'swap':
log?.(TRADING_PANEL_LOG_EVENT.SWAP, payload)
break
}

LOG_EVENT_BY_TRANSACTION_ACTION_MAP[action].forEach((event) => {
log?.(event, payload)
})
}
Loading