@segment/analytics-browser-mixpanel-web-actions 1.4.0 → 1.4.1-staging-154441964.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/fields.js.map +1 -1
- package/dist/cjs/functions.js.map +1 -1
- package/dist/cjs/init-script.js +59 -15
- package/dist/cjs/init-script.js.map +1 -1
- package/dist/cjs/setting-fields.js +1 -1
- package/dist/cjs/setting-fields.js.map +1 -1
- package/dist/cjs/track/index.js.map +1 -1
- package/dist/cjs/trackPageView/index.js.map +1 -1
- package/dist/esm/fields.js.map +1 -1
- package/dist/esm/functions.js.map +1 -1
- package/dist/esm/init-script.js +59 -15
- package/dist/esm/init-script.js.map +1 -1
- package/dist/esm/setting-fields.js +1 -1
- package/dist/esm/setting-fields.js.map +1 -1
- package/dist/esm/track/index.js.map +1 -1
- package/dist/esm/trackPageView/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/alias/__tests__/index.test.ts +2 -3
- package/src/constants.ts +1 -1
- package/src/fields.ts +137 -134
- package/src/functions.ts +9 -14
- package/src/group/__tests__/index.test.ts +6 -7
- package/src/group/index.ts +2 -2
- package/src/identify/__tests__/index.test.ts +12 -13
- package/src/identify/index.ts +3 -3
- package/src/init-script.ts +60 -2
- package/src/setting-fields.ts +260 -260
- package/src/track/__tests__/index.test.ts +23 -24
- package/src/track/index.ts +8 -6
- package/src/trackPageView/__tests__/index.test.ts +36 -35
- package/src/trackPageView/index.ts +10 -8
package/src/track/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Settings } from '../generated-types'
|
|
|
3
3
|
import type { Payload } from './generated-types'
|
|
4
4
|
import type { Mixpanel } from '../types'
|
|
5
5
|
import { sendIdentify, sendGroup } from '../functions'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
7
|
event_name,
|
|
8
8
|
properties,
|
|
9
9
|
unique_id,
|
|
@@ -21,17 +21,18 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
21
21
|
description: 'Sync Segment track events to Mixpanel.',
|
|
22
22
|
platform: 'web',
|
|
23
23
|
fields: {
|
|
24
|
-
event_name,
|
|
24
|
+
event_name,
|
|
25
25
|
properties,
|
|
26
26
|
unique_id: {
|
|
27
27
|
...unique_id,
|
|
28
|
-
description:
|
|
28
|
+
description:
|
|
29
|
+
'The unique ID to associate with the user. Settings this value will trigger a Mixpanel identify call before immediately the track event is sent.',
|
|
29
30
|
default: undefined,
|
|
30
31
|
required: false
|
|
31
32
|
},
|
|
32
33
|
user_profile_properties_to_set: {
|
|
33
34
|
...user_profile_properties_to_set,
|
|
34
|
-
default: {
|
|
35
|
+
default: {
|
|
35
36
|
name: {
|
|
36
37
|
'@if': {
|
|
37
38
|
exists: { '@path': '$.context.traits.name' },
|
|
@@ -59,7 +60,7 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
59
60
|
then: { '@path': '$.context.traits.email' },
|
|
60
61
|
else: { '@path': '$.properties.email' }
|
|
61
62
|
}
|
|
62
|
-
},
|
|
63
|
+
},
|
|
63
64
|
phone: {
|
|
64
65
|
'@if': {
|
|
65
66
|
exists: { '@path': '$.context.traits.phone' },
|
|
@@ -88,7 +89,8 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
88
89
|
group_details: {
|
|
89
90
|
...group_details,
|
|
90
91
|
required: false,
|
|
91
|
-
description:
|
|
92
|
+
description:
|
|
93
|
+
'Details for the group to be created or updated in Mixpanel. Setting this value will trigger a Mixpanel set_group call before the track event is sent.',
|
|
92
94
|
default: undefined
|
|
93
95
|
},
|
|
94
96
|
group_profile_properties_to_set,
|
|
@@ -36,7 +36,6 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
36
36
|
beforeEach(async () => {
|
|
37
37
|
jest.restoreAllMocks()
|
|
38
38
|
jest.spyOn(destination, 'initialize').mockImplementation(() => {
|
|
39
|
-
|
|
40
39
|
mockGroup = {
|
|
41
40
|
set: jest.fn(),
|
|
42
41
|
set_once: jest.fn(),
|
|
@@ -71,32 +70,32 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
71
70
|
mapping: {
|
|
72
71
|
event_name: undefined,
|
|
73
72
|
properties: { '@path': '$.properties' },
|
|
74
|
-
unique_id:{ '@path': '$.userId' },
|
|
75
|
-
user_profile_properties_to_set: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
unique_id: { '@path': '$.userId' },
|
|
74
|
+
user_profile_properties_to_set: {
|
|
75
|
+
name: { '@path': '$.context.traits.user.name' },
|
|
76
|
+
first_name: { '@path': '$.context.traits.user.first_name' },
|
|
77
|
+
last_name: { '@path': '$.context.traits.user.last_name' },
|
|
78
|
+
email: { '@path': '$.context.traits.user.email' },
|
|
79
|
+
phone: { '@path': '$.context.traits.user.phone' },
|
|
80
|
+
avatar: { '@path': '$.context.traits.user.avatar' },
|
|
81
|
+
created: { '@path': '$.context.traits.user.created' }
|
|
83
82
|
},
|
|
84
83
|
user_profile_properties_to_set_once: {
|
|
85
|
-
|
|
84
|
+
set_once_trait: { '@path': '$.context.traits.user.set_once_trait_1' }
|
|
86
85
|
},
|
|
87
86
|
user_profile_properties_to_increment: {
|
|
88
|
-
|
|
87
|
+
increment_property: { '@path': '$.context.traits.user.increment_property_1' }
|
|
89
88
|
},
|
|
90
89
|
group_details: {
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
group_key: { '@path': '$.context.traits.company.group_key' },
|
|
91
|
+
group_id: { '@path': '$.context.groupId' }
|
|
93
92
|
},
|
|
94
|
-
group_profile_properties_to_set: {
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
group_profile_properties_to_set: {
|
|
94
|
+
company_name: { '@path': '$.context.traits.company.company_name' },
|
|
95
|
+
number_employees: { '@path': '$.context.traits.company.number_employees' }
|
|
97
96
|
},
|
|
98
97
|
group_profile_properties_to_set_once: {
|
|
99
|
-
|
|
98
|
+
set_once_trait: { '@path': '$.context.traits.company.set_once_trait_1' }
|
|
100
99
|
},
|
|
101
100
|
group_profile_properties_to_union: { '@path': '$.context.traits.company.union_properties' }
|
|
102
101
|
}
|
|
@@ -113,7 +112,7 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
113
112
|
prop2: 2,
|
|
114
113
|
prop3: true,
|
|
115
114
|
prop4: [1, 2, 3],
|
|
116
|
-
prop5: { subprop1: 'subvalue1', subprop2: 22}
|
|
115
|
+
prop5: { subprop1: 'subvalue1', subprop2: 22 }
|
|
117
116
|
},
|
|
118
117
|
context: {
|
|
119
118
|
groupId: 'groupId1',
|
|
@@ -152,8 +151,8 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
152
151
|
await event.load(Context.system(), {} as Analytics)
|
|
153
152
|
await event.group?.(context)
|
|
154
153
|
|
|
155
|
-
// Identify related calls
|
|
156
|
-
expect(mockMPP.identify).toHaveBeenCalledWith(
|
|
154
|
+
// Identify related calls
|
|
155
|
+
expect(mockMPP.identify).toHaveBeenCalledWith('userId1')
|
|
157
156
|
expect(mockMPP.people.set).toHaveBeenCalledWith({
|
|
158
157
|
$name: 'User Name',
|
|
159
158
|
$last_name: 'Last',
|
|
@@ -170,7 +169,7 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
170
169
|
increment_property: 5
|
|
171
170
|
})
|
|
172
171
|
|
|
173
|
-
// Group related calls
|
|
172
|
+
// Group related calls
|
|
174
173
|
expect(mockMPP.set_group).toHaveBeenCalledWith('company', 'groupId1')
|
|
175
174
|
expect(mockMPP.get_group).toHaveBeenCalledWith('company', 'groupId1')
|
|
176
175
|
expect(mockGroup.set).toHaveBeenCalledWith({
|
|
@@ -190,7 +189,7 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
190
189
|
prop2: 2,
|
|
191
190
|
prop3: true,
|
|
192
191
|
prop4: [1, 2, 3],
|
|
193
|
-
prop5: { subprop1: 'subvalue1', subprop2: 22}
|
|
192
|
+
prop5: { subprop1: 'subvalue1', subprop2: 22 }
|
|
194
193
|
})
|
|
195
194
|
})
|
|
196
195
|
|
|
@@ -214,13 +213,13 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
214
213
|
anonymousId: 'anonymousId',
|
|
215
214
|
userId: 'userId1',
|
|
216
215
|
properties: {
|
|
217
|
-
event_name:
|
|
216
|
+
event_name: 'Dis be an event name',
|
|
218
217
|
other_props: {
|
|
219
218
|
prop1: 'value1',
|
|
220
219
|
prop2: 2,
|
|
221
220
|
prop3: true,
|
|
222
221
|
prop4: [1, 2, 3],
|
|
223
|
-
prop5: { subprop1: 'subvalue1', subprop2: 22}
|
|
222
|
+
prop5: { subprop1: 'subvalue1', subprop2: 22 }
|
|
224
223
|
}
|
|
225
224
|
}
|
|
226
225
|
})
|
|
@@ -235,15 +234,17 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
235
234
|
await event.group?.(context)
|
|
236
235
|
|
|
237
236
|
// Track Page View related calls
|
|
238
|
-
expect(mockMPP.track_pageview).toHaveBeenCalledWith(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
237
|
+
expect(mockMPP.track_pageview).toHaveBeenCalledWith(
|
|
238
|
+
{
|
|
239
|
+
prop1: 'value1',
|
|
240
|
+
prop2: 2,
|
|
241
|
+
prop3: true,
|
|
242
|
+
prop4: [1, 2, 3],
|
|
243
|
+
prop5: { subprop1: 'subvalue1', subprop2: 22 }
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
event_name: 'Dis be an event name'
|
|
247
|
+
}
|
|
248
|
+
)
|
|
248
249
|
})
|
|
249
250
|
})
|
|
@@ -3,7 +3,7 @@ import type { Settings } from '../generated-types'
|
|
|
3
3
|
import type { Payload } from './generated-types'
|
|
4
4
|
import type { Mixpanel } from '../types'
|
|
5
5
|
import { sendIdentify, sendGroup } from '../functions'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
7
|
event_name,
|
|
8
8
|
properties,
|
|
9
9
|
unique_id,
|
|
@@ -30,12 +30,13 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
30
30
|
properties,
|
|
31
31
|
unique_id: {
|
|
32
32
|
...unique_id,
|
|
33
|
-
description:
|
|
33
|
+
description:
|
|
34
|
+
'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
35
|
default: undefined
|
|
35
36
|
},
|
|
36
37
|
user_profile_properties_to_set: {
|
|
37
38
|
...user_profile_properties_to_set,
|
|
38
|
-
default: {
|
|
39
|
+
default: {
|
|
39
40
|
name: {
|
|
40
41
|
'@if': {
|
|
41
42
|
exists: { '@path': '$.context.traits.name' },
|
|
@@ -63,7 +64,7 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
63
64
|
then: { '@path': '$.context.traits.email' },
|
|
64
65
|
else: { '@path': '$.properties.email' }
|
|
65
66
|
}
|
|
66
|
-
},
|
|
67
|
+
},
|
|
67
68
|
phone: {
|
|
68
69
|
'@if': {
|
|
69
70
|
exists: { '@path': '$.context.traits.phone' },
|
|
@@ -92,7 +93,8 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
92
93
|
group_details: {
|
|
93
94
|
...group_details,
|
|
94
95
|
required: false,
|
|
95
|
-
description:
|
|
96
|
+
description:
|
|
97
|
+
'Details for the group to be created or updated in Mixpanel. Setting this value will trigger a Mixpanel set_group call before the page event is sent.',
|
|
96
98
|
default: undefined
|
|
97
99
|
},
|
|
98
100
|
group_profile_properties_to_set,
|
|
@@ -103,10 +105,10 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
103
105
|
sendIdentify(mixpanel, payload)
|
|
104
106
|
sendGroup(mixpanel, payload)
|
|
105
107
|
const { event_name, properties = {} } = payload
|
|
106
|
-
if(event_name){
|
|
107
|
-
|
|
108
|
+
if (event_name) {
|
|
109
|
+
mixpanel.track_pageview(properties || {}, { event_name })
|
|
108
110
|
} else {
|
|
109
|
-
|
|
111
|
+
mixpanel.track_pageview(properties || {})
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
}
|