Skip to content

Commit f524e4d

Browse files
committed
add changelog analytics event
1 parent ac28ef2 commit f524e4d

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

src/lib/analytics.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ enum Objects {
1515
CARD = 'Card',
1616
SEARCH_ENGINE = 'Search Engine',
1717
LISTING_MODE = 'Listing Mode',
18+
CHANGE_LOG = 'Change Log',
1819
}
1920

2021
enum Verbs {
@@ -206,6 +207,13 @@ export const trackCardDateRangeSelect = (sourceName: string, dateRange: string)
206207
})
207208
}
208209

210+
export const trackChangeLogOpen = () => {
211+
trackEvent({
212+
object: Objects.CHANGE_LOG,
213+
verb: Verbs.OPEN
214+
})
215+
}
216+
209217
// Identification
210218

211219
export const identifyUserLanguages = (languages: string[]) => {
@@ -233,7 +241,7 @@ export const identifyUserLinksInNewTab = (enabled: boolean) => {
233241
type trackEventProps = {
234242
object: Exclude<Objects, null | undefined>,
235243
verb: Exclude<Verbs, null | undefined>,
236-
attributes: {
244+
attributes?: {
237245
//[P in Exclude<Attributes, null | undefined>]?: string;
238246
[P: string]: string;
239247
}
@@ -242,17 +250,20 @@ type trackEventProps = {
242250
const trackEvent = ({ object, verb, attributes }: trackEventProps) => {
243251
try {
244252
const event = `${object}${_SEP_}${verb}`
245-
Object.keys(attributes).map(attr => {
246-
const value = attributes[attr];
247-
if (typeof value !== "number") {
248-
attributes[attr] = value.toLowerCase();
249-
}
250-
return attr;
251-
});
252253

253-
// Remove http and www from links
254-
if (Object.keys(attributes).some((attr) => attr == Attributes.LINK)) {
255-
attributes[Attributes.LINK] = attributes[Attributes.LINK].replace(/(https*:\/\/[www.]*)/, '')
254+
if (attributes) {
255+
Object.keys(attributes).map(attr => {
256+
const value = attributes[attr];
257+
if (typeof value !== "number") {
258+
attributes[attr] = value.toLowerCase();
259+
}
260+
return attr;
261+
});
262+
263+
// Remove http and www from links
264+
if (Object.keys(attributes).some((attr) => attr == Attributes.LINK)) {
265+
attributes[Attributes.LINK] = attributes[Attributes.LINK].replace(/(https*:\/\/[www.]*)/, '')
266+
}
256267
}
257268

258269
if (isDevelopment()) {

0 commit comments

Comments
 (0)