@segment/analytics-browser-hubble-web 1.1.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/README.md +31 -0
- package/dist/cjs/generated-types.d.ts +3 -0
- package/dist/cjs/generated-types.js +3 -0
- package/dist/cjs/generated-types.js.map +1 -0
- package/dist/cjs/identify/generated-types.d.ts +7 -0
- package/dist/cjs/identify/generated-types.js +3 -0
- package/dist/cjs/identify/generated-types.js.map +1 -0
- package/dist/cjs/identify/index.d.ts +6 -0
- package/dist/cjs/identify/index.js +44 -0
- package/dist/cjs/identify/index.js.map +1 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.js +50 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/track/generated-types.d.ts +8 -0
- package/dist/cjs/track/generated-types.js +3 -0
- package/dist/cjs/track/generated-types.js.map +1 -0
- package/dist/cjs/track/index.d.ts +6 -0
- package/dist/cjs/track/index.js +58 -0
- package/dist/cjs/track/index.js.map +1 -0
- package/dist/cjs/types.d.ts +9 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/generated-types.d.ts +3 -0
- package/dist/esm/generated-types.js +2 -0
- package/dist/esm/generated-types.js.map +1 -0
- package/dist/esm/identify/generated-types.d.ts +7 -0
- package/dist/esm/identify/generated-types.js +2 -0
- package/dist/esm/identify/generated-types.js.map +1 -0
- package/dist/esm/identify/index.d.ts +6 -0
- package/dist/esm/identify/index.js +42 -0
- package/dist/esm/identify/index.js.map +1 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.js +46 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/track/generated-types.d.ts +8 -0
- package/dist/esm/track/generated-types.js +2 -0
- package/dist/esm/track/generated-types.js.map +1 -0
- package/dist/esm/track/index.d.ts +6 -0
- package/dist/esm/track/index.js +56 -0
- package/dist/esm/track/index.js.map +1 -0
- package/dist/esm/types.d.ts +9 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +25 -0
- package/src/__tests__/__snapshots__/index.test.ts.snap +16 -0
- package/src/__tests__/index.test.ts +101 -0
- package/src/generated-types.ts +8 -0
- package/src/identify/__tests__/index.test.ts +92 -0
- package/src/identify/generated-types.ts +18 -0
- package/src/identify/index.ts +49 -0
- package/src/index.ts +64 -0
- package/src/track/__tests__/index.test.ts +84 -0
- package/src/track/generated-types.ts +22 -0
- package/src/track/index.ts +63 -0
- package/src/types.ts +10 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Analytics, Context } from '@segment/analytics-next'
|
|
2
|
+
import hubbleDestination, { destination } from '../../index'
|
|
3
|
+
import { Subscription } from '@segment/browser-destination-runtime/types'
|
|
4
|
+
|
|
5
|
+
const subscriptions: Subscription[] = [
|
|
6
|
+
{
|
|
7
|
+
partnerAction: 'track',
|
|
8
|
+
name: 'Track event',
|
|
9
|
+
enabled: true,
|
|
10
|
+
subscribe: 'type = "track"',
|
|
11
|
+
mapping: {
|
|
12
|
+
event: {
|
|
13
|
+
'@path': '$.event'
|
|
14
|
+
},
|
|
15
|
+
attributes: {
|
|
16
|
+
'@path': '$.properties'
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
describe('track', () => {
|
|
23
|
+
beforeAll(() => {
|
|
24
|
+
jest.mock('@segment/browser-destination-runtime/load-script', () => ({
|
|
25
|
+
loadScript: (_src: any, _attributes: any) => {}
|
|
26
|
+
}))
|
|
27
|
+
jest.mock('@segment/browser-destination-runtime/resolve-when', () => ({
|
|
28
|
+
resolveWhen: (_fn: any, _timeout: any) => {}
|
|
29
|
+
}))
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
let track: any
|
|
33
|
+
const mockTrack: jest.Mock<any, any> = jest.fn()
|
|
34
|
+
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
const [hubbleTrack] = await hubbleDestination({
|
|
37
|
+
id: 'testID',
|
|
38
|
+
subscriptions
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
track = hubbleTrack
|
|
42
|
+
|
|
43
|
+
jest.spyOn(destination, 'initialize').mockImplementation(() => {
|
|
44
|
+
const mockedWithTrack = {
|
|
45
|
+
id: 'testID',
|
|
46
|
+
initialized: true,
|
|
47
|
+
emitter: { setSource: jest.fn() },
|
|
48
|
+
track: mockTrack,
|
|
49
|
+
identify: jest.fn(),
|
|
50
|
+
setSource: jest.fn()
|
|
51
|
+
}
|
|
52
|
+
return Promise.resolve(mockedWithTrack)
|
|
53
|
+
})
|
|
54
|
+
await track.load(Context.system(), {} as Analytics)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('it maps event parameters correctly to track function', async () => {
|
|
58
|
+
jest.spyOn(destination.actions.track, 'perform')
|
|
59
|
+
|
|
60
|
+
await track.track?.(
|
|
61
|
+
new Context({
|
|
62
|
+
type: 'track',
|
|
63
|
+
event: 'event-test',
|
|
64
|
+
properties: {
|
|
65
|
+
prop1: 'something',
|
|
66
|
+
prop2: 'another-thing'
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
expect(destination.actions.track.perform).toHaveBeenCalledWith(
|
|
72
|
+
expect.anything(),
|
|
73
|
+
expect.objectContaining({
|
|
74
|
+
payload: {
|
|
75
|
+
event: 'event-test',
|
|
76
|
+
attributes: {
|
|
77
|
+
prop1: 'something',
|
|
78
|
+
prop2: 'another-thing'
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
)
|
|
83
|
+
})
|
|
84
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Generated file. DO NOT MODIFY IT BY HAND.
|
|
2
|
+
|
|
3
|
+
export interface Payload {
|
|
4
|
+
/**
|
|
5
|
+
* Event to be tracked
|
|
6
|
+
*/
|
|
7
|
+
event: string
|
|
8
|
+
/**
|
|
9
|
+
* Object containing the attributes (properties) of the event
|
|
10
|
+
*/
|
|
11
|
+
attributes?: {
|
|
12
|
+
[k: string]: unknown
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Unique identifer of the user
|
|
16
|
+
*/
|
|
17
|
+
userId?: string
|
|
18
|
+
/**
|
|
19
|
+
* Anonymous identifier of the user
|
|
20
|
+
*/
|
|
21
|
+
anonymousId?: string
|
|
22
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
|
|
2
|
+
import { Hubble } from '../types'
|
|
3
|
+
import type { Settings } from '../generated-types'
|
|
4
|
+
import type { Payload } from './generated-types'
|
|
5
|
+
|
|
6
|
+
// Change from unknown to the partner SDK types
|
|
7
|
+
const action: BrowserActionDefinition<Settings, Hubble, Payload> = {
|
|
8
|
+
title: 'Track',
|
|
9
|
+
description: 'Track events to trigger Hubble surveys',
|
|
10
|
+
platform: 'web',
|
|
11
|
+
defaultSubscription: 'type = "track"',
|
|
12
|
+
fields: {
|
|
13
|
+
event: {
|
|
14
|
+
description: 'Event to be tracked',
|
|
15
|
+
label: 'Event',
|
|
16
|
+
required: true,
|
|
17
|
+
type: 'string',
|
|
18
|
+
default: {
|
|
19
|
+
'@path': '$.event'
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
attributes: {
|
|
23
|
+
description: 'Object containing the attributes (properties) of the event',
|
|
24
|
+
type: 'object',
|
|
25
|
+
required: false,
|
|
26
|
+
label: 'Event Attributes',
|
|
27
|
+
default: {
|
|
28
|
+
'@path': '$.properties'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
userId: {
|
|
32
|
+
description: 'Unique identifer of the user',
|
|
33
|
+
type: 'string',
|
|
34
|
+
required: false,
|
|
35
|
+
label: 'User ID',
|
|
36
|
+
default: {
|
|
37
|
+
'@path': '$.userId'
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
anonymousId: {
|
|
41
|
+
description: 'Anonymous identifier of the user',
|
|
42
|
+
type: 'string',
|
|
43
|
+
required: false,
|
|
44
|
+
label: 'Anonymous ID',
|
|
45
|
+
default: {
|
|
46
|
+
'@path': '$.anonymousId'
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
perform: (hubble, event) => {
|
|
51
|
+
const payload = event.payload
|
|
52
|
+
|
|
53
|
+
hubble.track &&
|
|
54
|
+
hubble.track({
|
|
55
|
+
event: payload.event,
|
|
56
|
+
attributes: payload.attributes,
|
|
57
|
+
userId: payload.userId,
|
|
58
|
+
anonymousId: payload.anonymousId
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default action
|
package/src/types.ts
ADDED