Skip to content

Commit ac36c6b

Browse files
authored
Merge pull request #11708 from ethereum/matomo-updates
Matomo updates
2 parents 3ed1e73 + 6a180f4 commit ac36c6b

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

src/components/Buttons/Button.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "@chakra-ui/react"
77

88
import { scrollIntoView } from "../../utils/scrollIntoView"
9+
import { type MatomoEventOptions, trackCustomEvent } from "../../utils/matomo"
910

1011
export const checkIsSecondary = (props: {
1112
variant?: string
@@ -33,15 +34,15 @@ export interface IProps extends ButtonProps {
3334
* `NOTE`: Does not apply to the `Solid` or `Link` variants
3435
*/
3536
isSecondary?: boolean
37+
customEventOptions?: MatomoEventOptions
3638
}
3739

3840
const Button = forwardRef<IProps, "button">((props, ref) => {
39-
const { toId, onClick, isSecondary, ...rest } = props
41+
const { toId, onClick, isSecondary, customEventOptions, ...rest } = props
4042

4143
const handleOnClick = (e: React.MouseEvent<HTMLButtonElement>) => {
42-
if (toId) {
43-
scrollIntoView(toId)
44-
}
44+
toId && scrollIntoView(toId)
45+
customEventOptions && trackCustomEvent(customEventOptions)
4546

4647
onClick?.(e)
4748
}

src/components/FindWallet/WalletTable/index.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,13 @@ const WalletTable = ({ data, filters, walletData }: WalletTableProps) => {
427427
<Wallet
428428
onClick={() => {
429429
updateMoreInfo(wallet.key)
430-
trackCustomEvent({
431-
eventCategory: "WalletMoreInfo",
432-
eventAction: `More info wallet`,
433-
eventName: `More info ${wallet.name} ${wallet.moreInfo}`,
434-
})
430+
// Log "more info" event only on expanding
431+
wallet.moreInfo &&
432+
trackCustomEvent({
433+
eventCategory: "WalletMoreInfo",
434+
eventAction: `More info wallet`,
435+
eventName: `More info ${wallet.name}`,
436+
})
435437
}}
436438
>
437439
<Td lineHeight="revert">
@@ -473,7 +475,7 @@ const WalletTable = ({ data, filters, walletData }: WalletTableProps) => {
473475
customEventOptions={{
474476
eventCategory: "WalletExternalLinkList",
475477
eventAction: `Go to wallet`,
476-
eventName: `${wallet.name} ${idx}`,
478+
eventName: `Website: ${wallet.name} ${idx}`,
477479
eventValue: JSON.stringify(filters),
478480
}}
479481
>
@@ -486,7 +488,7 @@ const WalletTable = ({ data, filters, walletData }: WalletTableProps) => {
486488
customEventOptions={{
487489
eventCategory: "WalletExternalLinkList",
488490
eventAction: `Go to wallet`,
489-
eventName: `${wallet.name} ${idx}`,
491+
eventName: `Twitter: ${wallet.name} ${idx}`,
490492
eventValue: JSON.stringify(filters),
491493
}}
492494
>
@@ -504,7 +506,7 @@ const WalletTable = ({ data, filters, walletData }: WalletTableProps) => {
504506
customEventOptions={{
505507
eventCategory: "WalletExternalLinkList",
506508
eventAction: `Go to wallet`,
507-
eventName: `${wallet.name} ${idx}`,
509+
eventName: `Discord: ${wallet.name} ${idx}`,
508510
eventValue: JSON.stringify(filters),
509511
}}
510512
>

src/utils/matomo.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@ export const trackCustomEvent = ({
1313
eventName,
1414
eventValue,
1515
}: MatomoEventOptions): void => {
16-
if (process.env.NODE_ENV === "production" || window.dev === true) {
17-
const optedOutValue = localStorage.getItem(MATOMO_LS_KEY) || "false"
18-
const isOptedOut = JSON.parse(optedOutValue)
19-
if (!window._paq || isOptedOut) return
16+
if (process.env.NODE_ENV !== "production" && !window.dev) return
17+
const optedOutValue = localStorage.getItem(MATOMO_LS_KEY) || "false"
18+
const isOptedOut = JSON.parse(optedOutValue)
19+
if (!window._paq || isOptedOut) return
2020

21-
const { _paq, dev } = window
21+
const { _paq, dev } = window
2222

23-
_paq.push([`trackEvent`, eventCategory, eventAction, eventName, eventValue])
23+
_paq.push([`trackEvent`, eventCategory, eventAction, eventName, eventValue])
24+
if (!dev) return
2425

25-
if (dev) {
26-
console.debug(
27-
`[Matomo] event tracked, category: ${eventCategory}, action: ${eventAction}, name: ${eventName}, value: ${eventValue}`
28-
)
29-
}
30-
}
26+
console.debug(
27+
`[Matomo] event tracked, category: ${eventCategory}, action: ${eventAction}, name: ${eventName}, value: ${eventValue}`
28+
)
3129
}

0 commit comments

Comments
 (0)