@segment/analytics-browser-actions-heap 1.40.1-staging.5 → 1.41.1-staging.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segment/analytics-browser-actions-heap",
3
- "version": "1.40.1-staging.5+6b1cc217c",
3
+ "version": "1.41.1-staging.5+87aac1d09",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -15,11 +15,11 @@
15
15
  },
16
16
  "typings": "./dist/esm",
17
17
  "dependencies": {
18
- "@segment/actions-core": "^3.109.1-staging.5+6b1cc217c",
19
- "@segment/browser-destination-runtime": "^1.39.1-staging.5+6b1cc217c"
18
+ "@segment/actions-core": "^3.110.1-staging.5+87aac1d09",
19
+ "@segment/browser-destination-runtime": "^1.40.1-staging.5+87aac1d09"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@segment/analytics-next": ">=1.55.0"
23
23
  },
24
- "gitHead": "6b1cc217c683766098c274c597650ca6ce4301d5"
24
+ "gitHead": "87aac1d096d4d53961f5f82de385da53c8a3918b"
25
25
  }
@@ -45,26 +45,22 @@ describe('#trackEvent', () => {
45
45
  products: [
46
46
  {
47
47
  name: 'Test Product 1',
48
- properties: {
49
- color: 'red',
50
- qty: 2,
51
- custom_vars: {
52
- position: 0,
53
- something_else: 'test',
54
- another_one: ['one', 'two', 'three']
55
- }
48
+ color: 'red',
49
+ qty: 2,
50
+ custom_vars: {
51
+ position: 0,
52
+ something_else: 'test',
53
+ another_one: ['one', 'two', 'three']
56
54
  }
57
55
  },
58
56
  {
59
57
  name: 'Test Product 2',
60
- properties: {
61
- color: 'blue',
62
- qty: 1,
63
- custom_vars: {
64
- position: 1,
65
- something_else: 'blah',
66
- another_one: ['four', 'five', 'six']
67
- }
58
+ color: 'blue',
59
+ qty: 1,
60
+ custom_vars: {
61
+ position: 1,
62
+ something_else: 'blah',
63
+ another_one: ['four', 'five', 'six']
68
64
  }
69
65
  }
70
66
  ]
@@ -92,7 +88,7 @@ describe('#trackEvent', () => {
92
88
  })
93
89
  expect(heapTrackSpy).toHaveBeenNthCalledWith(3, 'hello!', {
94
90
  products:
95
- '[{"name":"Test Product 1","properties":{"color":"red","qty":2,"custom_vars":{"position":0,"something_else":"test","another_one":["one","two","three"]}}},{"name":"Test Product 2","properties":{"color":"blue","qty":1,"custom_vars":{"position":1,"something_else":"blah","another_one":["four","five","six"]}}}]',
91
+ '[{"name":"Test Product 1","color":"red","qty":2,"custom_vars":{"position":0,"something_else":"test","another_one":["one","two","three"]}},{"name":"Test Product 2","color":"blue","qty":1,"custom_vars":{"position":1,"something_else":"blah","another_one":["four","five","six"]}}]',
96
92
  segment_library: HEAP_SEGMENT_BROWSER_LIBRARY_NAME
97
93
  })
98
94
  expect(addUserPropertiesSpy).toHaveBeenCalledTimes(0)
@@ -114,13 +110,13 @@ describe('#trackEvent', () => {
114
110
 
115
111
  for (let i = 1; i <= 3; i++) {
116
112
  expect(heapTrackSpy).toHaveBeenNthCalledWith(i, 'hello! testArray1 item', {
117
- val: i,
113
+ val: i.toString(),
118
114
  segment_library: HEAP_SEGMENT_BROWSER_LIBRARY_NAME
119
115
  })
120
116
  }
121
117
  for (let i = 4; i <= 5; i++) {
122
118
  expect(heapTrackSpy).toHaveBeenNthCalledWith(i, 'hello! testArray2 item', {
123
- val: i,
119
+ val: i.toString(),
124
120
  segment_library: HEAP_SEGMENT_BROWSER_LIBRARY_NAME
125
121
  })
126
122
  }
@@ -191,13 +187,37 @@ describe('#trackEvent', () => {
191
187
  )
192
188
  expect(heapTrackSpy).toHaveBeenCalledWith('hello!', {
193
189
  segment_library: HEAP_SEGMENT_BROWSER_LIBRARY_NAME,
194
- isAutomated: true,
195
- isClickable: true,
196
- bodyText: 'Testing text',
197
- ctaText: 'Click me',
198
- position: '0',
199
- 'testNestedValues.count': '5',
200
- 'testNestedValues.color': 'green'
190
+ isAutomated: 'true',
191
+ isClickable: 'true',
192
+ 'custom_vars.bodyText': 'Testing text',
193
+ 'custom_vars.ctaText': 'Click me',
194
+ 'custom_vars.position': '0',
195
+ 'custom_vars.testNestedValues.count': '5',
196
+ 'custom_vars.testNestedValues.color': 'green'
197
+ })
198
+ })
199
+
200
+ it('should flatten properties on parent when browserArrayLimit is set', async () => {
201
+ await eventWithUnrolling.track?.(
202
+ new Context({
203
+ type: 'track',
204
+ name: 'hello!',
205
+ properties: {
206
+ boolean_test: false,
207
+ string_test: 'react',
208
+ number_test: 0,
209
+ custom_vars: {
210
+ property: 1
211
+ }
212
+ }
213
+ })
214
+ )
215
+ expect(heapTrackSpy).toHaveBeenCalledWith('hello!', {
216
+ segment_library: HEAP_SEGMENT_BROWSER_LIBRARY_NAME,
217
+ boolean_test: 'false',
218
+ string_test: 'react',
219
+ number_test: '0',
220
+ 'custom_vars.property': '1'
201
221
  })
202
222
  })
203
223
 
@@ -316,27 +336,27 @@ describe('#trackEvent', () => {
316
336
  sku: 'PT2252152-0001-00',
317
337
  url: '/products/THE-ONE-JOGGER-PT2252152-0001-2',
318
338
  variant: 'Black',
319
- vip_price: 59.95,
320
- membership_brand_id: 1,
321
- quantity: 1,
339
+ vip_price: '59.95',
340
+ membership_brand_id: '1',
341
+ quantity: '1',
322
342
  segment_library: HEAP_SEGMENT_BROWSER_LIBRARY_NAME
323
343
  })
324
344
  expect(heapTrackSpy).toHaveBeenNthCalledWith(2, 'Product List Viewed products item', {
325
345
  sku: 'PT2252152-4846-00',
326
346
  url: '/products/THE-ONE-JOGGER-PT2252152-4846',
327
347
  variant: 'Deep Navy',
328
- vip_price: 59.95,
329
- membership_brand_id: 1,
330
- quantity: 1,
348
+ vip_price: '59.95',
349
+ membership_brand_id: '1',
350
+ quantity: '1',
331
351
  segment_library: HEAP_SEGMENT_BROWSER_LIBRARY_NAME
332
352
  })
333
353
  expect(heapTrackSpy).toHaveBeenNthCalledWith(3, 'Product List Viewed products item', {
334
354
  sku: 'PT2458220-0001-00',
335
355
  url: '/products/THE-YEAR-ROUND-TERRY-JOGGER-PT2458220-0001',
336
356
  variant: 'Black',
337
- vip_price: 59.95,
338
- membership_brand_id: 1,
339
- quantity: 1,
357
+ vip_price: '59.95',
358
+ membership_brand_id: '1',
359
+ quantity: '1',
340
360
  segment_library: HEAP_SEGMENT_BROWSER_LIBRARY_NAME
341
361
  })
342
362
  expect(heapTrackSpy).toHaveBeenNthCalledWith(4, 'Product List Viewed', {
@@ -101,13 +101,13 @@ const heapTrackArrays = (
101
101
  return eventProperties
102
102
  }
103
103
 
104
+ delete eventProperties[key]
105
+ eventProperties = { ...eventProperties, ...flat({ [key]: value }) }
106
+
104
107
  if (!Array.isArray(value)) {
105
108
  continue
106
109
  }
107
110
 
108
- delete eventProperties[key]
109
- eventProperties = { ...eventProperties, ...flat({ [key]: value }) }
110
-
111
111
  const arrayLength = value.length
112
112
  let arrayPropertyValues
113
113
  // truncate in case there are multiple array properties
package/src/utils.ts CHANGED
@@ -10,7 +10,7 @@ export type Properties = {
10
10
  }
11
11
 
12
12
  type FlattenProperties = object & {
13
- [k: string]: string
13
+ [k: string]: string | null
14
14
  }
15
15
 
16
16
  export function flat(data?: Properties, prefix = ''): FlattenProperties | undefined {
@@ -24,9 +24,7 @@ export function flat(data?: Properties, prefix = ''): FlattenProperties | undefi
24
24
  result = { ...result, ...flatten }
25
25
  } else {
26
26
  const stringifiedValue = stringify(data[key])
27
- // replaces the first . or .word.
28
- const identifier = (prefix + '.' + key).replace(/^\.(\w+\.)?/, '')
29
- result[identifier] = stringifiedValue
27
+ result[(prefix + '.' + key).replace(/^\./, '')] = stringifiedValue
30
28
  }
31
29
  }
32
30
  return result
@@ -39,14 +37,15 @@ export const flattenProperties = (arrayPropertyValue: any) => {
39
37
  if (typeof value == 'object' && value !== null) {
40
38
  arrayProperties = { ...arrayProperties, ...flat({ [key]: value as Properties }) }
41
39
  } else {
42
- arrayProperties = Object.assign(arrayProperties, { [key]: value })
40
+ const stringifiedValue = stringify(value)
41
+ arrayProperties = Object.assign(arrayProperties, { [key]: stringifiedValue })
43
42
  }
44
43
  }
45
44
  return arrayProperties
46
45
  }
47
46
 
48
- function stringify(value: unknown): string {
49
- if (typeof value === 'string') {
47
+ function stringify(value: unknown): string | null {
48
+ if (typeof value === 'string' || value === null) {
50
49
  return value
51
50
  }
52
51
  if (typeof value === 'number' || typeof value === 'boolean') {