@segment/analytics-browser-mixpanel-web-actions 1.3.1-staging-96646e7a8.0 → 1.3.1-staging-e5586ad4f.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.
@@ -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: '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:
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: '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
+ 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
- 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' }
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
- set_once_trait: { '@path': '$.context.traits.user.set_once_trait_1' },
84
+ set_once_trait: { '@path': '$.context.traits.user.set_once_trait_1' }
86
85
  },
87
86
  user_profile_properties_to_increment: {
88
- increment_property: { '@path': '$.context.traits.user.increment_property_1' }
87
+ increment_property: { '@path': '$.context.traits.user.increment_property_1' }
89
88
  },
90
89
  group_details: {
91
- group_key: { '@path': '$.context.traits.company.group_key' },
92
- group_id: { '@path': '$.context.groupId' }
90
+ group_key: { '@path': '$.context.traits.company.group_key' },
91
+ group_id: { '@path': '$.context.groupId' }
93
92
  },
94
- group_profile_properties_to_set: {
95
- company_name: { '@path': '$.context.traits.company.company_name' },
96
- number_employees: { '@path': '$.context.traits.company.number_employees' }
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
- set_once_trait: { '@path': '$.context.traits.company.set_once_trait_1' },
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("userId1")
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: "Dis be an 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
- 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
- })
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: '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:
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: '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
+ 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
- mixpanel.track_pageview(properties || {}, { event_name } )
108
+ if (event_name) {
109
+ mixpanel.track_pageview(properties || {}, { event_name })
108
110
  } else {
109
- mixpanel.track_pageview(properties || {})
111
+ mixpanel.track_pageview(properties || {})
110
112
  }
111
113
  }
112
114
  }
package/src/types.ts CHANGED
@@ -29,36 +29,38 @@ 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: {[k: string]: unknown}): void
39
- set_once(prop: {[k: string]: unknown}): void
40
- increment(prop: {[k: string]: unknown}): void
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: {[k: string]: unknown}): void
45
- set_once(prop: {[k: string]: unknown}): void
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
- 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,
50
+ autocapture?:
51
+ | {
52
+ pageview?: PageViewUrlConfigOption
53
+ click?: boolean
54
+ dead_click?: boolean
55
+ input?: boolean
56
+ rage_click?: boolean
57
+ scroll?: boolean
58
+ submit?: boolean
59
+ capture_text_content?: boolean
60
+ }
61
+ | boolean
60
62
  cross_subdomain_cookie?: boolean
61
- persistence?: PersistenceOptions,
63
+ persistence?: PersistenceOptions
62
64
  track_marketing?: boolean
63
65
  cookie_expiration?: number
64
66
  disable_persistence?: boolean
@@ -74,4 +76,3 @@ export interface Config {
74
76
  record_min_ms?: number
75
77
  record_sessions_percent?: number
76
78
  }
77
-