@solomon-tech/webanalytics-sdk 1.0.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 ADDED
@@ -0,0 +1,20 @@
1
+ # Deploy
2
+
3
+ Add to page/liquid:
4
+
5
+ ```html
6
+ ...
7
+ <script>
8
+ //
9
+ window.__SOLOMON__ = {
10
+ companyId: "SOLOMON"
11
+ };
12
+ </script>
13
+ <script defer src="https://storage.googleapis.com/solomon-app-scripts/webanalytics-events.js"></script>
14
+ ...
15
+ ```
16
+
17
+ HTML5 has 3 options to load scripts: sync, defer and async. Sync adds delay to rendering, so it should be avoided. Defer is preferred since it does not block rendering.
18
+
19
+ Async could be used but it does not prevent DOMContentLoaded event. Currently, we send PageView on this event. This should be reviewed later on.
20
+
@@ -0,0 +1,3 @@
1
+ declare const getFbp: () => Promise<string | null>;
2
+ declare const getFbc: () => Promise<string | null>;
3
+ export { getFbp, getFbc };
@@ -0,0 +1,21 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getCookie } from "../utils";
11
+ const FBP_COOKIE_NAME = "_fbp";
12
+ const FBC_COOKIE_NAME = "_fbc";
13
+ const getFbp = () => __awaiter(void 0, void 0, void 0, function* () {
14
+ const cookie = (yield getCookie(FBP_COOKIE_NAME));
15
+ return cookie;
16
+ });
17
+ const getFbc = () => __awaiter(void 0, void 0, void 0, function* () {
18
+ const cookie = (yield getCookie(FBC_COOKIE_NAME));
19
+ return cookie;
20
+ });
21
+ export { getFbp, getFbc };
@@ -0,0 +1,2 @@
1
+ declare const getLegacyId: () => Promise<string | null>;
2
+ export { getLegacyId };
@@ -0,0 +1,16 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getAllStorage } from "../utils";
11
+ const LEGACY_ID_KEY = "uniqueId";
12
+ const getLegacyId = () => __awaiter(void 0, void 0, void 0, function* () {
13
+ const legacyId = (yield getAllStorage(LEGACY_ID_KEY));
14
+ return legacyId || null;
15
+ });
16
+ export { getLegacyId };
@@ -0,0 +1,2 @@
1
+ declare const getSessionId: () => Promise<string>;
2
+ export { getSessionId };
@@ -0,0 +1,25 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getCookie, setCookie } from "../utils";
11
+ const SESSION_ID_COOKIE_NAME = "solomon-session-id";
12
+ const SESSION_ID_COOKIE_TIME = 30 * 60 * 1000;
13
+ function generateUUIDv4() {
14
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
15
+ const r = (crypto.getRandomValues(new Uint8Array(1))[0] & 15) >> 0;
16
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
17
+ return v.toString(16);
18
+ });
19
+ }
20
+ const getSessionId = () => __awaiter(void 0, void 0, void 0, function* () {
21
+ const cookie = (yield getCookie(SESSION_ID_COOKIE_NAME)) || generateUUIDv4();
22
+ yield setCookie(SESSION_ID_COOKIE_NAME, cookie, SESSION_ID_COOKIE_TIME);
23
+ return cookie;
24
+ });
25
+ export { getSessionId };
@@ -0,0 +1,2 @@
1
+ declare const getUserId: () => Promise<string>;
2
+ export { getUserId };
@@ -0,0 +1,25 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getAllStorage, setAllStorage } from "../utils";
11
+ const USER_ID_KEY = "solomon-user-id";
12
+ const USER_ID_COOKIE_TIME = 365 * 24 * 60 * 60 * 1000;
13
+ function generateUUIDv4() {
14
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
15
+ const r = (crypto.getRandomValues(new Uint8Array(1))[0] & 15) >> 0;
16
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
17
+ return v.toString(16);
18
+ });
19
+ }
20
+ const getUserId = () => __awaiter(void 0, void 0, void 0, function* () {
21
+ const cookie = (yield getAllStorage(USER_ID_KEY)) || generateUUIDv4();
22
+ yield setAllStorage(USER_ID_KEY, cookie, USER_ID_COOKIE_TIME);
23
+ return cookie;
24
+ });
25
+ export { getUserId };
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,292 @@
1
+ import { Product, CustomAliases } from "./types";
2
+ declare enum Type {
3
+ VIEW_PAGE = "VIEW_PAGE",
4
+ CONTENT_VIEW = "CONTENT_VIEW",
5
+ ADD_TO_CART = "ADD_TO_CART",
6
+ INITIATE_CHECKOUT = "INITIATE_CHECKOUT",
7
+ ADD_SHIPPING_INFO = "ADD_SHIPPING_INFO",
8
+ ADD_CUSTOMER_INFO = "ADD_CUSTOMER_INFO",
9
+ ADD_PAYMENT_INFO = "ADD_PAYMENT_INFO",
10
+ CHECKOUT_COMPLETED = "CHECKOUT_COMPLETED"
11
+ }
12
+ declare const SolomonEvent: (companyId: string, type: Type, payload: any, custom_aliases?: Promise<CustomAliases>) => Promise<{
13
+ company_id: string;
14
+ event_id: string;
15
+ event_time: string;
16
+ session_id: string;
17
+ user_id: string;
18
+ fbp: string | null;
19
+ fbc: string | null;
20
+ legacy_id: string | null;
21
+ custom_aliases: CustomAliases | undefined;
22
+ event_type: string;
23
+ page_referrer: string;
24
+ page_path: string;
25
+ utm_source: string;
26
+ utm_medium: string;
27
+ utm_campaign: string;
28
+ utm_term: string;
29
+ utm_content: string;
30
+ sol_source: string;
31
+ sol_medium: string;
32
+ sol_campaign: string;
33
+ sol_content: string;
34
+ event_payload: any;
35
+ voxus_url: string;
36
+ }>;
37
+ declare const ViewPageEvent: (payload: {
38
+ url: string;
39
+ path?: string;
40
+ }, aliases?: Promise<CustomAliases>, companyId?: string) => Promise<{
41
+ company_id: string;
42
+ event_id: string;
43
+ event_time: string;
44
+ session_id: string;
45
+ user_id: string;
46
+ fbp: string | null;
47
+ fbc: string | null;
48
+ legacy_id: string | null;
49
+ custom_aliases: CustomAliases | undefined;
50
+ event_type: string;
51
+ page_referrer: string;
52
+ page_path: string;
53
+ utm_source: string;
54
+ utm_medium: string;
55
+ utm_campaign: string;
56
+ utm_term: string;
57
+ utm_content: string;
58
+ sol_source: string;
59
+ sol_medium: string;
60
+ sol_campaign: string;
61
+ sol_content: string;
62
+ event_payload: any;
63
+ voxus_url: string;
64
+ }>;
65
+ declare const EventTouchpoint: (aliases?: Promise<CustomAliases>, platform?: string, account_id?: string) => Promise<any>;
66
+ declare const ContentViewEvent: (payload: Product & {
67
+ path?: string;
68
+ }, aliases?: Promise<CustomAliases>, companyId?: string) => Promise<{
69
+ company_id: string;
70
+ event_id: string;
71
+ event_time: string;
72
+ session_id: string;
73
+ user_id: string;
74
+ fbp: string | null;
75
+ fbc: string | null;
76
+ legacy_id: string | null;
77
+ custom_aliases: CustomAliases | undefined;
78
+ event_type: string;
79
+ page_referrer: string;
80
+ page_path: string;
81
+ utm_source: string;
82
+ utm_medium: string;
83
+ utm_campaign: string;
84
+ utm_term: string;
85
+ utm_content: string;
86
+ sol_source: string;
87
+ sol_medium: string;
88
+ sol_campaign: string;
89
+ sol_content: string;
90
+ event_payload: any;
91
+ voxus_url: string;
92
+ }>;
93
+ declare const AddToCartEvent: (payload: {
94
+ item_id: string;
95
+ item_quantity: number;
96
+ url?: string;
97
+ path?: string;
98
+ }, aliases?: Promise<CustomAliases>, companyId?: string) => Promise<{
99
+ company_id: string;
100
+ event_id: string;
101
+ event_time: string;
102
+ session_id: string;
103
+ user_id: string;
104
+ fbp: string | null;
105
+ fbc: string | null;
106
+ legacy_id: string | null;
107
+ custom_aliases: CustomAliases | undefined;
108
+ event_type: string;
109
+ page_referrer: string;
110
+ page_path: string;
111
+ utm_source: string;
112
+ utm_medium: string;
113
+ utm_campaign: string;
114
+ utm_term: string;
115
+ utm_content: string;
116
+ sol_source: string;
117
+ sol_medium: string;
118
+ sol_campaign: string;
119
+ sol_content: string;
120
+ event_payload: any;
121
+ voxus_url: string;
122
+ }>;
123
+ export type InitiateCheckoutPayload = {
124
+ 'item_count': number;
125
+ 'items': any;
126
+ 'total_price': number;
127
+ 'currency': string;
128
+ 'total_discount'?: number;
129
+ 'url'?: string;
130
+ 'path'?: string;
131
+ };
132
+ declare const InitiateCheckoutEvent: (payload: InitiateCheckoutPayload, aliases?: Promise<CustomAliases>, companyId?: string) => Promise<{
133
+ company_id: string;
134
+ event_id: string;
135
+ event_time: string;
136
+ session_id: string;
137
+ user_id: string;
138
+ fbp: string | null;
139
+ fbc: string | null;
140
+ legacy_id: string | null;
141
+ custom_aliases: CustomAliases | undefined;
142
+ event_type: string;
143
+ page_referrer: string;
144
+ page_path: string;
145
+ utm_source: string;
146
+ utm_medium: string;
147
+ utm_campaign: string;
148
+ utm_term: string;
149
+ utm_content: string;
150
+ sol_source: string;
151
+ sol_medium: string;
152
+ sol_campaign: string;
153
+ sol_content: string;
154
+ event_payload: any;
155
+ voxus_url: string;
156
+ }>;
157
+ export type AddCustomerInfoPayload = {
158
+ 'item_count': number;
159
+ 'items': any;
160
+ 'total_price': number;
161
+ 'currency': string;
162
+ 'total_discount'?: number;
163
+ 'path'?: string;
164
+ 'url'?: string;
165
+ };
166
+ declare const AddCustomerInfoEvent: (payload: AddCustomerInfoPayload, aliases?: Promise<CustomAliases>, companyId?: string) => Promise<{
167
+ company_id: string;
168
+ event_id: string;
169
+ event_time: string;
170
+ session_id: string;
171
+ user_id: string;
172
+ fbp: string | null;
173
+ fbc: string | null;
174
+ legacy_id: string | null;
175
+ custom_aliases: CustomAliases | undefined;
176
+ event_type: string;
177
+ page_referrer: string;
178
+ page_path: string;
179
+ utm_source: string;
180
+ utm_medium: string;
181
+ utm_campaign: string;
182
+ utm_term: string;
183
+ utm_content: string;
184
+ sol_source: string;
185
+ sol_medium: string;
186
+ sol_campaign: string;
187
+ sol_content: string;
188
+ event_payload: any;
189
+ voxus_url: string;
190
+ }>;
191
+ export type AddShippingInfoPayload = {
192
+ 'item_count': number;
193
+ 'items': any;
194
+ 'total_price': number;
195
+ 'currency': string;
196
+ 'total_discount'?: number;
197
+ 'path'?: string;
198
+ 'url'?: string;
199
+ };
200
+ declare const AddShippingInfoEvent: (payload: AddShippingInfoPayload, aliases?: Promise<CustomAliases>, companyId?: string) => Promise<{
201
+ company_id: string;
202
+ event_id: string;
203
+ event_time: string;
204
+ session_id: string;
205
+ user_id: string;
206
+ fbp: string | null;
207
+ fbc: string | null;
208
+ legacy_id: string | null;
209
+ custom_aliases: CustomAliases | undefined;
210
+ event_type: string;
211
+ page_referrer: string;
212
+ page_path: string;
213
+ utm_source: string;
214
+ utm_medium: string;
215
+ utm_campaign: string;
216
+ utm_term: string;
217
+ utm_content: string;
218
+ sol_source: string;
219
+ sol_medium: string;
220
+ sol_campaign: string;
221
+ sol_content: string;
222
+ event_payload: any;
223
+ voxus_url: string;
224
+ }>;
225
+ export type AddPaymentInfoPayload = {
226
+ 'item_count': number;
227
+ 'items': any;
228
+ 'total_price': number;
229
+ 'currency'?: string;
230
+ 'path'?: string;
231
+ 'url'?: string;
232
+ };
233
+ declare const AddPaymentInfoEvent: (payload: AddPaymentInfoPayload, aliases?: Promise<CustomAliases>, companyId?: string) => Promise<{
234
+ company_id: string;
235
+ event_id: string;
236
+ event_time: string;
237
+ session_id: string;
238
+ user_id: string;
239
+ fbp: string | null;
240
+ fbc: string | null;
241
+ legacy_id: string | null;
242
+ custom_aliases: CustomAliases | undefined;
243
+ event_type: string;
244
+ page_referrer: string;
245
+ page_path: string;
246
+ utm_source: string;
247
+ utm_medium: string;
248
+ utm_campaign: string;
249
+ utm_term: string;
250
+ utm_content: string;
251
+ sol_source: string;
252
+ sol_medium: string;
253
+ sol_campaign: string;
254
+ sol_content: string;
255
+ event_payload: any;
256
+ voxus_url: string;
257
+ }>;
258
+ export type CheckoutCompletedPayload = {
259
+ 'item_count': number;
260
+ 'items': any;
261
+ 'total_price': number;
262
+ 'currency': string;
263
+ 'total_discount'?: number;
264
+ 'url'?: string;
265
+ 'path'?: string;
266
+ };
267
+ declare const CheckoutCompletedEvent: (payload: CheckoutCompletedPayload, aliases?: Promise<CustomAliases>, companyId?: string) => Promise<{
268
+ company_id: string;
269
+ event_id: string;
270
+ event_time: string;
271
+ session_id: string;
272
+ user_id: string;
273
+ fbp: string | null;
274
+ fbc: string | null;
275
+ legacy_id: string | null;
276
+ custom_aliases: CustomAliases | undefined;
277
+ event_type: string;
278
+ page_referrer: string;
279
+ page_path: string;
280
+ utm_source: string;
281
+ utm_medium: string;
282
+ utm_campaign: string;
283
+ utm_term: string;
284
+ utm_content: string;
285
+ sol_source: string;
286
+ sol_medium: string;
287
+ sol_campaign: string;
288
+ sol_content: string;
289
+ event_payload: any;
290
+ voxus_url: string;
291
+ }>;
292
+ export { SolomonEvent, Type, ViewPageEvent as createViewPage, ContentViewEvent, AddToCartEvent, InitiateCheckoutEvent, AddPaymentInfoEvent, AddCustomerInfoEvent, AddShippingInfoEvent, CheckoutCompletedEvent, EventTouchpoint as eventTouchpoint };