@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/src/fields.ts CHANGED
@@ -1,170 +1,173 @@
1
1
  import { InputField } from '@segment/actions-core'
2
2
 
3
3
  export const event_name: InputField = {
4
- label: 'Event Name',
5
- description: 'The name of the event to track in Mixpanel.',
6
- required: true,
7
- type: 'string',
8
- default: { '@path': '$.event' }
4
+ label: 'Event Name',
5
+ description: 'The name of the event to track in Mixpanel.',
6
+ required: true,
7
+ type: 'string',
8
+ default: { '@path': '$.event' }
9
9
  }
10
10
 
11
- export const properties: InputField ={
12
- label: 'Event Properties',
13
- description: 'Properties to associate with the event.',
14
- required: false,
15
- type: 'object',
16
- default: { '@path': '$.properties'}
11
+ export const properties: InputField = {
12
+ label: 'Event Properties',
13
+ description: 'Properties to associate with the event.',
14
+ required: false,
15
+ type: 'object',
16
+ default: { '@path': '$.properties' }
17
17
  }
18
18
 
19
19
  export const unique_id: InputField = {
20
- label: 'Unique ID',
21
- description: 'The unique ID to associate with the user.',
22
- required: true,
23
- type: 'string',
24
- default: { '@path': '$.userId' }
20
+ label: 'Unique ID',
21
+ description: 'The unique ID to associate with the user.',
22
+ required: true,
23
+ type: 'string',
24
+ default: { '@path': '$.userId' }
25
25
  }
26
26
 
27
27
  export const user_profile_properties_to_set: InputField = {
28
- label: 'User Profile Properties to Set',
29
- description: 'User Profile Properties to set on the user profile in Mixpanel.',
30
- required: false,
31
- defaultObjectUI: 'keyvalue',
32
- additionalProperties: true,
33
- type: 'object',
34
- properties: {
35
- name: {
36
- label: 'Name',
37
- description: 'The name of the user.',
38
- type: 'string'
39
- },
40
- first_name: {
41
- label: 'First Name',
42
- description: 'The first name of the user.',
43
- type: 'string'
44
- },
45
- last_name: {
46
- label: 'Last Name',
47
- description: 'The last name of the user.',
48
- type: 'string'
49
- },
50
- email: {
51
- label: 'Email',
52
- description: 'The email of the user.',
53
- type: 'string',
54
- format: 'email'
55
- },
56
- phone: {
57
- label: 'Phone',
58
- description: 'The phone number of the user.',
59
- type: 'string'
60
- },
61
- avatar: {
62
- label: 'Avatar',
63
- description: 'The avatar URL of the user.',
64
- type: 'string',
65
- format: 'uri'
66
- },
67
- created: {
68
- label: 'Created',
69
- description: 'The creation date of the user profile.',
70
- type: 'string',
71
- format: 'date-time'
72
- }
28
+ label: 'User Profile Properties to Set',
29
+ description: 'User Profile Properties to set on the user profile in Mixpanel.',
30
+ required: false,
31
+ defaultObjectUI: 'keyvalue',
32
+ additionalProperties: true,
33
+ type: 'object',
34
+ properties: {
35
+ name: {
36
+ label: 'Name',
37
+ description: 'The name of the user.',
38
+ type: 'string'
73
39
  },
74
- default: {
75
- name: { '@path': '$.traits.name' },
76
- first_name: { '@path': '$.traits.first_name' },
77
- last_name: { '@path': '$.traits.last_name' },
78
- email: { '@path': '$.traits.email' },
79
- phone: { '@path': '$.traits.phone' },
80
- avatar: { '@path': '$.traits.avatar' },
81
- created: { '@path': '$.traits.created' }
40
+ first_name: {
41
+ label: 'First Name',
42
+ description: 'The first name of the user.',
43
+ type: 'string'
44
+ },
45
+ last_name: {
46
+ label: 'Last Name',
47
+ description: 'The last name of the user.',
48
+ type: 'string'
49
+ },
50
+ email: {
51
+ label: 'Email',
52
+ description: 'The email of the user.',
53
+ type: 'string',
54
+ format: 'email'
55
+ },
56
+ phone: {
57
+ label: 'Phone',
58
+ description: 'The phone number of the user.',
59
+ type: 'string'
60
+ },
61
+ avatar: {
62
+ label: 'Avatar',
63
+ description: 'The avatar URL of the user.',
64
+ type: 'string',
65
+ format: 'uri'
66
+ },
67
+ created: {
68
+ label: 'Created',
69
+ description: 'The creation date of the user profile.',
70
+ type: 'string',
71
+ format: 'date-time'
82
72
  }
73
+ },
74
+ default: {
75
+ name: { '@path': '$.traits.name' },
76
+ first_name: { '@path': '$.traits.first_name' },
77
+ last_name: { '@path': '$.traits.last_name' },
78
+ email: { '@path': '$.traits.email' },
79
+ phone: { '@path': '$.traits.phone' },
80
+ avatar: { '@path': '$.traits.avatar' },
81
+ created: { '@path': '$.traits.created' }
82
+ }
83
83
  }
84
84
 
85
85
  export const user_profile_properties_to_set_once: InputField = {
86
- label: 'User Profile Properties to Set Once',
87
- description: 'User Profile Properties to set once on the user profile in Mixpanel. Values which get set once cannot be overwritten later.',
88
- required: false,
89
- defaultObjectUI: 'keyvalue',
90
- type: 'object'
86
+ label: 'User Profile Properties to Set Once',
87
+ description:
88
+ 'User Profile Properties to set once on the user profile in Mixpanel. Values which get set once cannot be overwritten later.',
89
+ required: false,
90
+ defaultObjectUI: 'keyvalue',
91
+ type: 'object'
91
92
  }
92
93
 
93
- export const user_profile_properties_to_increment: InputField = {
94
- label: 'User Profile Properties to Increment',
95
- description: 'User Profile Properties to increment on the user profile in Mixpanel. Values must be numeric.',
96
- required: false,
97
- defaultObjectUI: 'keyvalue',
98
- type: 'object'
94
+ export const user_profile_properties_to_increment: InputField = {
95
+ label: 'User Profile Properties to Increment',
96
+ description: 'User Profile Properties to increment on the user profile in Mixpanel. Values must be numeric.',
97
+ required: false,
98
+ defaultObjectUI: 'keyvalue',
99
+ type: 'object'
99
100
  }
100
101
 
101
102
  export const group_details: InputField = {
102
- label: 'Group Details',
103
- description: 'Details for the group to be created or updated in Mixpanel.',
104
- type: 'object',
105
- defaultObjectUI: 'keyvalue:only',
106
- additionalProperties: false,
107
- required: true,
108
- properties: {
103
+ label: 'Group Details',
104
+ description: 'Details for the group to be created or updated in Mixpanel.',
105
+ type: 'object',
106
+ defaultObjectUI: 'keyvalue:only',
107
+ additionalProperties: false,
108
+ required: true,
109
+ properties: {
109
110
  group_key: {
110
- label: 'Group Key',
111
- description: 'The Group Key / type of group to associate with the user. This group key should already be defined in your Mixpanel project.',
112
- required: true,
113
- type: 'string'
111
+ label: 'Group Key',
112
+ description:
113
+ 'The Group Key / type of group to associate with the user. This group key should already be defined in your Mixpanel project.',
114
+ required: true,
115
+ type: 'string'
114
116
  },
115
117
  group_id: {
116
- label: 'Group ID',
117
- description: 'The unique ID to associate with the group.',
118
- required: true,
119
- type: 'string'
120
- }
121
- },
122
- default: {
123
- group_key: { '@path': '$.traits.group_key' },
124
- group_id: { '@path': '$.groupId' }
118
+ label: 'Group ID',
119
+ description: 'The unique ID to associate with the group.',
120
+ required: true,
121
+ type: 'string'
125
122
  }
123
+ },
124
+ default: {
125
+ group_key: { '@path': '$.traits.group_key' },
126
+ group_id: { '@path': '$.groupId' }
127
+ }
126
128
  }
127
129
 
128
130
  export const group_profile_properties_to_set: InputField = {
129
- label: 'Group properties to Set',
130
- description: 'Group Profile Properties to set on the group in Mixpanel.',
131
- required: false,
132
- defaultObjectUI: 'keyvalue',
133
- type: 'object'
131
+ label: 'Group properties to Set',
132
+ description: 'Group Profile Properties to set on the group in Mixpanel.',
133
+ required: false,
134
+ defaultObjectUI: 'keyvalue',
135
+ type: 'object'
134
136
  }
135
137
 
136
138
  export const group_profile_properties_to_set_once: InputField = {
137
- label: 'Group properties to set once',
138
- description: 'Group Profile Properties to set once on the group profile in Mixpanel. Values which get set once cannot be overwritten later.',
139
- required: false,
140
- defaultObjectUI: 'keyvalue',
141
- type: 'object'
139
+ label: 'Group properties to set once',
140
+ description:
141
+ 'Group Profile Properties to set once on the group profile in Mixpanel. Values which get set once cannot be overwritten later.',
142
+ required: false,
143
+ defaultObjectUI: 'keyvalue',
144
+ type: 'object'
142
145
  }
143
146
 
144
147
  export const group_profile_properties_to_union: InputField = {
145
- label: 'Group list properties to union',
146
- description: 'Merge a list into a list group property. Duplicates will be removed.',
147
- required: false,
148
- type: 'object',
149
- multiple: true,
150
- defaultObjectUI: 'arrayeditor',
151
- additionalProperties: false,
152
- properties: {
153
- list_name: {
154
- label: 'List Name',
155
- description: 'The name of the list property to union values into.',
156
- type: 'string',
157
- allowNull: false,
158
- required: true
159
- },
160
- string_values: {
161
- label: 'Values',
162
- description: 'An array of string values to merge into the list. Non string lists cannot be updated. Duplicates will be removed.',
163
- type: 'string',
164
- required: true,
165
- allowNull: false,
166
- multiple: true
167
- }
148
+ label: 'Group list properties to union',
149
+ description: 'Merge a list into a list group property. Duplicates will be removed.',
150
+ required: false,
151
+ type: 'object',
152
+ multiple: true,
153
+ defaultObjectUI: 'arrayeditor',
154
+ additionalProperties: false,
155
+ properties: {
156
+ list_name: {
157
+ label: 'List Name',
158
+ description: 'The name of the list property to union values into.',
159
+ type: 'string',
160
+ allowNull: false,
161
+ required: true
162
+ },
163
+ string_values: {
164
+ label: 'Values',
165
+ description:
166
+ 'An array of string values to merge into the list. Non string lists cannot be updated. Duplicates will be removed.',
167
+ type: 'string',
168
+ required: true,
169
+ allowNull: false,
170
+ multiple: true
168
171
  }
172
+ }
169
173
  }
170
-
package/src/functions.ts CHANGED
@@ -6,14 +6,14 @@ import type { Mixpanel } from './types'
6
6
  import { STANDARD_USER_PROFILE_PROPERTIES } from './constants'
7
7
 
8
8
  export function sendIdentify(mixpanel: Mixpanel, payload: IdentifyPayload | TrackPayload | TrackPageViewPayload) {
9
- const {
10
- unique_id,
9
+ const {
10
+ unique_id,
11
11
  user_profile_properties_to_set,
12
12
  user_profile_properties_to_set_once,
13
13
  user_profile_properties_to_increment
14
14
  } = payload
15
15
 
16
- if(unique_id) {
16
+ if (unique_id) {
17
17
  mixpanel.identify(unique_id)
18
18
  }
19
19
 
@@ -31,22 +31,20 @@ export function sendIdentify(mixpanel: Mixpanel, payload: IdentifyPayload | Trac
31
31
  }
32
32
 
33
33
  function ensureDollarPrefix(property: string): string {
34
- if(STANDARD_USER_PROFILE_PROPERTIES.includes(property) && !property.startsWith('$')) {
34
+ if (STANDARD_USER_PROFILE_PROPERTIES.includes(property) && !property.startsWith('$')) {
35
35
  return `$${property}`
36
36
  }
37
37
  return property
38
38
  }
39
39
 
40
40
  function mapKeys<T extends Record<string, unknown>>(obj: T, fn: (key: string) => string): Record<string, T[keyof T]> {
41
- return Object.fromEntries(
42
- Object.entries(obj).map(([k, v]) => [fn(k), v])
43
- ) as Record<string, T[keyof T]>;
41
+ return Object.fromEntries(Object.entries(obj).map(([k, v]) => [fn(k), v])) as Record<string, T[keyof T]>
44
42
  }
45
43
 
46
44
  export function sendGroup(mixpanel: Mixpanel, payload: GroupPayload | TrackPayload | TrackPageViewPayload) {
47
- const {
45
+ const {
48
46
  group_details: { group_key, group_id } = {},
49
- group_profile_properties_to_set,
47
+ group_profile_properties_to_set,
50
48
  group_profile_properties_to_set_once,
51
49
  group_profile_properties_to_union
52
50
  } = payload
@@ -63,12 +61,9 @@ export function sendGroup(mixpanel: Mixpanel, payload: GroupPayload | TrackPaylo
63
61
  }
64
62
  if (group_profile_properties_to_union && group_profile_properties_to_union.length > 0) {
65
63
  group_profile_properties_to_union.forEach((item) => {
66
- const {
67
- list_name,
68
- string_values
69
- } = item
64
+ const { list_name, string_values } = item
70
65
  group.union(list_name, string_values)
71
66
  })
72
67
  }
73
68
  }
74
- }
69
+ }
@@ -36,7 +36,6 @@ describe('Mixpanel.group', () => {
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(),
@@ -70,15 +69,15 @@ describe('Mixpanel.group', () => {
70
69
  subscribe: 'type = "group"',
71
70
  mapping: {
72
71
  group_details: {
73
- group_key: { '@path': '$.traits.group_key' },
74
- group_id: { '@path': '$.groupId' }
72
+ group_key: { '@path': '$.traits.group_key' },
73
+ group_id: { '@path': '$.groupId' }
75
74
  },
76
- group_profile_properties_to_set: {
77
- company_name: { '@path': '$.traits.company_name' },
78
- number_employees: { '@path': '$.traits.number_employees' }
75
+ group_profile_properties_to_set: {
76
+ company_name: { '@path': '$.traits.company_name' },
77
+ number_employees: { '@path': '$.traits.number_employees' }
79
78
  },
80
79
  group_profile_properties_to_set_once: {
81
- set_once_trait: { '@path': '$.traits.set_once_trait_1' },
80
+ set_once_trait: { '@path': '$.traits.set_once_trait_1' }
82
81
  },
83
82
  group_profile_properties_to_union: { '@path': '$.traits.union_properties' }
84
83
  }
@@ -3,8 +3,8 @@ import type { Settings } from '../generated-types'
3
3
  import type { Payload } from './generated-types'
4
4
  import type { Mixpanel } from '../types'
5
5
  import { sendGroup } from '../functions'
6
- import {
7
- group_details,
6
+ import {
7
+ group_details,
8
8
  group_profile_properties_to_set,
9
9
  group_profile_properties_to_set_once,
10
10
  group_profile_properties_to_union
@@ -36,7 +36,6 @@ describe('Mixpanel.identify', () => {
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(),
@@ -69,21 +68,21 @@ describe('Mixpanel.identify', () => {
69
68
  enabled: true,
70
69
  subscribe: 'type = "identify"',
71
70
  mapping: {
72
- unique_id:{ '@path': '$.userId' },
73
- user_profile_properties_to_set: {
74
- name: { '@path': '$.traits.name' },
75
- first_name: { '@path': '$.traits.first_name' },
76
- last_name: { '@path': '$.traits.last_name' },
77
- email: { '@path': '$.traits.email' },
78
- phone: { '@path': '$.traits.phone' },
79
- avatar: { '@path': '$.traits.avatar' },
80
- created: { '@path': '$.traits.created' }
71
+ unique_id: { '@path': '$.userId' },
72
+ user_profile_properties_to_set: {
73
+ name: { '@path': '$.traits.name' },
74
+ first_name: { '@path': '$.traits.first_name' },
75
+ last_name: { '@path': '$.traits.last_name' },
76
+ email: { '@path': '$.traits.email' },
77
+ phone: { '@path': '$.traits.phone' },
78
+ avatar: { '@path': '$.traits.avatar' },
79
+ created: { '@path': '$.traits.created' }
81
80
  },
82
81
  user_profile_properties_to_set_once: {
83
- set_once_trait: { '@path': '$.traits.set_once_trait_1' },
82
+ set_once_trait: { '@path': '$.traits.set_once_trait_1' }
84
83
  },
85
84
  user_profile_properties_to_increment: {
86
- increment_property: { '@path': '$.traits.increment_property_1' }
85
+ increment_property: { '@path': '$.traits.increment_property_1' }
87
86
  }
88
87
  }
89
88
  }
@@ -116,7 +115,7 @@ describe('Mixpanel.identify', () => {
116
115
  await event.load(Context.system(), {} as Analytics)
117
116
  await event.identify?.(context)
118
117
 
119
- expect(mockMPP.identify).toHaveBeenCalledWith("userId1")
118
+ expect(mockMPP.identify).toHaveBeenCalledWith('userId1')
120
119
  expect(mockMPP.people.set).toHaveBeenCalledWith({
121
120
  $name: 'name1',
122
121
  $last_name: 'lastName1',
@@ -3,8 +3,8 @@ 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 } from '../functions'
6
- import {
7
- unique_id,
6
+ import {
7
+ unique_id,
8
8
  user_profile_properties_to_set,
9
9
  user_profile_properties_to_set_once,
10
10
  user_profile_properties_to_increment
@@ -16,7 +16,7 @@ const action: BrowserActionDefinition<Settings, Mixpanel, Payload> = {
16
16
  defaultSubscription: 'type = "identify"',
17
17
  platform: 'web',
18
18
  fields: {
19
- unique_id,
19
+ unique_id,
20
20
  user_profile_properties_to_set,
21
21
  user_profile_properties_to_set_once,
22
22
  user_profile_properties_to_increment
@@ -1,5 +1,63 @@
1
1
  /* eslint-disable */
2
2
  // @ts-nocheck
3
3
  export async function initScript() {
4
- (function (f, b) { if (!b.__SV) { var e, g, i, h; window.mixpanel = b; b._i = []; b.init = function (e, f, c) { function g(a, d) { var b = d.split("."); 2 == b.length && ((a = a[b[0]]), (d = b[1])); a[d] = function () { a.push([d].concat(Array.prototype.slice.call(arguments, 0))); }; } var a = b; "undefined" !== typeof c ? (a = b[c] = []) : (c = "mixpanel"); a.people = a.people || []; a.toString = function (a) { var d = "mixpanel"; "mixpanel" !== c && (d += "." + c); a || (d += " (stub)"); return d; }; a.people.toString = function () { return a.toString(1) + ".people (stub)"; }; i = "disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split( " "); for (h = 0; h < i.length; h++) g(a, i[h]); var j = "set set_once union unset remove delete".split(" "); a.get_group = function () { function b(c) { d[c] = function () { call2_args = arguments; call2 = [c].concat(Array.prototype.slice.call(call2_args, 0)); a.push([e, call2]); }; } for ( var d = {}, e = ["get_group"].concat( Array.prototype.slice.call(arguments, 0)), c = 0; c < j.length; c++) b(j[c]); return d; }; b._i.push([e, f, c]); }; b.__SV = 1.2; e = f.createElement("script"); e.type = "text/javascript"; e.async = !0; e.src = "undefined" !== typeof MIXPANEL_CUSTOM_LIB_URL ? MIXPANEL_CUSTOM_LIB_URL : "file:" === f.location.protocol && "//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//) ? "https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js" : "//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js"; g = f.getElementsByTagName("script")[0]; g.parentNode.insertBefore(e, g); } })(document, window.mixpanel || []);
5
- }
4
+ ;(function (f, b) {
5
+ if (!b.__SV) {
6
+ var e, g, i, h
7
+ window.mixpanel = b
8
+ b._i = []
9
+ b.init = function (e, f, c) {
10
+ function g(a, d) {
11
+ var b = d.split('.')
12
+ 2 == b.length && ((a = a[b[0]]), (d = b[1]))
13
+ a[d] = function () {
14
+ a.push([d].concat(Array.prototype.slice.call(arguments, 0)))
15
+ }
16
+ }
17
+ var a = b
18
+ 'undefined' !== typeof c ? (a = b[c] = []) : (c = 'mixpanel')
19
+ a.people = a.people || []
20
+ a.toString = function (a) {
21
+ var d = 'mixpanel'
22
+ 'mixpanel' !== c && (d += '.' + c)
23
+ a || (d += ' (stub)')
24
+ return d
25
+ }
26
+ a.people.toString = function () {
27
+ return a.toString(1) + '.people (stub)'
28
+ }
29
+ i =
30
+ 'disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove'.split(
31
+ ' '
32
+ )
33
+ for (h = 0; h < i.length; h++) g(a, i[h])
34
+ var j = 'set set_once union unset remove delete'.split(' ')
35
+ a.get_group = function () {
36
+ function b(c) {
37
+ d[c] = function () {
38
+ call2_args = arguments
39
+ call2 = [c].concat(Array.prototype.slice.call(call2_args, 0))
40
+ a.push([e, call2])
41
+ }
42
+ }
43
+ for (var d = {}, e = ['get_group'].concat(Array.prototype.slice.call(arguments, 0)), c = 0; c < j.length; c++)
44
+ b(j[c])
45
+ return d
46
+ }
47
+ b._i.push([e, f, c])
48
+ }
49
+ b.__SV = 1.2
50
+ e = f.createElement('script')
51
+ e.type = 'text/javascript'
52
+ e.async = !0
53
+ e.src =
54
+ 'undefined' !== typeof MIXPANEL_CUSTOM_LIB_URL
55
+ ? MIXPANEL_CUSTOM_LIB_URL
56
+ : 'file:' === f.location.protocol && '//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js'.match(/^\/\//)
57
+ ? 'https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js'
58
+ : '//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js'
59
+ g = f.getElementsByTagName('script')[0]
60
+ g.parentNode.insertBefore(e, g)
61
+ }
62
+ })(document, window.mixpanel || [])
63
+ }