@customerio/cdp-analytics-browser 0.0.1 → 0.0.2
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/dist/cjs/browser/index.js +45 -28
- package/dist/cjs/browser/index.js.map +1 -1
- package/dist/cjs/plugins/customerio/batched-dispatcher.js +2 -2
- package/dist/cjs/plugins/customerio/batched-dispatcher.js.map +1 -1
- package/dist/cjs/plugins/customerio/index.js +2 -1
- package/dist/cjs/plugins/customerio/index.js.map +1 -1
- package/dist/cjs/plugins/in-app-plugin/events.js +37 -0
- package/dist/cjs/plugins/in-app-plugin/events.js.map +1 -0
- package/dist/cjs/plugins/in-app-plugin/index.js +169 -0
- package/dist/cjs/plugins/in-app-plugin/index.js.map +1 -0
- package/dist/pkg/browser/index.js +45 -28
- package/dist/pkg/browser/index.js.map +1 -1
- package/dist/pkg/plugins/customerio/batched-dispatcher.js +2 -2
- package/dist/pkg/plugins/customerio/batched-dispatcher.js.map +1 -1
- package/dist/pkg/plugins/customerio/index.js +2 -1
- package/dist/pkg/plugins/customerio/index.js.map +1 -1
- package/dist/pkg/plugins/in-app-plugin/events.js +32 -0
- package/dist/pkg/plugins/in-app-plugin/events.js.map +1 -0
- package/dist/pkg/plugins/in-app-plugin/index.js +165 -0
- package/dist/pkg/plugins/in-app-plugin/index.js.map +1 -0
- package/dist/types/browser/index.d.ts.map +1 -1
- package/dist/types/plugins/customerio/batched-dispatcher.d.ts +1 -1
- package/dist/types/plugins/customerio/batched-dispatcher.d.ts.map +1 -1
- package/dist/types/plugins/customerio/index.d.ts.map +1 -1
- package/dist/types/plugins/in-app-plugin/events.d.ts +15 -0
- package/dist/types/plugins/in-app-plugin/events.d.ts.map +1 -0
- package/dist/types/plugins/in-app-plugin/index.d.ts +11 -0
- package/dist/types/plugins/in-app-plugin/index.d.ts.map +1 -0
- package/dist/umd/646.js +1 -0
- package/dist/umd/646.js.gz +0 -0
- package/dist/umd/{799.bundle.f804d7b881cf284fbd56.js.gz → 799.js.gz} +0 -0
- package/dist/umd/{870.bundle.e0b7bfa4797bb87217c9.js.gz → 870.js.gz} +0 -0
- package/dist/umd/{ajs-destination.bundle.847bf422720e5616c9d5.js.gz → ajs-destination.js.gz} +0 -0
- package/dist/umd/{auto-track.bundle.758629f7a47544af2d44.js.gz → auto-track.js.gz} +0 -0
- package/dist/umd/inAppPlugin.js +1 -0
- package/dist/umd/inAppPlugin.js.gz +0 -0
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.gz +0 -0
- package/dist/umd/{legacyVideos.bundle.d7ac356ab28fab36e111.js.gz → legacyVideos.js.gz} +0 -0
- package/dist/umd/{queryString.bundle.913501e40ce64ef92884.js.gz → queryString.js.gz} +0 -0
- package/dist/umd/{remoteMiddleware.bundle.3bc569811c4c2c93d90c.js.gz → remoteMiddleware.js.gz} +0 -0
- package/dist/umd/{schemaFilter.bundle.bb8180ae95843c8f138e.js.gz → schemaFilter.js.gz} +0 -0
- package/dist/umd/standalone.js +1 -1
- package/dist/umd/standalone.js.gz +0 -0
- package/dist/umd/{tsub-middleware.bundle.af0f402084ddd2b605cc.js.gz → tsub-middleware.js.gz} +0 -0
- package/package.json +2 -1
- package/src/browser/index.ts +13 -0
- package/src/generated/version.ts +1 -1
- package/src/plugins/customerio/batched-dispatcher.ts +2 -5
- package/src/plugins/customerio/index.ts +2 -1
- package/src/plugins/in-app-plugin/events.ts +33 -0
- package/src/plugins/in-app-plugin/index.ts +156 -0
- /package/dist/umd/{799.bundle.f804d7b881cf284fbd56.js → 799.js} +0 -0
- /package/dist/umd/{870.bundle.e0b7bfa4797bb87217c9.js → 870.js} +0 -0
- /package/dist/umd/{ajs-destination.bundle.847bf422720e5616c9d5.js → ajs-destination.js} +0 -0
- /package/dist/umd/{auto-track.bundle.758629f7a47544af2d44.js → auto-track.js} +0 -0
- /package/dist/umd/{legacyVideos.bundle.d7ac356ab28fab36e111.js → legacyVideos.js} +0 -0
- /package/dist/umd/{queryString.bundle.913501e40ce64ef92884.js → queryString.js} +0 -0
- /package/dist/umd/{remoteMiddleware.bundle.3bc569811c4c2c93d90c.js → remoteMiddleware.js} +0 -0
- /package/dist/umd/{schemaFilter.bundle.bb8180ae95843c8f138e.js → schemaFilter.js} +0 -0
- /package/dist/umd/{tsub-middleware.bundle.af0f402084ddd2b605cc.js → tsub-middleware.js} +0 -0
package/src/generated/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated.
|
|
2
|
-
export const version = '0.0.
|
|
2
|
+
export const version = '0.0.2'
|
|
@@ -43,10 +43,7 @@ function chunks(batch: object[]): Array<object[]> {
|
|
|
43
43
|
return result
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export default function batch(
|
|
47
|
-
apiHost: string,
|
|
48
|
-
config?: BatchingDispatchConfig
|
|
49
|
-
) {
|
|
46
|
+
export default function batch(remote: string, config?: BatchingDispatchConfig) {
|
|
50
47
|
let buffer: object[] = []
|
|
51
48
|
let pageUnloaded = false
|
|
52
49
|
|
|
@@ -60,7 +57,7 @@ export default function batch(
|
|
|
60
57
|
|
|
61
58
|
const writeKey = (batch[0] as CustomerioEvent)?.writeKey
|
|
62
59
|
|
|
63
|
-
return fetch(
|
|
60
|
+
return fetch(`${remote}/b`, {
|
|
64
61
|
keepalive: pageUnloaded,
|
|
65
62
|
headers: {
|
|
66
63
|
'Content-Type': 'text/plain',
|
|
@@ -78,7 +78,7 @@ export function customerio(
|
|
|
78
78
|
const deliveryStrategy = settings?.deliveryStrategy
|
|
79
79
|
const client =
|
|
80
80
|
deliveryStrategy?.strategy === 'batching'
|
|
81
|
-
? batch(
|
|
81
|
+
? batch(remote, deliveryStrategy.config)
|
|
82
82
|
: standard(deliveryStrategy?.config as StandardDispatcherConfig)
|
|
83
83
|
|
|
84
84
|
async function send(ctx: Context): Promise<Context> {
|
|
@@ -130,6 +130,7 @@ export function customerio(
|
|
|
130
130
|
page: send,
|
|
131
131
|
alias: send,
|
|
132
132
|
group: send,
|
|
133
|
+
screen: send,
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
// Buffer may already have items if they were previously stored in localStorage.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export enum InAppEvents {
|
|
2
|
+
MessageOpened = 'in-app:message-opened',
|
|
3
|
+
MessageDismissed = 'in-app:message-dismissed',
|
|
4
|
+
MessageError = 'in-app:message-error',
|
|
5
|
+
MessageAction = 'in-app:message-action'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const allEvents:string[] = Object.values(InAppEvents);
|
|
9
|
+
|
|
10
|
+
export enum SemanticEvents {
|
|
11
|
+
JourneyMetric = 'Report Delivery Event',
|
|
12
|
+
Opened = 'opened',
|
|
13
|
+
Clicked = 'clicked',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function newEvent(type:string, detail:any): CustomEvent {
|
|
17
|
+
return new CustomEvent(type, { detail })
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function gistToCIO(gistEvent:string): string {
|
|
21
|
+
switch (gistEvent) {
|
|
22
|
+
case 'messageShown':
|
|
23
|
+
return InAppEvents.MessageOpened;
|
|
24
|
+
case 'messageDismissed':
|
|
25
|
+
return InAppEvents.MessageDismissed;
|
|
26
|
+
case 'messageError':
|
|
27
|
+
return InAppEvents.MessageError;
|
|
28
|
+
case 'messageAction':
|
|
29
|
+
return InAppEvents.MessageAction;
|
|
30
|
+
default:
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Analytics } from '../../core/analytics'
|
|
2
|
+
import { Context } from '../../core/context'
|
|
3
|
+
import { Plugin } from '../../core/plugin'
|
|
4
|
+
|
|
5
|
+
import { InAppEvents, SemanticEvents, newEvent, allEvents, gistToCIO } from './events'
|
|
6
|
+
import Gist from 'customerio-gist-web'
|
|
7
|
+
|
|
8
|
+
export { InAppEvents }
|
|
9
|
+
|
|
10
|
+
export type InAppPluginSettings = {
|
|
11
|
+
siteId: string | undefined
|
|
12
|
+
events: EventListenerOrEventListenerObject | null | undefined
|
|
13
|
+
|
|
14
|
+
_env: string | undefined
|
|
15
|
+
_logging: boolean | undefined
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function InAppPlugin(
|
|
19
|
+
settings: InAppPluginSettings,
|
|
20
|
+
): Plugin {
|
|
21
|
+
|
|
22
|
+
let _analytics: Analytics;
|
|
23
|
+
let _gistLoaded:boolean = false;
|
|
24
|
+
let _pluginLoaded:boolean = false;
|
|
25
|
+
const _eventTarget:EventTarget = new EventTarget();
|
|
26
|
+
|
|
27
|
+
function attachListeners() {
|
|
28
|
+
if(!_gistLoaded || _pluginLoaded)
|
|
29
|
+
return;
|
|
30
|
+
|
|
31
|
+
_analytics.on('reset', reset);
|
|
32
|
+
|
|
33
|
+
if(settings.events) {
|
|
34
|
+
allEvents.forEach((event) => {
|
|
35
|
+
_eventTarget.addEventListener(event, settings?.events as EventListenerOrEventListenerObject);
|
|
36
|
+
});
|
|
37
|
+
['messageShown', 'messageDismissed', 'messageError'].forEach((event) => {
|
|
38
|
+
Gist.events.on(event, (message: any) => {
|
|
39
|
+
_eventTarget.dispatchEvent(newEvent(gistToCIO(event), {
|
|
40
|
+
messageId: message.messageId,
|
|
41
|
+
deliveryId: message.properties?.gist?.campaignId,
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Gist.events.on('messageShown', (message: any) => {
|
|
48
|
+
const deliveryId:string = message?.properties?.gist?.campaignId;
|
|
49
|
+
if (typeof deliveryId != 'undefined' && deliveryId != '') {
|
|
50
|
+
_analytics.track(SemanticEvents.JourneyMetric, {
|
|
51
|
+
'deliveryId': deliveryId,
|
|
52
|
+
'metric': SemanticEvents.Opened,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
Gist.events.on('messageAction', (params: any) => {
|
|
58
|
+
const deliveryId:string = params?.message?.properties?.gist?.campaignId;
|
|
59
|
+
if (params.action != 'gist://close' && typeof deliveryId != 'undefined' && deliveryId != '') {
|
|
60
|
+
_analytics.track(SemanticEvents.JourneyMetric, {
|
|
61
|
+
'deliveryId': deliveryId,
|
|
62
|
+
'metric': SemanticEvents.Clicked,
|
|
63
|
+
'actionName': params.name,
|
|
64
|
+
'actionValue': params.action,
|
|
65
|
+
});
|
|
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
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function page(ctx: Context): Promise<Context> {
|
|
84
|
+
if(!_pluginLoaded)
|
|
85
|
+
return ctx;
|
|
86
|
+
|
|
87
|
+
const page:string = ctx.event?.properties?.name ?? ctx.event?.properties?.url;
|
|
88
|
+
if(typeof page === 'string' && page.length > 0) {
|
|
89
|
+
Gist.setCurrentRoute(page);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return ctx;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function reset(ctx: Context): Promise<Context> {
|
|
96
|
+
await Gist.clearUserToken();
|
|
97
|
+
return ctx;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function syncUserToken(ctx: Context): Promise<Context> {
|
|
101
|
+
if(!_gistLoaded)
|
|
102
|
+
return ctx;
|
|
103
|
+
|
|
104
|
+
const user = _analytics.user().id();
|
|
105
|
+
if (typeof user === 'string' && user.length > 0) {
|
|
106
|
+
await Gist.setUserToken(user);
|
|
107
|
+
} else {
|
|
108
|
+
await Gist.clearUserToken();
|
|
109
|
+
}
|
|
110
|
+
return ctx;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const customerio: Plugin = {
|
|
114
|
+
name: 'Customer.io In-App Plugin',
|
|
115
|
+
type: 'before',
|
|
116
|
+
version: '0.0.1',
|
|
117
|
+
isLoaded: (): boolean => _pluginLoaded,
|
|
118
|
+
load: async (ctx: Context, instance: Analytics) => {
|
|
119
|
+
_analytics = instance;
|
|
120
|
+
|
|
121
|
+
if(settings.siteId == null || settings.siteId == "") {
|
|
122
|
+
_error("siteId is required. Can't initialize.")
|
|
123
|
+
return ctx;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
await Gist.setup({
|
|
127
|
+
siteId: settings.siteId,
|
|
128
|
+
env: settings._env? settings._env : "prod",
|
|
129
|
+
logging: settings._logging,
|
|
130
|
+
});
|
|
131
|
+
_gistLoaded = true;
|
|
132
|
+
|
|
133
|
+
await syncUserToken(ctx);
|
|
134
|
+
attachListeners();
|
|
135
|
+
|
|
136
|
+
_pluginLoaded = true;
|
|
137
|
+
|
|
138
|
+
return Promise.resolve();
|
|
139
|
+
},
|
|
140
|
+
identify: syncUserToken,
|
|
141
|
+
page: page,
|
|
142
|
+
unload: async () => {
|
|
143
|
+
if(settings.events) {
|
|
144
|
+
allEvents.forEach((event) => {
|
|
145
|
+
_eventTarget.removeEventListener(event, settings?.events as EventListenerOrEventListenerObject);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return customerio;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function _error(msg: string) {
|
|
155
|
+
console.error(`[Customer.io In-App Plugin] ${msg}`)
|
|
156
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|