@segment/analytics-browser-actions-fullstory 1.29.0 → 1.30.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.
Files changed (59) hide show
  1. package/dist/cjs/identifyUserV2/generated-types.d.ts +9 -0
  2. package/dist/cjs/identifyUserV2/generated-types.js +3 -0
  3. package/dist/cjs/identifyUserV2/generated-types.js.map +1 -0
  4. package/dist/cjs/identifyUserV2/index.d.ts +6 -0
  5. package/dist/cjs/identifyUserV2/index.js +81 -0
  6. package/dist/cjs/identifyUserV2/index.js.map +1 -0
  7. package/dist/cjs/index.js +19 -6
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/trackEventV2/generated-types.d.ts +6 -0
  10. package/dist/cjs/trackEventV2/generated-types.js +3 -0
  11. package/dist/cjs/trackEventV2/generated-types.js.map +1 -0
  12. package/dist/cjs/trackEventV2/index.d.ts +6 -0
  13. package/dist/cjs/trackEventV2/index.js +37 -0
  14. package/dist/cjs/trackEventV2/index.js.map +1 -0
  15. package/dist/cjs/types.d.ts +3 -10
  16. package/dist/cjs/types.js +4 -4
  17. package/dist/cjs/types.js.map +1 -1
  18. package/dist/cjs/viewedPageV2/generated-types.d.ts +6 -0
  19. package/dist/cjs/viewedPageV2/generated-types.js +3 -0
  20. package/dist/cjs/viewedPageV2/generated-types.js.map +1 -0
  21. package/dist/cjs/viewedPageV2/index.d.ts +6 -0
  22. package/dist/cjs/viewedPageV2/index.js +44 -0
  23. package/dist/cjs/viewedPageV2/index.js.map +1 -0
  24. package/dist/esm/identifyUserV2/generated-types.d.ts +9 -0
  25. package/dist/esm/identifyUserV2/generated-types.js +2 -0
  26. package/dist/esm/identifyUserV2/generated-types.js.map +1 -0
  27. package/dist/esm/identifyUserV2/index.d.ts +6 -0
  28. package/dist/esm/identifyUserV2/index.js +79 -0
  29. package/dist/esm/identifyUserV2/index.js.map +1 -0
  30. package/dist/esm/index.js +20 -7
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/trackEventV2/generated-types.d.ts +6 -0
  33. package/dist/esm/trackEventV2/generated-types.js +2 -0
  34. package/dist/esm/trackEventV2/generated-types.js.map +1 -0
  35. package/dist/esm/trackEventV2/index.d.ts +6 -0
  36. package/dist/esm/trackEventV2/index.js +35 -0
  37. package/dist/esm/trackEventV2/index.js.map +1 -0
  38. package/dist/esm/types.d.ts +3 -10
  39. package/dist/esm/types.js +2 -2
  40. package/dist/esm/types.js.map +1 -1
  41. package/dist/esm/viewedPageV2/generated-types.d.ts +6 -0
  42. package/dist/esm/viewedPageV2/generated-types.js +2 -0
  43. package/dist/esm/viewedPageV2/generated-types.js.map +1 -0
  44. package/dist/esm/viewedPageV2/index.d.ts +6 -0
  45. package/dist/esm/viewedPageV2/index.js +42 -0
  46. package/dist/esm/viewedPageV2/index.js.map +1 -0
  47. package/dist/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +3 -3
  49. package/src/__tests__/fullstory.test.ts +131 -81
  50. package/src/__tests__/fullstoryV2.test.ts +277 -0
  51. package/src/__tests__/initialization.test.ts +81 -0
  52. package/src/identifyUserV2/generated-types.ts +26 -0
  53. package/src/identifyUserV2/index.ts +95 -0
  54. package/src/index.ts +20 -7
  55. package/src/trackEventV2/generated-types.ts +14 -0
  56. package/src/trackEventV2/index.ts +44 -0
  57. package/src/types.ts +3 -9
  58. package/src/viewedPageV2/generated-types.ts +14 -0
  59. package/src/viewedPageV2/index.ts +52 -0
@@ -0,0 +1,95 @@
1
+ import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
2
+ import type { Settings } from '../generated-types'
3
+ import type { Payload } from './generated-types'
4
+ import type { FS } from '../types'
5
+ import { segmentEventSource } from '..'
6
+
7
+ // Change from unknown to the partner SDK types
8
+ const action: BrowserActionDefinition<Settings, FS, Payload> = {
9
+ title: 'Identify User V2',
10
+ description: 'Sets user identity properties',
11
+ platform: 'web',
12
+ defaultSubscription: 'type = "identify"',
13
+ fields: {
14
+ userId: {
15
+ type: 'string',
16
+ required: false,
17
+ description: "The user's id",
18
+ label: 'User ID',
19
+ default: {
20
+ '@path': '$.userId'
21
+ }
22
+ },
23
+ anonymousId: {
24
+ type: 'string',
25
+ required: false,
26
+ description: "The user's anonymous id",
27
+ label: 'Anonymous ID',
28
+ default: {
29
+ '@path': '$.anonymousId'
30
+ }
31
+ },
32
+ displayName: {
33
+ type: 'string',
34
+ required: false,
35
+ description: "The user's display name",
36
+ label: 'Display Name',
37
+ default: {
38
+ '@path': '$.traits.name'
39
+ }
40
+ },
41
+ email: {
42
+ type: 'string',
43
+ required: false,
44
+ description: "The user's email",
45
+ label: 'Email',
46
+ default: {
47
+ '@path': '$.traits.email'
48
+ }
49
+ },
50
+ traits: {
51
+ type: 'object',
52
+ required: false,
53
+ description: 'The Segment traits to be forwarded to FullStory',
54
+ label: 'Traits',
55
+ default: {
56
+ '@path': '$.traits'
57
+ }
58
+ }
59
+ },
60
+ perform: (FS, event) => {
61
+ const newTraits: Record<string, unknown> = event.payload.traits || {}
62
+
63
+ if (event.payload.anonymousId) {
64
+ newTraits.segmentAnonymousId = event.payload.anonymousId
65
+ }
66
+
67
+ const userProperties = {
68
+ ...newTraits,
69
+ ...(event.payload.email !== undefined && { email: event.payload.email }),
70
+ ...(event.payload.displayName !== undefined && { displayName: event.payload.displayName })
71
+ }
72
+
73
+ if (event.payload.userId) {
74
+ FS(
75
+ 'setIdentity',
76
+ {
77
+ uid: event.payload.userId,
78
+ properties: userProperties
79
+ },
80
+ segmentEventSource
81
+ )
82
+ } else {
83
+ FS(
84
+ 'setProperties',
85
+ {
86
+ type: 'user',
87
+ properties: userProperties
88
+ },
89
+ segmentEventSource
90
+ )
91
+ }
92
+ }
93
+ }
94
+
95
+ export default action
package/src/index.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import type { FS } from './types'
2
2
  import type { BrowserDestinationDefinition } from '@segment/browser-destination-runtime/types'
3
- import { FSPackage } from './types'
3
+ import { initFullStory } from './types'
4
4
  import { browserDestination } from '@segment/browser-destination-runtime/shim'
5
5
  import type { Settings } from './generated-types'
6
6
  import trackEvent from './trackEvent'
7
+ import trackEventV2 from './trackEventV2'
7
8
  import identifyUser from './identifyUser'
9
+ import identifyUserV2 from './identifyUserV2'
8
10
  import viewedPage from './viewedPage'
11
+ import viewedPageV2 from './viewedPageV2'
9
12
  import { defaultValues } from '@segment/actions-core'
10
13
 
11
14
  declare global {
@@ -24,15 +27,22 @@ export const destination: BrowserDestinationDefinition<Settings, FS> = {
24
27
  {
25
28
  name: 'Track Event',
26
29
  subscribe: 'type = "track"',
27
- partnerAction: 'trackEvent',
28
- mapping: defaultValues(trackEvent.fields),
30
+ partnerAction: 'trackEventV2',
31
+ mapping: defaultValues(trackEventV2.fields),
29
32
  type: 'automatic'
30
33
  },
31
34
  {
32
35
  name: 'Identify User',
33
36
  subscribe: 'type = "identify"',
34
- partnerAction: 'identifyUser',
35
- mapping: defaultValues(identifyUser.fields),
37
+ partnerAction: 'identifyUserV2',
38
+ mapping: defaultValues(identifyUserV2.fields),
39
+ type: 'automatic'
40
+ },
41
+ {
42
+ name: 'Viewed Page',
43
+ subscribe: 'type = "page"',
44
+ partnerAction: 'viewedPageV2',
45
+ mapping: defaultValues(viewedPageV2.fields),
36
46
  type: 'automatic'
37
47
  }
38
48
  ],
@@ -60,11 +70,14 @@ export const destination: BrowserDestinationDefinition<Settings, FS> = {
60
70
  },
61
71
  actions: {
62
72
  trackEvent,
73
+ trackEventV2,
63
74
  identifyUser,
64
- viewedPage
75
+ identifyUserV2,
76
+ viewedPage,
77
+ viewedPageV2
65
78
  },
66
79
  initialize: async ({ settings }, dependencies) => {
67
- FSPackage.init(settings)
80
+ initFullStory(settings)
68
81
  await dependencies.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, 'FS'), 100)
69
82
  return window.FS
70
83
  }
@@ -0,0 +1,14 @@
1
+ // Generated file. DO NOT MODIFY IT BY HAND.
2
+
3
+ export interface Payload {
4
+ /**
5
+ * The name of the event.
6
+ */
7
+ name: string
8
+ /**
9
+ * A JSON object containing additional information about the event that will be indexed by FullStory.
10
+ */
11
+ properties?: {
12
+ [k: string]: unknown
13
+ }
14
+ }
@@ -0,0 +1,44 @@
1
+ import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
2
+ import type { Settings } from '../generated-types'
3
+ import type { Payload } from './generated-types'
4
+ import type { FS } from '../types'
5
+ import { segmentEventSource } from '..'
6
+
7
+ const action: BrowserActionDefinition<Settings, FS, Payload> = {
8
+ title: 'Track Event V2',
9
+ description: 'Track events',
10
+ platform: 'web',
11
+ defaultSubscription: 'type = "track"',
12
+ fields: {
13
+ name: {
14
+ description: 'The name of the event.',
15
+ label: 'Name',
16
+ required: true,
17
+ type: 'string',
18
+ default: {
19
+ '@path': '$.event'
20
+ }
21
+ },
22
+ properties: {
23
+ description: 'A JSON object containing additional information about the event that will be indexed by FullStory.',
24
+ label: 'Properties',
25
+ required: false,
26
+ type: 'object',
27
+ default: {
28
+ '@path': '$.properties'
29
+ }
30
+ }
31
+ },
32
+ perform: (FS, event) => {
33
+ FS(
34
+ 'trackEvent',
35
+ {
36
+ name: event.payload.name,
37
+ properties: event.payload.properties ?? {}
38
+ },
39
+ segmentEventSource
40
+ )
41
+ }
42
+ }
43
+
44
+ export default action
package/src/types.ts CHANGED
@@ -1,10 +1,4 @@
1
- import * as FullStory from '@fullstory/browser'
1
+ import { FullStory, init as initFullStory } from '@fullstory/browser'
2
2
 
3
- export const FSPackage = FullStory
4
- export type FS = typeof FullStory & {
5
- // setVars is not available on the FS client yet.
6
- setVars: (eventName: string, eventProperties: object, source: string) => {}
7
- setUserVars: (eventProperties: object, source: string) => void
8
- event: (eventName: string, eventProperties: { [key: string]: unknown }, source: string) => void
9
- identify: (uid: string, customVars: FullStory.UserVars, source: string) => void
10
- }
3
+ export type FS = typeof FullStory
4
+ export { FullStory, initFullStory }
@@ -0,0 +1,14 @@
1
+ // Generated file. DO NOT MODIFY IT BY HAND.
2
+
3
+ export interface Payload {
4
+ /**
5
+ * The name of the page that was viewed.
6
+ */
7
+ pageName?: string
8
+ /**
9
+ * The properties of the page that was viewed.
10
+ */
11
+ properties?: {
12
+ [k: string]: unknown
13
+ }
14
+ }
@@ -0,0 +1,52 @@
1
+ import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
2
+ import type { Settings } from '../generated-types'
3
+ import type { Payload } from './generated-types'
4
+ import type { FS } from '../types'
5
+ import { segmentEventSource } from '..'
6
+
7
+ const action: BrowserActionDefinition<Settings, FS, Payload> = {
8
+ title: 'Viewed Page V2',
9
+ description: 'Sets page properties',
10
+ defaultSubscription: 'type = "page"',
11
+ platform: 'web',
12
+ fields: {
13
+ pageName: {
14
+ type: 'string',
15
+ required: false,
16
+ description: 'The name of the page that was viewed.',
17
+ label: 'Page Name',
18
+ default: {
19
+ '@if': {
20
+ exists: { '@path': '$.category' },
21
+ then: { '@path': '$.category' },
22
+ else: { '@path': '$.name' }
23
+ }
24
+ }
25
+ },
26
+ properties: {
27
+ type: 'object',
28
+ required: false,
29
+ description: 'The properties of the page that was viewed.',
30
+ label: 'Properties',
31
+ default: {
32
+ '@path': '$.properties'
33
+ }
34
+ }
35
+ },
36
+ perform: (FS, event) => {
37
+ const properties: object = event.payload.pageName
38
+ ? { pageName: event.payload.pageName, ...event.payload.properties }
39
+ : { ...event.payload.properties }
40
+
41
+ FS(
42
+ 'setProperties',
43
+ {
44
+ type: 'page',
45
+ properties
46
+ },
47
+ segmentEventSource
48
+ )
49
+ }
50
+ }
51
+
52
+ export default action