Skip to content

Commit 70b6360

Browse files
STRATCONN-6300 - [Mixpanel Web] - more bugfixes (#3512)
* STRATCONN-6300 - [Mixpanel Web] - more bugfixes * types * removing default mappings for track and page
1 parent 8de8767 commit 70b6360

File tree

4 files changed

+34
-106
lines changed

4 files changed

+34
-106
lines changed

packages/browser-destinations/destinations/mixpanel-web/src/index.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@ export const destination: BrowserDestinationDefinition<Settings, Mixpanel> = {
4242
...rest
4343
} = settings
4444

45+
const numericKeys = new Set([
46+
'record_sessions_percent',
47+
'record_min_ms',
48+
'record_max_ms',
49+
'record_idle_timeout_ms',
50+
'cookie_expiration'
51+
])
52+
53+
const remainingSettings = Object.fromEntries(
54+
Object.entries(rest).flatMap(([key, value]) => {
55+
if (numericKeys.has(key)) {
56+
if (value === undefined || value === null || value === '') {
57+
return []
58+
}
59+
const num = Number(value)
60+
if (Number.isNaN(num)) {
61+
console.warn(`Setting "${key}" with value "${value}" cannot be converted to a number. Setting will be ignored.`)
62+
return []
63+
}
64+
return [[key, num]]
65+
}
66+
return [[key, value]]
67+
})
68+
)
69+
4570
const config: Config = {
4671
autocapture:
4772
autocapture === AUTOCAPTURE_OPTIONS.CUSTOM
@@ -59,7 +84,7 @@ export const destination: BrowserDestinationDefinition<Settings, Mixpanel> = {
5984
? true
6085
: false,
6186
persistence: persistence as PersistenceOptions,
62-
...rest
87+
...remainingSettings
6388
}
6489

6590
return new Promise<Mixpanel>((resolve) => {

packages/browser-destinations/destinations/mixpanel-web/src/track/index.ts

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -31,57 +31,7 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
3131
},
3232
user_profile_properties_to_set: {
3333
...user_profile_properties_to_set,
34-
default: {
35-
name: {
36-
'@if': {
37-
exists: { '@path': '$.context.traits.name' },
38-
then: { '@path': '$.context.traits.name' },
39-
else: { '@path': '$.properties.name' }
40-
}
41-
},
42-
first_name: {
43-
'@if': {
44-
exists: { '@path': '$.context.traits.first_name' },
45-
then: { '@path': '$.context.traits.first_name' },
46-
else: { '@path': '$.properties.first_name' }
47-
}
48-
},
49-
last_name: {
50-
'@if': {
51-
exists: { '@path': '$.context.traits.last_name' },
52-
then: { '@path': '$.context.traits.last_name' },
53-
else: { '@path': '$.properties.last_name' }
54-
}
55-
},
56-
email: {
57-
'@if': {
58-
exists: { '@path': '$.context.traits.email' },
59-
then: { '@path': '$.context.traits.email' },
60-
else: { '@path': '$.properties.email' }
61-
}
62-
},
63-
phone: {
64-
'@if': {
65-
exists: { '@path': '$.context.traits.phone' },
66-
then: { '@path': '$.context.traits.phone' },
67-
else: { '@path': '$.properties.phone' }
68-
}
69-
},
70-
avatar: {
71-
'@if': {
72-
exists: { '@path': '$.context.traits.avatar' },
73-
then: { '@path': '$.context.traits.avatar' },
74-
else: { '@path': '$.properties.avatar' }
75-
}
76-
},
77-
created: {
78-
'@if': {
79-
exists: { '@path': '$.context.traits.created_at' },
80-
then: { '@path': '$.context.traits.created_at' },
81-
else: { '@path': '$.properties.created_at' }
82-
}
83-
}
84-
}
34+
default: undefined
8535
},
8636
user_profile_properties_to_set_once,
8737
user_profile_properties_to_increment,

packages/browser-destinations/destinations/mixpanel-web/src/trackPageView/generated-types.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/browser-destinations/destinations/mixpanel-web/src/trackPageView/index.ts

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,68 +24,21 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
2424
fields: {
2525
event_name: {
2626
...event_name,
27-
default: undefined,
27+
default: {
28+
'@path': '$.name'
29+
},
2830
required: false
2931
},
3032
properties,
3133
unique_id: {
3234
...unique_id,
3335
description: 'The unique ID to associate with the user. Settings this value will trigger a Mixpanel identify call before immediately the page event is sent.',
34-
default: undefined
36+
default: undefined,
37+
required: false
3538
},
3639
user_profile_properties_to_set: {
3740
...user_profile_properties_to_set,
38-
default: {
39-
name: {
40-
'@if': {
41-
exists: { '@path': '$.context.traits.name' },
42-
then: { '@path': '$.context.traits.name' },
43-
else: { '@path': '$.properties.name' }
44-
}
45-
},
46-
first_name: {
47-
'@if': {
48-
exists: { '@path': '$.context.traits.first_name' },
49-
then: { '@path': '$.context.traits.first_name' },
50-
else: { '@path': '$.properties.first_name' }
51-
}
52-
},
53-
last_name: {
54-
'@if': {
55-
exists: { '@path': '$.context.traits.last_name' },
56-
then: { '@path': '$.context.traits.last_name' },
57-
else: { '@path': '$.properties.last_name' }
58-
}
59-
},
60-
email: {
61-
'@if': {
62-
exists: { '@path': '$.context.traits.email' },
63-
then: { '@path': '$.context.traits.email' },
64-
else: { '@path': '$.properties.email' }
65-
}
66-
},
67-
phone: {
68-
'@if': {
69-
exists: { '@path': '$.context.traits.phone' },
70-
then: { '@path': '$.context.traits.phone' },
71-
else: { '@path': '$.properties.phone' }
72-
}
73-
},
74-
avatar: {
75-
'@if': {
76-
exists: { '@path': '$.context.traits.avatar' },
77-
then: { '@path': '$.context.traits.avatar' },
78-
else: { '@path': '$.properties.avatar' }
79-
}
80-
},
81-
created: {
82-
'@if': {
83-
exists: { '@path': '$.context.traits.created_at' },
84-
then: { '@path': '$.context.traits.created_at' },
85-
else: { '@path': '$.properties.created_at' }
86-
}
87-
}
88-
}
41+
default: undefined
8942
},
9043
user_profile_properties_to_set_once,
9144
user_profile_properties_to_increment,

0 commit comments

Comments
 (0)