Skip to content

Commit 1f86367

Browse files
committed
track max visible cards feature
1 parent 1e89a07 commit 1f86367

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/features/settings/components/SettingsModal.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import {
1313
identifyUserLanguages,
1414
identifyUserLinksInNewTab,
1515
identifyUserListingMode,
16+
identifyUserMaxVisibleCards,
1617
identifyUserSearchEngine,
1718
identifyUserTheme,
1819
trackLanguageAdd,
1920
trackLanguageRemove,
2021
trackListingModeSelect,
22+
trackMaxVisibleCardsChange,
2123
trackSearchEngineSelect,
2224
trackSourceAdd,
2325
trackSourceRemove,
@@ -147,9 +149,12 @@ export const SettingsModal = ({ showSettings, setShowSettings }: SettingsModalPr
147149
identifyUserTheme(newTheme)
148150
}
149151

150-
const onCardsCountChange = (selectedChips: Option[]) => {
152+
const onMaxVisibleCardsChange = (selectedChips: Option[]) => {
151153
if (selectedChips.length) {
152-
setMaxVisibleCards(parseInt(selectedChips[0].value))
154+
const maxVisibleCards = parseInt(selectedChips[0].value)
155+
setMaxVisibleCards(maxVisibleCards)
156+
identifyUserMaxVisibleCards(maxVisibleCards)
157+
trackMaxVisibleCardsChange(maxVisibleCards)
153158
}
154159
}
155160

@@ -250,7 +255,7 @@ export const SettingsModal = ({ showSettings, setShowSettings }: SettingsModalPr
250255
]}
251256
defaultValues={[maxVisibleCards.toString()]}
252257
onChange={(_, selectedChips) => {
253-
onCardsCountChange(selectedChips)
258+
onMaxVisibleCardsChange(selectedChips)
254259
}}
255260
/>
256261

src/lib/analytics.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum Verbs {
3838
FINISH = 'Finish',
3939
SKIP = 'Skip',
4040
DRAG = 'Drag',
41+
Change = 'Change',
4142
}
4243

4344
export enum Attributes {
@@ -60,6 +61,7 @@ export enum Attributes {
6061
SOURCE_TAGS = 'Source Tags',
6162
CAMPAIGN_ID = 'Campaign Id',
6263
OCCUPATION = 'Occupation',
64+
MAX_VISIBLE_CARDS = 'Max Visible Cards',
6365
}
6466

6567
const _SEP_ = ' '
@@ -82,6 +84,7 @@ export const setupIdentification = () => {
8284
listingMode,
8385
openLinksNewTab,
8486
searchEngine,
87+
maxVisibleCards
8588
} = useUserPreferences.getState()
8689

8790
identifyUserProperty(Attributes.RESOLUTION, getScreenResolution())
@@ -91,6 +94,7 @@ export const setupIdentification = () => {
9194
identifyUserListingMode(listingMode)
9295
identifyUserSearchEngine(searchEngine)
9396
identifyUserLinksInNewTab(openLinksNewTab)
97+
identifyUserMaxVisibleCards(maxVisibleCards)
9498
if (onboardingResult?.title) {
9599
identifyUserOccupation(onboardingResult.title)
96100
}
@@ -291,6 +295,14 @@ export const trackPageDrag = () => {
291295
})
292296
}
293297

298+
export const trackMaxVisibleCardsChange = (maxVisibleCards: number) => {
299+
trackEvent({
300+
object: Objects.CARD,
301+
verb: Verbs.Change,
302+
attributes: {[Attributes.MAX_VISIBLE_CARDS]: maxVisibleCards}
303+
})
304+
}
305+
294306
// Identification
295307

296308
export const identifyUserLanguages = (languages: string[]) => {
@@ -317,7 +329,9 @@ export const identifyUserLinksInNewTab = (enabled: boolean) => {
317329
export const identifyUserOccupation = (occupation: string) => {
318330
identifyUserProperty(Attributes.OCCUPATION, occupation)
319331
}
320-
332+
export const identifyUserMaxVisibleCards = (maxVisibleCards: number) => {
333+
identifyUserProperty(Attributes.MAX_VISIBLE_CARDS, maxVisibleCards)
334+
}
321335

322336
// Private functions
323337
type trackEventProps = {
@@ -365,13 +379,13 @@ const trackEvent = ({ object, verb, attributes }: trackEventProps) => {
365379
}
366380
}
367381

368-
const identifyUserProperty = (attributes: Attributes, value: string | string[]) => {
382+
const identifyUserProperty = (attributes: Attributes, value: string | number | string[]) => {
369383
try {
370384
let formatedValue
371385
if (Array.isArray(value)) {
372386
formatedValue = value.filter(Boolean).map((item) => item.toLowerCase())
373387
} else {
374-
formatedValue = value.toLowerCase()
388+
formatedValue = typeof value === "string" ? value.toLowerCase() : value.toString()
375389
}
376390

377391
if (isDevelopment()) {

0 commit comments

Comments
 (0)