@segment/analytics-browser-mixpanel-web-actions 1.0.1-staging-b870c2b86.0 → 1.2.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/index.js.map +1 -1
- package/dist/cjs/init-script.js +15 -59
- 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/index.js.map +1 -1
- package/dist/esm/init-script.js +15 -59
- 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 +2 -2
- package/src/alias/__tests__/index.test.ts +3 -2
- package/src/constants.ts +1 -1
- package/src/fields.ts +134 -137
- package/src/functions.ts +10 -7
- package/src/group/__tests__/index.test.ts +7 -6
- package/src/group/index.ts +2 -2
- package/src/identify/__tests__/index.test.ts +13 -12
- package/src/identify/index.ts +3 -3
- package/src/index.ts +14 -14
- package/src/init-script.ts +2 -60
- package/src/setting-fields.ts +260 -260
- package/src/track/__tests__/index.test.ts +24 -23
- package/src/track/index.ts +6 -8
- package/src/trackPageView/__tests__/index.test.ts +35 -36
- package/src/trackPageView/index.ts +8 -10
- package/src/types.ts +18 -19
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,18 +21,17 @@ 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:
|
|
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.',
|
|
28
|
+
description: 'The unique ID to associate with the user. Settings this value will trigger a Mixpanel identify call before immediately the track event is sent.',
|
|
30
29
|
default: undefined,
|
|
31
30
|
required: false
|
|
32
31
|
},
|
|
33
32
|
user_profile_properties_to_set: {
|
|
34
33
|
...user_profile_properties_to_set,
|
|
35
|
-
default: {
|
|
34
|
+
default: {
|
|
36
35
|
name: {
|
|
37
36
|
'@if': {
|
|
38
37
|
exists: { '@path': '$.context.traits.name' },
|
|
@@ -60,7 +59,7 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
60
59
|
then: { '@path': '$.context.traits.email' },
|
|
61
60
|
else: { '@path': '$.properties.email' }
|
|
62
61
|
}
|
|
63
|
-
},
|
|
62
|
+
},
|
|
64
63
|
phone: {
|
|
65
64
|
'@if': {
|
|
66
65
|
exists: { '@path': '$.context.traits.phone' },
|
|
@@ -89,8 +88,7 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
89
88
|
group_details: {
|
|
90
89
|
...group_details,
|
|
91
90
|
required: false,
|
|
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.',
|
|
91
|
+
description: '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.',
|
|
94
92
|
default: undefined
|
|
95
93
|
},
|
|
96
94
|
group_profile_properties_to_set,
|
|
@@ -36,6 +36,7 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
36
36
|
beforeEach(async () => {
|
|
37
37
|
jest.restoreAllMocks()
|
|
38
38
|
jest.spyOn(destination, 'initialize').mockImplementation(() => {
|
|
39
|
+
|
|
39
40
|
mockGroup = {
|
|
40
41
|
set: jest.fn(),
|
|
41
42
|
set_once: jest.fn(),
|
|
@@ -70,32 +71,32 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
70
71
|
mapping: {
|
|
71
72
|
event_name: undefined,
|
|
72
73
|
properties: { '@path': '$.properties' },
|
|
73
|
-
unique_id:
|
|
74
|
-
user_profile_properties_to_set: {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
unique_id:{ '@path': '$.userId' },
|
|
75
|
+
user_profile_properties_to_set: {
|
|
76
|
+
name: { '@path': '$.context.traits.user.name' },
|
|
77
|
+
first_name: { '@path': '$.context.traits.user.first_name' },
|
|
78
|
+
last_name: { '@path': '$.context.traits.user.last_name' },
|
|
79
|
+
email: { '@path': '$.context.traits.user.email' },
|
|
80
|
+
phone: { '@path': '$.context.traits.user.phone' },
|
|
81
|
+
avatar: { '@path': '$.context.traits.user.avatar' },
|
|
82
|
+
created: { '@path': '$.context.traits.user.created' }
|
|
82
83
|
},
|
|
83
84
|
user_profile_properties_to_set_once: {
|
|
84
|
-
|
|
85
|
+
set_once_trait: { '@path': '$.context.traits.user.set_once_trait_1' },
|
|
85
86
|
},
|
|
86
87
|
user_profile_properties_to_increment: {
|
|
87
|
-
|
|
88
|
+
increment_property: { '@path': '$.context.traits.user.increment_property_1' }
|
|
88
89
|
},
|
|
89
90
|
group_details: {
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
group_key: { '@path': '$.context.traits.company.group_key' },
|
|
92
|
+
group_id: { '@path': '$.context.groupId' }
|
|
92
93
|
},
|
|
93
|
-
group_profile_properties_to_set: {
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
group_profile_properties_to_set: {
|
|
95
|
+
company_name: { '@path': '$.context.traits.company.company_name' },
|
|
96
|
+
number_employees: { '@path': '$.context.traits.company.number_employees' }
|
|
96
97
|
},
|
|
97
98
|
group_profile_properties_to_set_once: {
|
|
98
|
-
|
|
99
|
+
set_once_trait: { '@path': '$.context.traits.company.set_once_trait_1' },
|
|
99
100
|
},
|
|
100
101
|
group_profile_properties_to_union: { '@path': '$.context.traits.company.union_properties' }
|
|
101
102
|
}
|
|
@@ -112,7 +113,7 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
112
113
|
prop2: 2,
|
|
113
114
|
prop3: true,
|
|
114
115
|
prop4: [1, 2, 3],
|
|
115
|
-
prop5: { subprop1: 'subvalue1', subprop2: 22
|
|
116
|
+
prop5: { subprop1: 'subvalue1', subprop2: 22}
|
|
116
117
|
},
|
|
117
118
|
context: {
|
|
118
119
|
groupId: 'groupId1',
|
|
@@ -151,8 +152,8 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
151
152
|
await event.load(Context.system(), {} as Analytics)
|
|
152
153
|
await event.group?.(context)
|
|
153
154
|
|
|
154
|
-
// Identify related calls
|
|
155
|
-
expect(mockMPP.identify).toHaveBeenCalledWith(
|
|
155
|
+
// Identify related calls
|
|
156
|
+
expect(mockMPP.identify).toHaveBeenCalledWith("userId1")
|
|
156
157
|
expect(mockMPP.people.set).toHaveBeenCalledWith({
|
|
157
158
|
name: 'User Name',
|
|
158
159
|
last_name: 'Last',
|
|
@@ -169,7 +170,7 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
169
170
|
increment_property: 5
|
|
170
171
|
})
|
|
171
172
|
|
|
172
|
-
// Group related calls
|
|
173
|
+
// Group related calls
|
|
173
174
|
expect(mockMPP.set_group).toHaveBeenCalledWith('company', 'groupId1')
|
|
174
175
|
expect(mockMPP.get_group).toHaveBeenCalledWith('company', 'groupId1')
|
|
175
176
|
expect(mockGroup.set).toHaveBeenCalledWith({
|
|
@@ -189,7 +190,7 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
189
190
|
prop2: 2,
|
|
190
191
|
prop3: true,
|
|
191
192
|
prop4: [1, 2, 3],
|
|
192
|
-
prop5: { subprop1: 'subvalue1', subprop2: 22
|
|
193
|
+
prop5: { subprop1: 'subvalue1', subprop2: 22}
|
|
193
194
|
})
|
|
194
195
|
})
|
|
195
196
|
|
|
@@ -213,13 +214,13 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
213
214
|
anonymousId: 'anonymousId',
|
|
214
215
|
userId: 'userId1',
|
|
215
216
|
properties: {
|
|
216
|
-
event_name:
|
|
217
|
+
event_name: "Dis be an event name",
|
|
217
218
|
other_props: {
|
|
218
219
|
prop1: 'value1',
|
|
219
220
|
prop2: 2,
|
|
220
221
|
prop3: true,
|
|
221
222
|
prop4: [1, 2, 3],
|
|
222
|
-
prop5: { subprop1: 'subvalue1', subprop2: 22
|
|
223
|
+
prop5: { subprop1: 'subvalue1', subprop2: 22}
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
})
|
|
@@ -234,17 +235,15 @@ describe('Mixpanel.trackPageView', () => {
|
|
|
234
235
|
await event.group?.(context)
|
|
235
236
|
|
|
236
237
|
// Track Page View related calls
|
|
237
|
-
expect(mockMPP.track_pageview).toHaveBeenCalledWith(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
)
|
|
238
|
+
expect(mockMPP.track_pageview).toHaveBeenCalledWith({
|
|
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
|
+
})
|
|
249
248
|
})
|
|
250
249
|
})
|
|
@@ -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,13 +30,12 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
30
30
|
properties,
|
|
31
31
|
unique_id: {
|
|
32
32
|
...unique_id,
|
|
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.',
|
|
33
|
+
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.',
|
|
35
34
|
default: undefined
|
|
36
35
|
},
|
|
37
36
|
user_profile_properties_to_set: {
|
|
38
37
|
...user_profile_properties_to_set,
|
|
39
|
-
default: {
|
|
38
|
+
default: {
|
|
40
39
|
name: {
|
|
41
40
|
'@if': {
|
|
42
41
|
exists: { '@path': '$.context.traits.name' },
|
|
@@ -64,7 +63,7 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
64
63
|
then: { '@path': '$.context.traits.email' },
|
|
65
64
|
else: { '@path': '$.properties.email' }
|
|
66
65
|
}
|
|
67
|
-
},
|
|
66
|
+
},
|
|
68
67
|
phone: {
|
|
69
68
|
'@if': {
|
|
70
69
|
exists: { '@path': '$.context.traits.phone' },
|
|
@@ -93,8 +92,7 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
93
92
|
group_details: {
|
|
94
93
|
...group_details,
|
|
95
94
|
required: false,
|
|
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.',
|
|
95
|
+
description: '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.',
|
|
98
96
|
default: undefined
|
|
99
97
|
},
|
|
100
98
|
group_profile_properties_to_set,
|
|
@@ -105,10 +103,10 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
|
|
|
105
103
|
sendIdentify(mixpanel, payload)
|
|
106
104
|
sendGroup(mixpanel, payload)
|
|
107
105
|
const { event_name, properties = {} } = payload
|
|
108
|
-
if
|
|
109
|
-
|
|
106
|
+
if(event_name){
|
|
107
|
+
mixpanel.track_pageview(properties || {}, { event_name } )
|
|
110
108
|
} else {
|
|
111
|
-
|
|
109
|
+
mixpanel.track_pageview(properties || {})
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
112
|
}
|
package/src/types.ts
CHANGED
|
@@ -29,38 +29,36 @@ export interface Mixpanel {
|
|
|
29
29
|
|
|
30
30
|
get_group(group_key: string, group_id: string): Group
|
|
31
31
|
|
|
32
|
-
set_group(group_key: string, group_ids: string): void
|
|
32
|
+
set_group( group_key: string, group_ids: string): void
|
|
33
33
|
|
|
34
34
|
people: People
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export interface People {
|
|
38
|
-
set(prop: {
|
|
39
|
-
set_once(prop: {
|
|
40
|
-
increment(prop: {
|
|
38
|
+
set(prop: {[k: string]: unknown}): void
|
|
39
|
+
set_once(prop: {[k: string]: unknown}): void
|
|
40
|
+
increment(prop: {[k: string]: unknown}): void
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export interface Group {
|
|
44
|
-
set(prop: {
|
|
45
|
-
set_once(prop: {
|
|
44
|
+
set(prop: {[k: string]: unknown}): void
|
|
45
|
+
set_once(prop: {[k: string]: unknown}): void
|
|
46
46
|
union(list_name: string, values: (string | number | boolean)[]): void
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export interface Config {
|
|
50
|
-
autocapture?:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
| boolean
|
|
50
|
+
autocapture?: {
|
|
51
|
+
pageview?: PageViewUrlConfigOption
|
|
52
|
+
click?: boolean
|
|
53
|
+
dead_click?: boolean
|
|
54
|
+
input?: boolean
|
|
55
|
+
rage_click?: boolean
|
|
56
|
+
scroll?: boolean
|
|
57
|
+
submit?: boolean
|
|
58
|
+
capture_text_content?: boolean
|
|
59
|
+
} | boolean,
|
|
62
60
|
cross_subdomain_cookie?: boolean
|
|
63
|
-
persistence?: PersistenceOptions
|
|
61
|
+
persistence?: PersistenceOptions,
|
|
64
62
|
track_marketing?: boolean
|
|
65
63
|
cookie_expiration?: number
|
|
66
64
|
disable_persistence?: boolean
|
|
@@ -76,3 +74,4 @@ export interface Config {
|
|
|
76
74
|
record_min_ms?: number
|
|
77
75
|
record_sessions_percent?: number
|
|
78
76
|
}
|
|
77
|
+
|