Skip to content

Commit 4ebdfb5

Browse files
committed
track dnd events
1 parent d37aacc commit 4ebdfb5

4 files changed

Lines changed: 34 additions & 7 deletions

File tree

src/App.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@ function App() {
3838
// eslint-disable-next-line react-hooks/exhaustive-deps
3939
}, [onboardingCompleted, firstSeenDate])
4040

41-
useEffect(() => {
41+
useLayoutEffect(() => {
4242
document.documentElement.style.setProperty('--max-visible-cards', maxVisibleCards)
4343
}, [maxVisibleCards])
4444

4545
useEffect(() => {
4646
setupAnalytics()
4747
setupIdentification()
48-
trackPageView('home')
4948
}, [])
5049

50+
useEffect(() => {
51+
trackPageView('home', isDNDModeActive())
52+
}, [DNDDurarion, isDNDModeActive])
53+
5154
const callback = (entries) => {
5255
entries.forEach((entry) => {
5356
if (!entry.isIntersecting) {

src/components/Layout/Header.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { SearchBar } from 'src/components/Elements/SearchBar'
88
import { UserTags } from 'src/components/Elements/UserTags'
99
import { Changelog } from 'src/features/changelog'
1010
import { SettingsModal } from 'src/features/settings'
11-
import { identifyUserTheme, trackThemeSelect } from 'src/lib/analytics'
11+
import { identifyUserTheme, trackDNDDisable, trackThemeSelect } from 'src/lib/analytics'
1212
import { useBookmarks } from 'src/stores/bookmarks'
1313
import { useUserPreferences } from 'src/stores/preferences'
1414

@@ -75,6 +75,7 @@ export const Header = ({
7575
}
7676

7777
const onUnpauseClicked = () => {
78+
trackDNDDisable()
7879
setDNDDuration(0)
7980
}
8081

src/features/settings/components/DNDSettings.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState } from 'react'
22
import Select, { SingleValue } from 'react-select'
3+
import { trackDNDEnable } from 'src/lib/analytics'
34
import { useUserPreferences } from 'src/stores/preferences'
45

56
type DndOption = {
@@ -36,6 +37,7 @@ export const DNDSettings = ({ setShowSettings }: DNDSettingsProps) => {
3637
setDNDDuration(futureDate.getTime())
3738
}
3839

40+
trackDNDEnable(selectedDNDDuration)
3941
setShowSettings(false)
4042
}
4143

src/lib/analytics.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum Objects {
2020
MARKETING_CAMPAIGN = 'Marketing Campaign',
2121
ONBOARDING = 'Onboarding',
2222
RSS = 'Rss',
23+
DO_NOT_DISTURB = 'DND',
2324
}
2425

2526
enum Verbs {
@@ -38,7 +39,9 @@ enum Verbs {
3839
FINISH = 'Finish',
3940
SKIP = 'Skip',
4041
DRAG = 'Drag',
41-
Change = 'Change',
42+
CHANGE = 'Change',
43+
ENABLE = "Enable",
44+
DISABLE = "Disable"
4245
}
4346

4447
export enum Attributes {
@@ -62,6 +65,7 @@ export enum Attributes {
6265
CAMPAIGN_ID = 'Campaign Id',
6366
OCCUPATION = 'Occupation',
6467
MAX_VISIBLE_CARDS = 'Max Visible Cards',
68+
DURATION = 'DURATION',
6569
}
6670

6771
const _SEP_ = ' '
@@ -100,11 +104,13 @@ export const setupIdentification = () => {
100104
}
101105
}
102106

103-
export const trackPageView = (pageName: string) => {
107+
export const trackPageView = (pageName: string, dndModeActive: boolean = false) => {
104108
trackEvent({
105109
object: Objects.PAGE,
106110
verb: Verbs.VIEW,
107-
attributes: { [Attributes.PAGE_NAME]: pageName },
111+
attributes: {
112+
[Attributes.PAGE_NAME]: pageName,
113+
[Objects.DO_NOT_DISTURB]: dndModeActive ? "on" : "off" },
108114
})
109115
}
110116

@@ -298,11 +304,26 @@ export const trackPageDrag = () => {
298304
export const trackMaxVisibleCardsChange = (maxVisibleCards: number) => {
299305
trackEvent({
300306
object: Objects.CARD,
301-
verb: Verbs.Change,
307+
verb: Verbs.CHANGE,
302308
attributes: {[Attributes.MAX_VISIBLE_CARDS]: maxVisibleCards}
303309
})
304310
}
305311

312+
export const trackDNDEnable = (duration: number | "always") => {
313+
trackEvent({
314+
object: Objects.DO_NOT_DISTURB,
315+
verb: Verbs.ENABLE,
316+
attributes: {[Attributes.DURATION]: duration}
317+
})
318+
}
319+
320+
export const trackDNDDisable = () => {
321+
trackEvent({
322+
object: Objects.DO_NOT_DISTURB,
323+
verb: Verbs.DISABLE
324+
})
325+
}
326+
306327
// Identification
307328

308329
export const identifyUserLanguages = (languages: string[]) => {

0 commit comments

Comments
 (0)