Skip to content

Commit 6a180f4

Browse files
committed
[chore] refactor using guard clauses
1 parent 3c84ce3 commit 6a180f4

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

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)