@customerio/cdp-analytics-browser 0.1.2 → 0.2.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 (35) hide show
  1. package/dist/cjs/generated/version.js +1 -1
  2. package/dist/cjs/index.js +1 -0
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/plugins/in-app-plugin/events.js +11 -7
  5. package/dist/cjs/plugins/in-app-plugin/events.js.map +1 -1
  6. package/dist/cjs/plugins/in-app-plugin/index.js +51 -21
  7. package/dist/cjs/plugins/in-app-plugin/index.js.map +1 -1
  8. package/dist/pkg/generated/version.js +1 -1
  9. package/dist/pkg/index.js +1 -0
  10. package/dist/pkg/index.js.map +1 -1
  11. package/dist/pkg/plugins/in-app-plugin/events.js +10 -6
  12. package/dist/pkg/plugins/in-app-plugin/events.js.map +1 -1
  13. package/dist/pkg/plugins/in-app-plugin/index.js +52 -22
  14. package/dist/pkg/plugins/in-app-plugin/index.js.map +1 -1
  15. package/dist/types/core/buffer/index.d.ts +1 -1
  16. package/dist/types/generated/version.d.ts +1 -1
  17. package/dist/types/index.d.ts +1 -0
  18. package/dist/types/index.d.ts.map +1 -1
  19. package/dist/types/plugins/in-app-plugin/events.d.ts +7 -3
  20. package/dist/types/plugins/in-app-plugin/events.d.ts.map +1 -1
  21. package/dist/types/plugins/in-app-plugin/index.d.ts +1 -0
  22. package/dist/types/plugins/in-app-plugin/index.d.ts.map +1 -1
  23. package/dist/umd/646.js +1 -1
  24. package/dist/umd/646.js.gz +0 -0
  25. package/dist/umd/inAppPlugin.js +1 -1
  26. package/dist/umd/inAppPlugin.js.gz +0 -0
  27. package/dist/umd/index.js +1 -1
  28. package/dist/umd/index.js.gz +0 -0
  29. package/dist/umd/standalone.js +1 -1
  30. package/dist/umd/standalone.js.gz +0 -0
  31. package/package.json +3 -3
  32. package/src/generated/version.ts +1 -1
  33. package/src/index.ts +2 -0
  34. package/src/plugins/in-app-plugin/events.ts +7 -2
  35. package/src/plugins/in-app-plugin/index.ts +51 -19
@@ -7,12 +7,17 @@ export enum InAppEvents {
7
7
 
8
8
  export const allEvents:string[] = Object.values(InAppEvents);
9
9
 
10
- export enum SemanticEvents {
11
- JourneyMetric = 'Report Delivery Event',
10
+ export enum JourneysEvents {
11
+ Metric = 'Report Delivery Event',
12
+ Content = 'Report Content Event',
12
13
  Opened = 'opened',
13
14
  Clicked = 'clicked',
15
+ ViewedContent = 'viewed_content',
16
+ ClickedContent = 'clicked_content'
14
17
  }
15
18
 
19
+ export const AnonymousContentType = 'iab'
20
+
16
21
  export function newEvent(type:string, detail:any): CustomEvent {
17
22
  return new CustomEvent(type, { detail })
18
23
  }
@@ -2,7 +2,7 @@ import { Analytics } from '../../core/analytics'
2
2
  import { Context } from '../../core/context'
3
3
  import { Plugin } from '../../core/plugin'
4
4
 
5
- import { InAppEvents, SemanticEvents, newEvent, allEvents, gistToCIO } from './events'
5
+ import { InAppEvents, JourneysEvents, newEvent, allEvents, gistToCIO, AnonymousContentType } from './events'
6
6
  import Gist from 'customerio-gist-web'
7
7
 
8
8
  export { InAppEvents }
@@ -13,6 +13,8 @@ export type InAppPluginSettings = {
13
13
 
14
14
  _env: string | undefined
15
15
  _logging: boolean | undefined
16
+
17
+ anonymousInApp: boolean | false
16
18
  }
17
19
 
18
20
  export function InAppPlugin(
@@ -47,36 +49,65 @@ export function InAppPlugin(
47
49
  Gist.events.on('messageShown', (message: any) => {
48
50
  const deliveryId:string = message?.properties?.gist?.campaignId;
49
51
  if (typeof deliveryId != 'undefined' && deliveryId != '') {
50
- _analytics.track(SemanticEvents.JourneyMetric, {
52
+ _analytics.track(JourneysEvents.Metric, {
51
53
  'deliveryId': deliveryId,
52
- 'metric': SemanticEvents.Opened,
54
+ 'metric': JourneysEvents.Opened,
55
+ });
56
+ return;
57
+ }
58
+ const broadcastId:Number = message?.properties?.gist?.broadcast?.broadcastIdInt;
59
+ if (broadcastId) {
60
+ const templateId = message?.properties?.gist?.broadcast?.templateId;
61
+ _analytics.track(JourneysEvents.Content, {
62
+ 'actionType': JourneysEvents.ViewedContent,
63
+ 'contentId': broadcastId,
64
+ 'templateId': templateId,
65
+ 'contentType': AnonymousContentType,
53
66
  });
54
67
  }
55
68
  });
56
69
 
57
70
  Gist.events.on('messageAction', (params: any) => {
71
+ if (params.action == 'gist://close') {
72
+ return;
73
+ }
58
74
  const deliveryId:string = params?.message?.properties?.gist?.campaignId;
59
- if (params.action != 'gist://close' && typeof deliveryId != 'undefined' && deliveryId != '') {
60
- _analytics.track(SemanticEvents.JourneyMetric, {
75
+ if (typeof deliveryId != 'undefined' && deliveryId != '') {
76
+ _analytics.track(JourneysEvents.Metric, {
61
77
  'deliveryId': deliveryId,
62
- 'metric': SemanticEvents.Clicked,
78
+ 'metric': JourneysEvents.Clicked,
63
79
  'actionName': params.name,
64
80
  'actionValue': params.action,
65
81
  });
66
- }
67
- settings.events && _eventTarget.dispatchEvent(newEvent(InAppEvents.MessageAction, {
68
- messageId: params.message.messageId,
69
- deliveryId: deliveryId,
70
- action: params.action,
71
- name: params.name,
72
- actionName: params.name,
73
- actionValue: params.action,
74
- message:{
75
- dismiss: function() {
76
- Gist.dismissMessage(params?.message?.instanceId);
77
- }
82
+ if (settings.events) {
83
+ _eventTarget.dispatchEvent(newEvent(InAppEvents.MessageAction, {
84
+ messageId: params.message.messageId,
85
+ deliveryId: deliveryId,
86
+ action: params.action,
87
+ name: params.name,
88
+ actionName: params.name,
89
+ actionValue: params.action,
90
+ message:{
91
+ dismiss: function() {
92
+ Gist.dismissMessage(params?.message?.instanceId);
93
+ }
94
+ }
95
+ }));
78
96
  }
79
- }));
97
+ return;
98
+ }
99
+ const broadcastId:Number = params?.message?.properties?.gist?.broadcast?.broadcastIdInt;
100
+ if (broadcastId) {
101
+ const templateId:Number = params?.message?.properties?.gist?.broadcast?.templateId;
102
+ _analytics.track(JourneysEvents.Content, {
103
+ 'actionType': JourneysEvents.ClickedContent,
104
+ 'contentId': broadcastId,
105
+ 'templateId': templateId,
106
+ 'contentType': AnonymousContentType,
107
+ 'actionName': params.name,
108
+ 'actionValue': params.action,
109
+ });
110
+ }
80
111
  });
81
112
 
82
113
  Gist.events.on('eventDispatched', (gistEvent: any) => {
@@ -137,6 +168,7 @@ export function InAppPlugin(
137
168
  siteId: settings.siteId,
138
169
  env: settings._env? settings._env : "prod",
139
170
  logging: settings._logging,
171
+ useAnonymousSession: settings.anonymousInApp,
140
172
  });
141
173
  _gistLoaded = true;
142
174