@customerio/cdp-analytics-browser 0.3.9 → 0.3.11

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 (31) hide show
  1. package/dist/cjs/generated/version.js +1 -1
  2. package/dist/cjs/generated/version.js.map +1 -1
  3. package/dist/cjs/plugins/in-app-plugin/inbox_messages.js +17 -4
  4. package/dist/cjs/plugins/in-app-plugin/inbox_messages.js.map +1 -1
  5. package/dist/cjs/plugins/in-app-plugin/index.js +11 -5
  6. package/dist/cjs/plugins/in-app-plugin/index.js.map +1 -1
  7. package/dist/pkg/generated/version.js +1 -1
  8. package/dist/pkg/generated/version.js.map +1 -1
  9. package/dist/pkg/plugins/in-app-plugin/inbox_messages.js +17 -4
  10. package/dist/pkg/plugins/in-app-plugin/inbox_messages.js.map +1 -1
  11. package/dist/pkg/plugins/in-app-plugin/index.js +11 -5
  12. package/dist/pkg/plugins/in-app-plugin/index.js.map +1 -1
  13. package/dist/types/core/buffer/index.d.ts +1 -1
  14. package/dist/types/core/buffer/index.d.ts.map +1 -1
  15. package/dist/types/generated/version.d.ts +1 -1
  16. package/dist/types/generated/version.d.ts.map +1 -1
  17. package/dist/types/plugins/in-app-plugin/inbox_messages.d.ts +10 -1
  18. package/dist/types/plugins/in-app-plugin/inbox_messages.d.ts.map +1 -1
  19. package/dist/types/plugins/in-app-plugin/index.d.ts.map +1 -1
  20. package/dist/umd/852.js +1 -1
  21. package/dist/umd/852.js.gz +0 -0
  22. package/dist/umd/inAppPlugin.js +1 -1
  23. package/dist/umd/inAppPlugin.js.gz +0 -0
  24. package/dist/umd/index.js +1 -1
  25. package/dist/umd/index.js.gz +0 -0
  26. package/dist/umd/standalone.js +1 -1
  27. package/dist/umd/standalone.js.gz +0 -0
  28. package/package.json +3 -3
  29. package/src/generated/version.ts +1 -1
  30. package/src/plugins/in-app-plugin/inbox_messages.ts +32 -3
  31. package/src/plugins/in-app-plugin/index.ts +9 -3
@@ -1,8 +1,12 @@
1
+ import { Analytics } from '../../core/analytics'
2
+ import { JourneysEvents } from './events'
3
+
1
4
  export interface GistInboxMessage {
2
5
  messageType: string
3
6
  expiry: string
4
7
  priority: number
5
8
  topics?: string[]
9
+ type: string
6
10
  properties: { [key: string]: any }
7
11
  queueId: string
8
12
  userToken: string
@@ -24,6 +28,18 @@ export interface InboxMessage {
24
28
  // When the message was sent
25
29
  readonly sentAt: string
26
30
 
31
+ // Optional message type
32
+ readonly type: string
33
+
34
+ // Optional list of topics this message belongs to
35
+ readonly topics: string[]
36
+
37
+ /**
38
+ * Tracks a click metric for the message with an optional tracked response value.
39
+ * @returns void
40
+ */
41
+ trackClick(trackedResponse?: string): void
42
+
27
43
  /**
28
44
  * Marks this message as opened
29
45
  * @returns Promise that resolves when the message is marked as opened
@@ -71,6 +87,7 @@ export interface InboxAPI {
71
87
  }
72
88
 
73
89
  function createInboxMessage(
90
+ analyticsInstance: Analytics,
74
91
  gist: any,
75
92
  gistMessage: GistInboxMessage
76
93
  ): InboxMessage {
@@ -79,6 +96,18 @@ function createInboxMessage(
79
96
  messageId: gistMessage.queueId,
80
97
  opened: gistMessage?.opened === true,
81
98
  properties: gistMessage.properties,
99
+ type: gistMessage.type || "",
100
+ topics: gistMessage.topics || [],
101
+ trackClick: (trackedResponse?: string) => {
102
+ if(typeof gistMessage.deliveryId === 'undefined' || gistMessage.deliveryId === '') {
103
+ return
104
+ }
105
+ void analyticsInstance.track(JourneysEvents.Metric, {
106
+ deliveryId: gistMessage.deliveryId,
107
+ metric: JourneysEvents.Clicked,
108
+ actionName: trackedResponse,
109
+ })
110
+ },
82
111
  markOpened: async () => {
83
112
  await gist.updateInboxMessageOpenState(gistMessage.queueId, true)
84
113
  },
@@ -118,7 +147,7 @@ async function getFilteredMessages(
118
147
  })
119
148
  }
120
149
 
121
- export function createInboxAPI(gist: any, topics: string[]): InboxAPI {
150
+ export function createInboxAPI(analyticsInstance: Analytics, gist: any, topics: string[]): InboxAPI {
122
151
  return {
123
152
  total: async () => {
124
153
  const messages = await getFilteredMessages(gist, topics, null)
@@ -132,7 +161,7 @@ export function createInboxAPI(gist: any, topics: string[]): InboxAPI {
132
161
  },
133
162
  messages: async (): Promise<InboxMessage[]> => {
134
163
  const messages = await getFilteredMessages(gist, topics, null)
135
- return messages.map((msg) => createInboxMessage(gist, msg))
164
+ return messages.map((msg) => createInboxMessage(analyticsInstance, gist, msg))
136
165
  },
137
166
  onUpdates: (callback: (messages: InboxMessage[]) => void): (() => void) => {
138
167
  const handler = async (gistMessages: GistInboxMessage[]) => {
@@ -143,7 +172,7 @@ export function createInboxAPI(gist: any, topics: string[]): InboxAPI {
143
172
  gistMessages
144
173
  )
145
174
  const inboxMessages = filteredMessages.map((msg) =>
146
- createInboxMessage(gist, msg)
175
+ createInboxMessage(analyticsInstance, gist, msg)
147
176
  )
148
177
 
149
178
  callback(inboxMessages)
@@ -86,8 +86,11 @@ export function InAppPlugin(settings: InAppPluginSettings): Plugin {
86
86
  })
87
87
  return
88
88
  }
89
- const broadcastId: Number =
89
+ let broadcastId: Number =
90
90
  message?.properties?.gist?.broadcast?.broadcastIdInt
91
+ if (!broadcastId) {
92
+ broadcastId = message?.properties?.gist?.broadcast?.broadcastId
93
+ }
91
94
  if (broadcastId) {
92
95
  const templateId = message?.properties?.gist?.broadcast?.templateId
93
96
  void _analytics.track(JourneysEvents.Content, {
@@ -136,8 +139,11 @@ export function InAppPlugin(settings: InAppPluginSettings): Plugin {
136
139
  })
137
140
  return
138
141
  }
139
- const broadcastId: Number =
142
+ let broadcastId: Number =
140
143
  params?.message?.properties?.gist?.broadcast?.broadcastIdInt
144
+ if (!broadcastId) {
145
+ broadcastId = params?.message?.properties?.gist?.broadcast?.broadcastId
146
+ }
141
147
  if (broadcastId) {
142
148
  const templateId: Number =
143
149
  params?.message?.properties?.gist?.broadcast?.templateId
@@ -229,7 +235,7 @@ export function InAppPlugin(settings: InAppPluginSettings): Plugin {
229
235
  'Customer.io In-App Plugin is not loaded yet. Ensure the plugin is initialized before calling inbox().'
230
236
  )
231
237
  }
232
- return createInboxAPI(Gist, topics)
238
+ return createInboxAPI(instance, Gist, topics)
233
239
  }
234
240
 
235
241
  _pluginLoaded = true