shopkit-analytics 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/LICENSE +21 -0
- package/README.md +769 -0
- package/dist/adapters/index.d.mts +4 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.js +2405 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +23 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/affiliate/index.d.mts +138 -0
- package/dist/affiliate/index.d.ts +138 -0
- package/dist/affiliate/index.js +816 -0
- package/dist/affiliate/index.js.map +1 -0
- package/dist/affiliate/index.mjs +74 -0
- package/dist/affiliate/index.mjs.map +1 -0
- package/dist/affiliate-tracker-BgHwibPv.d.mts +144 -0
- package/dist/affiliate-tracker-BgHwibPv.d.ts +144 -0
- package/dist/chunk-3TQR5DOP.mjs +79 -0
- package/dist/chunk-3TQR5DOP.mjs.map +1 -0
- package/dist/chunk-4MZH5OLR.mjs +2375 -0
- package/dist/chunk-4MZH5OLR.mjs.map +1 -0
- package/dist/chunk-JVEGG6JV.mjs +213 -0
- package/dist/chunk-JVEGG6JV.mjs.map +1 -0
- package/dist/chunk-P4OJDCEZ.mjs +57 -0
- package/dist/chunk-P4OJDCEZ.mjs.map +1 -0
- package/dist/chunk-TNXTKEGS.mjs +758 -0
- package/dist/chunk-TNXTKEGS.mjs.map +1 -0
- package/dist/events/index.d.mts +112 -0
- package/dist/events/index.d.ts +112 -0
- package/dist/events/index.js +2131 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/index.mjs +30 -0
- package/dist/events/index.mjs.map +1 -0
- package/dist/index-BnNRgdUv.d.ts +676 -0
- package/dist/index-GODWc1s6.d.mts +676 -0
- package/dist/index.d.mts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +3269 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +190 -0
- package/dist/index.mjs.map +1 -0
- package/dist/subscriber-43gnCKWe.d.ts +80 -0
- package/dist/subscriber-IFZJU57V.mjs +8 -0
- package/dist/subscriber-IFZJU57V.mjs.map +1 -0
- package/dist/subscriber-sWesj_5p.d.mts +80 -0
- package/dist/types.d.mts +991 -0
- package/dist/types.d.ts +991 -0
- package/dist/types.js +102 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +8 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +110 -0
|
@@ -0,0 +1,2405 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/adapters/index.ts
|
|
32
|
+
var adapters_exports = {};
|
|
33
|
+
__export(adapters_exports, {
|
|
34
|
+
BaseAdapter: () => BaseAdapter,
|
|
35
|
+
GoogleAdapter: () => GoogleAdapter,
|
|
36
|
+
KwikCheckoutAdapter: () => KwikCheckoutAdapter,
|
|
37
|
+
KwikPassAdapter: () => KwikPassAdapter,
|
|
38
|
+
MoengageAdapter: () => MoengageAdapter,
|
|
39
|
+
PixelAdapter: () => PixelAdapter,
|
|
40
|
+
PostHogAdapter: () => PostHogAdapter,
|
|
41
|
+
ShopifyAdapter: () => ShopifyAdapter
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(adapters_exports);
|
|
44
|
+
|
|
45
|
+
// src/logger/index.ts
|
|
46
|
+
var import_pino = __toESM(require("pino"));
|
|
47
|
+
var NoOpLogger = class _NoOpLogger {
|
|
48
|
+
trace() {
|
|
49
|
+
}
|
|
50
|
+
debug() {
|
|
51
|
+
}
|
|
52
|
+
info() {
|
|
53
|
+
}
|
|
54
|
+
warn() {
|
|
55
|
+
}
|
|
56
|
+
error() {
|
|
57
|
+
}
|
|
58
|
+
fatal() {
|
|
59
|
+
}
|
|
60
|
+
child() {
|
|
61
|
+
return new _NoOpLogger();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var PinoLogger = class _PinoLogger {
|
|
65
|
+
constructor(logger2) {
|
|
66
|
+
this.logger = logger2;
|
|
67
|
+
}
|
|
68
|
+
trace(message, ...args) {
|
|
69
|
+
this.logger.trace({ args }, message);
|
|
70
|
+
}
|
|
71
|
+
debug(message, ...args) {
|
|
72
|
+
this.logger.debug({ args }, message);
|
|
73
|
+
}
|
|
74
|
+
info(message, ...args) {
|
|
75
|
+
this.logger.info({ args }, message);
|
|
76
|
+
}
|
|
77
|
+
warn(message, ...args) {
|
|
78
|
+
this.logger.warn({ args }, message);
|
|
79
|
+
}
|
|
80
|
+
error(message, error, ...args) {
|
|
81
|
+
this.logger.error({ error, args }, message);
|
|
82
|
+
}
|
|
83
|
+
fatal(message, error, ...args) {
|
|
84
|
+
this.logger.fatal({ error, args }, message);
|
|
85
|
+
}
|
|
86
|
+
child(bindings) {
|
|
87
|
+
return new _PinoLogger(this.logger.child(bindings));
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
function createLogger(config = {}) {
|
|
91
|
+
const {
|
|
92
|
+
level = "info",
|
|
93
|
+
enabled = true,
|
|
94
|
+
name = "@shopkit/analytics",
|
|
95
|
+
prettyPrint = false,
|
|
96
|
+
redact = []
|
|
97
|
+
} = config;
|
|
98
|
+
if (!enabled) {
|
|
99
|
+
return new NoOpLogger();
|
|
100
|
+
}
|
|
101
|
+
const pinoConfig = {
|
|
102
|
+
name,
|
|
103
|
+
level,
|
|
104
|
+
redact,
|
|
105
|
+
browser: {
|
|
106
|
+
asObject: true,
|
|
107
|
+
serialize: true,
|
|
108
|
+
write: {
|
|
109
|
+
trace: (o) => console.trace(formatBrowserLog(o)),
|
|
110
|
+
debug: (o) => console.debug(formatBrowserLog(o)),
|
|
111
|
+
info: (o) => console.info(formatBrowserLog(o)),
|
|
112
|
+
warn: (o) => console.warn(formatBrowserLog(o)),
|
|
113
|
+
error: (o) => console.error(formatBrowserLog(o)),
|
|
114
|
+
fatal: (o) => console.error(formatBrowserLog(o))
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
if (prettyPrint && typeof window === "undefined") {
|
|
119
|
+
pinoConfig.transport = {
|
|
120
|
+
target: "pino-pretty",
|
|
121
|
+
options: {
|
|
122
|
+
colorize: true,
|
|
123
|
+
translateTime: "HH:MM:ss Z",
|
|
124
|
+
ignore: "pid,hostname"
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const pinoLogger = (0, import_pino.default)(pinoConfig);
|
|
129
|
+
return new PinoLogger(pinoLogger);
|
|
130
|
+
}
|
|
131
|
+
function formatBrowserLog(logObj) {
|
|
132
|
+
const { level, time, msg, name, args, error, ...rest } = logObj;
|
|
133
|
+
let message = `[${name}] ${msg}`;
|
|
134
|
+
if (args && args.length > 0) {
|
|
135
|
+
message += ` ${args.map(
|
|
136
|
+
(arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)
|
|
137
|
+
).join(" ")}`;
|
|
138
|
+
}
|
|
139
|
+
if (error) {
|
|
140
|
+
message += ` Error: ${error.message}`;
|
|
141
|
+
if (error.stack) {
|
|
142
|
+
message += `
|
|
143
|
+
${error.stack}`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (Object.keys(rest).length > 0) {
|
|
147
|
+
message += ` ${JSON.stringify(rest)}`;
|
|
148
|
+
}
|
|
149
|
+
return message;
|
|
150
|
+
}
|
|
151
|
+
var logger = createLogger({
|
|
152
|
+
enabled: true,
|
|
153
|
+
level: "info",
|
|
154
|
+
prettyPrint: false
|
|
155
|
+
});
|
|
156
|
+
function createAdapterLogger(adapterName, config = {}) {
|
|
157
|
+
const baseLogger = createLogger(config);
|
|
158
|
+
return baseLogger.child({ adapter: adapterName });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/adapters/base-adapter.ts
|
|
162
|
+
var BaseAdapter = class {
|
|
163
|
+
/**
|
|
164
|
+
* Constructor
|
|
165
|
+
* @param config Configuration for the adapter
|
|
166
|
+
*/
|
|
167
|
+
constructor(config = {}) {
|
|
168
|
+
/**
|
|
169
|
+
* Whether the adapter has been initialized
|
|
170
|
+
*/
|
|
171
|
+
this.initialized = false;
|
|
172
|
+
this.config = config;
|
|
173
|
+
const loggerConfig = {
|
|
174
|
+
enabled: config.enableDebugLogs ?? true,
|
|
175
|
+
level: config.logLevel ?? "info",
|
|
176
|
+
name: "@shopkit/analytics"
|
|
177
|
+
};
|
|
178
|
+
this.logger = createAdapterLogger("BaseAdapter", loggerConfig);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Initialize logger with proper adapter name
|
|
182
|
+
* Should be called by subclasses after name is available
|
|
183
|
+
*/
|
|
184
|
+
initializeLogger() {
|
|
185
|
+
const loggerConfig = {
|
|
186
|
+
enabled: this.config.enableDebugLogs ?? true,
|
|
187
|
+
level: this.config.logLevel ?? "info",
|
|
188
|
+
name: "@shopkit/analytics"
|
|
189
|
+
};
|
|
190
|
+
this.logger = createAdapterLogger(this.name, loggerConfig);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Check if the adapter is enabled
|
|
194
|
+
*/
|
|
195
|
+
isEnabled() {
|
|
196
|
+
return this.initialized;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get a configuration value
|
|
200
|
+
* @param key The configuration key
|
|
201
|
+
* @param defaultValue The default value if the key is not found
|
|
202
|
+
*/
|
|
203
|
+
getConfig(key, defaultValue) {
|
|
204
|
+
return key in this.config ? this.config[key] : defaultValue;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get affiliate parameters from session storage or custom implementation
|
|
208
|
+
* Override this method to provide your own affiliate tracking implementation
|
|
209
|
+
* @returns Affiliate parameters or null if not available
|
|
210
|
+
*/
|
|
211
|
+
getAffiliateParams() {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Enhance event parameters with affiliate data
|
|
216
|
+
* @param params The original parameters
|
|
217
|
+
* @returns Parameters enhanced with affiliate data
|
|
218
|
+
*/
|
|
219
|
+
enhanceWithAffiliateParams(params) {
|
|
220
|
+
const affiliateParams = this.getAffiliateParams();
|
|
221
|
+
if (!affiliateParams) return params;
|
|
222
|
+
return {
|
|
223
|
+
...params,
|
|
224
|
+
// Add affiliate parameters
|
|
225
|
+
...affiliateParams
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// src/adapters/pixel-adapter.ts
|
|
231
|
+
var PixelAdapter = class extends BaseAdapter {
|
|
232
|
+
constructor(config) {
|
|
233
|
+
super(config);
|
|
234
|
+
this.name = "FacebookPixel";
|
|
235
|
+
this.initializeLogger();
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Initialize the Facebook Pixel
|
|
239
|
+
*/
|
|
240
|
+
async initialize() {
|
|
241
|
+
if (this.initialized) {
|
|
242
|
+
this.logger.debug("Already initialized");
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (typeof window === "undefined") {
|
|
246
|
+
this.logger.debug("Skipping initialization on server");
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (!window.fbq) {
|
|
250
|
+
this.logger.warn(
|
|
251
|
+
"Facebook Pixel fbq not found. Make sure the script is loaded."
|
|
252
|
+
);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const pixelId = this.getConfig("pixelId");
|
|
256
|
+
this.logger.info("Successfully initialized", { pixelId: "***" });
|
|
257
|
+
this.initialized = true;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Track an event with Facebook Pixel
|
|
261
|
+
* @param event The event to track
|
|
262
|
+
*/
|
|
263
|
+
async trackEvent(event) {
|
|
264
|
+
if (!this.initialized || typeof window === "undefined" || !window.fbq) {
|
|
265
|
+
this.logger.warn(
|
|
266
|
+
"Cannot track event, adapter not initialized or fbq not available",
|
|
267
|
+
{
|
|
268
|
+
eventType: event.type,
|
|
269
|
+
initialized: this.initialized,
|
|
270
|
+
hasWindow: typeof window !== "undefined",
|
|
271
|
+
hasFbq: !!window?.fbq
|
|
272
|
+
}
|
|
273
|
+
);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
this.logger.debug("Tracking event", { eventType: event.type });
|
|
277
|
+
switch (event.type) {
|
|
278
|
+
case "page_view" /* PAGE_VIEW */:
|
|
279
|
+
this.trackPageView(event);
|
|
280
|
+
break;
|
|
281
|
+
case "view_content" /* VIEW_CONTENT */:
|
|
282
|
+
this.trackViewContent(event);
|
|
283
|
+
break;
|
|
284
|
+
case "product_view" /* PRODUCT_VIEW */:
|
|
285
|
+
this.trackProductView(event);
|
|
286
|
+
break;
|
|
287
|
+
case "add_to_cart" /* ADD_TO_CART */:
|
|
288
|
+
this.trackAddToCart(event);
|
|
289
|
+
break;
|
|
290
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
291
|
+
this.trackCheckoutStarted(event);
|
|
292
|
+
break;
|
|
293
|
+
case "checkout_completed" /* CHECKOUT_COMPLETED */:
|
|
294
|
+
this.trackCheckoutCompleted(event);
|
|
295
|
+
break;
|
|
296
|
+
case "purchase" /* PURCHASE */:
|
|
297
|
+
this.trackPurchase(event);
|
|
298
|
+
break;
|
|
299
|
+
case "add_payment_info" /* ADD_PAYMENT_INFO */:
|
|
300
|
+
this.trackAddPaymentInfo(event);
|
|
301
|
+
break;
|
|
302
|
+
case "search" /* SEARCH */:
|
|
303
|
+
this.trackSearch(event);
|
|
304
|
+
break;
|
|
305
|
+
default:
|
|
306
|
+
this.logger.debug("Unhandled event type", { eventType: event.type });
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Track a page view event
|
|
312
|
+
* @param event The page view event
|
|
313
|
+
*/
|
|
314
|
+
trackPageView(event) {
|
|
315
|
+
const params = this.enhanceWithAffiliateParams({});
|
|
316
|
+
window.fbq?.("track", "PageView", params);
|
|
317
|
+
this.logger.debug("PageView event tracked", { params });
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Track a product view event
|
|
321
|
+
* @param event The product view event
|
|
322
|
+
*/
|
|
323
|
+
trackProductView(event) {
|
|
324
|
+
const params = {
|
|
325
|
+
content_type: "product_group",
|
|
326
|
+
content_ids: [event.productId],
|
|
327
|
+
content_name: event.productName,
|
|
328
|
+
content_category: event.category,
|
|
329
|
+
value: event.price,
|
|
330
|
+
currency: event.currency || "INR"
|
|
331
|
+
};
|
|
332
|
+
window.fbq?.(
|
|
333
|
+
"track",
|
|
334
|
+
"ViewContent",
|
|
335
|
+
this.enhanceWithAffiliateParams(params)
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Track an add to cart event
|
|
340
|
+
* @param event The add to cart event
|
|
341
|
+
*/
|
|
342
|
+
trackAddToCart(event) {
|
|
343
|
+
const params = {
|
|
344
|
+
content_type: "product_group",
|
|
345
|
+
content_ids: [event.productId],
|
|
346
|
+
content_name: event.productName,
|
|
347
|
+
value: event.price,
|
|
348
|
+
currency: event.currency || "INR"
|
|
349
|
+
};
|
|
350
|
+
const enhancedParams = this.enhanceWithAffiliateParams(params);
|
|
351
|
+
window.fbq?.("track", "AddToCart", enhancedParams);
|
|
352
|
+
this.logger.debug("AddToCart event tracked", { params: enhancedParams });
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Track a checkout started event
|
|
356
|
+
* @param event The checkout started event
|
|
357
|
+
*/
|
|
358
|
+
trackCheckoutStarted(event) {
|
|
359
|
+
const params = {
|
|
360
|
+
content_ids: event.items.map((item) => item.productId),
|
|
361
|
+
content_type: "product_group",
|
|
362
|
+
value: event.cartValue,
|
|
363
|
+
currency: event.currency || "INR",
|
|
364
|
+
num_items: event.itemCount,
|
|
365
|
+
contents: event.items.map((item) => ({
|
|
366
|
+
id: item.productId,
|
|
367
|
+
quantity: item.quantity,
|
|
368
|
+
item_price: item.price
|
|
369
|
+
}))
|
|
370
|
+
};
|
|
371
|
+
window.fbq?.(
|
|
372
|
+
"track",
|
|
373
|
+
"InitiateCheckout",
|
|
374
|
+
this.enhanceWithAffiliateParams(params)
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Track a checkout completed event
|
|
379
|
+
* @param event The checkout completed event
|
|
380
|
+
*/
|
|
381
|
+
trackCheckoutCompleted(event) {
|
|
382
|
+
const params = {
|
|
383
|
+
value: event.cartValue,
|
|
384
|
+
currency: event.currency || "INR",
|
|
385
|
+
content_type: "product_group",
|
|
386
|
+
content_ids: event.items.map((item) => item.productId),
|
|
387
|
+
num_items: event.itemCount,
|
|
388
|
+
contents: event.items.map((item) => ({
|
|
389
|
+
id: item.productId,
|
|
390
|
+
quantity: item.quantity,
|
|
391
|
+
item_price: item.price
|
|
392
|
+
}))
|
|
393
|
+
};
|
|
394
|
+
window.fbq?.("track", "Purchase", this.enhanceWithAffiliateParams(params));
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Track a search event
|
|
398
|
+
* @param event The search event
|
|
399
|
+
*/
|
|
400
|
+
trackSearch(event) {
|
|
401
|
+
const params = {
|
|
402
|
+
search_string: event.searchTerm,
|
|
403
|
+
content_category: "product",
|
|
404
|
+
content_ids: event.content_ids || []
|
|
405
|
+
};
|
|
406
|
+
window.fbq?.("track", "Search", this.enhanceWithAffiliateParams(params));
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Track an add payment info event
|
|
410
|
+
* @param event The add payment info event
|
|
411
|
+
*/
|
|
412
|
+
trackAddPaymentInfo(event) {
|
|
413
|
+
const params = {
|
|
414
|
+
value: event.cartValue,
|
|
415
|
+
currency: event.currency || "INR",
|
|
416
|
+
content_type: "product_group",
|
|
417
|
+
content_ids: event.items.map((item) => item.productId),
|
|
418
|
+
contents: event.items.map((item) => ({
|
|
419
|
+
id: item.productId,
|
|
420
|
+
quantity: item.quantity,
|
|
421
|
+
item_price: item.price
|
|
422
|
+
})),
|
|
423
|
+
payment_type: event.paymentType || ""
|
|
424
|
+
};
|
|
425
|
+
window.fbq?.(
|
|
426
|
+
"track",
|
|
427
|
+
"AddPaymentInfo",
|
|
428
|
+
this.enhanceWithAffiliateParams(params)
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Track a view content event
|
|
433
|
+
* @param event The view content event
|
|
434
|
+
*/
|
|
435
|
+
trackViewContent(event) {
|
|
436
|
+
const params = {
|
|
437
|
+
content_type: event.content_type || "product",
|
|
438
|
+
content_ids: event.content_ids || [],
|
|
439
|
+
content_name: event.content_name || "",
|
|
440
|
+
content_category: event.content_category || "",
|
|
441
|
+
value: event.value || 0,
|
|
442
|
+
currency: event.currency || "INR"
|
|
443
|
+
};
|
|
444
|
+
window.fbq?.(
|
|
445
|
+
"track",
|
|
446
|
+
"ViewContent",
|
|
447
|
+
this.enhanceWithAffiliateParams(params)
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Track a purchase event
|
|
452
|
+
* @param event The purchase event
|
|
453
|
+
*/
|
|
454
|
+
trackPurchase(event) {
|
|
455
|
+
const params = {
|
|
456
|
+
value: event.value,
|
|
457
|
+
currency: event.currency || "INR",
|
|
458
|
+
content_type: event.content_type || "product_group",
|
|
459
|
+
content_ids: event.content_ids || [],
|
|
460
|
+
num_items: event.num_items || 1,
|
|
461
|
+
contents: event.contents || []
|
|
462
|
+
};
|
|
463
|
+
window.fbq?.("track", "Purchase", this.enhanceWithAffiliateParams(params));
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Convert an event to Facebook Pixel parameters
|
|
467
|
+
* @param event The event to convert
|
|
468
|
+
*/
|
|
469
|
+
eventToParams(event) {
|
|
470
|
+
const { type, timestamp, ...params } = event;
|
|
471
|
+
return this.enhanceWithAffiliateParams(params);
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
// src/adapters/google-adapter.ts
|
|
476
|
+
var GoogleAdapter = class extends BaseAdapter {
|
|
477
|
+
constructor(config) {
|
|
478
|
+
super(config);
|
|
479
|
+
this.name = "GoogleAnalytics";
|
|
480
|
+
this.initializeLogger();
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Initialize Google Analytics adapter
|
|
484
|
+
* This just checks if gtag is available
|
|
485
|
+
*/
|
|
486
|
+
isEnabled() {
|
|
487
|
+
const enabled = this.initialized && typeof window !== "undefined" && !!window.gtag;
|
|
488
|
+
this.logger.debug("Checking if enabled", {
|
|
489
|
+
initialized: this.initialized,
|
|
490
|
+
hasWindow: typeof window !== "undefined",
|
|
491
|
+
hasGtag: !!window?.gtag,
|
|
492
|
+
enabled
|
|
493
|
+
});
|
|
494
|
+
return enabled;
|
|
495
|
+
}
|
|
496
|
+
async initialize() {
|
|
497
|
+
this.logger.info("Starting initialization");
|
|
498
|
+
if (this.initialized) {
|
|
499
|
+
this.logger.debug("Already initialized");
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (typeof window === "undefined") {
|
|
503
|
+
this.logger.debug("Skipping initialization on server");
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const measurementId = this.getConfig("measurementId");
|
|
507
|
+
this.logger.info("Using measurement ID", { measurementId });
|
|
508
|
+
if (!window.gtag) {
|
|
509
|
+
this.logger.warn(
|
|
510
|
+
"Google Analytics gtag not found. Make sure the script is loaded."
|
|
511
|
+
);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
this.initialized = true;
|
|
515
|
+
this.logger.info("Successfully initialized", { measurementId });
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Track an event with Google Analytics
|
|
519
|
+
* @param event The event to track
|
|
520
|
+
*/
|
|
521
|
+
async trackEvent(event) {
|
|
522
|
+
this.logger.debug("Attempting to track event", {
|
|
523
|
+
initialized: this.initialized,
|
|
524
|
+
hasWindow: typeof window !== "undefined",
|
|
525
|
+
hasGtag: !!window?.gtag,
|
|
526
|
+
eventType: event.type
|
|
527
|
+
});
|
|
528
|
+
if (!this.initialized || typeof window === "undefined" || !window.gtag) {
|
|
529
|
+
this.logger.warn(
|
|
530
|
+
"Cannot track event, adapter not initialized or gtag not available",
|
|
531
|
+
{
|
|
532
|
+
eventType: event.type,
|
|
533
|
+
initialized: this.initialized,
|
|
534
|
+
hasWindow: typeof window !== "undefined",
|
|
535
|
+
hasGtag: !!window?.gtag
|
|
536
|
+
}
|
|
537
|
+
);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
const measurementId = this.getConfig("measurementId");
|
|
541
|
+
this.logger.info("Tracking event", {
|
|
542
|
+
eventType: event.type,
|
|
543
|
+
measurementId
|
|
544
|
+
});
|
|
545
|
+
switch (event.type) {
|
|
546
|
+
case "page_view" /* PAGE_VIEW */:
|
|
547
|
+
this.trackPageView(event, measurementId);
|
|
548
|
+
break;
|
|
549
|
+
case "user_engagement" /* USER_ENGAGEMENT */:
|
|
550
|
+
this.trackUserEngagement();
|
|
551
|
+
break;
|
|
552
|
+
case "session_start" /* SESSION_START */:
|
|
553
|
+
this.trackSessionStart();
|
|
554
|
+
break;
|
|
555
|
+
case "first_visit" /* FIRST_VISIT */:
|
|
556
|
+
this.trackFirstVisit();
|
|
557
|
+
break;
|
|
558
|
+
case "view_item" /* VIEW_ITEM */:
|
|
559
|
+
this.trackViewItem(event);
|
|
560
|
+
break;
|
|
561
|
+
case "viewed_product" /* VIEWED_PRODUCT */:
|
|
562
|
+
this.trackViewedProduct(event);
|
|
563
|
+
break;
|
|
564
|
+
case "checkout_payment" /* CHECKOUT_PAYMENT */:
|
|
565
|
+
this.trackCheckoutPayment(event);
|
|
566
|
+
break;
|
|
567
|
+
case "scroll" /* SCROLL */:
|
|
568
|
+
this.trackScroll();
|
|
569
|
+
break;
|
|
570
|
+
case "add_to_cart" /* ADD_TO_CART */:
|
|
571
|
+
case "shopify_add_to_cart" /* SHOPIFY_ADD_TO_CART */:
|
|
572
|
+
this.trackAddToCart(event);
|
|
573
|
+
break;
|
|
574
|
+
case "form_start" /* FORM_START */:
|
|
575
|
+
this.trackFormStart();
|
|
576
|
+
break;
|
|
577
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
578
|
+
this.trackCheckoutStarted(event);
|
|
579
|
+
break;
|
|
580
|
+
case "form_submission" /* FORM_SUBMISSION */:
|
|
581
|
+
this.trackFormSubmission(event);
|
|
582
|
+
break;
|
|
583
|
+
case "search" /* SEARCH */:
|
|
584
|
+
this.trackSearch(event);
|
|
585
|
+
break;
|
|
586
|
+
case "checkout_completed" /* CHECKOUT_COMPLETED */:
|
|
587
|
+
this.trackCheckoutCompleted(event);
|
|
588
|
+
break;
|
|
589
|
+
case "add_payment_info" /* ADD_PAYMENT_INFO */:
|
|
590
|
+
this.trackAddPaymentInfo(event);
|
|
591
|
+
break;
|
|
592
|
+
case "view_content" /* VIEW_CONTENT */:
|
|
593
|
+
this.trackViewContent(event);
|
|
594
|
+
break;
|
|
595
|
+
case "purchase" /* PURCHASE */:
|
|
596
|
+
this.trackPurchase(event);
|
|
597
|
+
break;
|
|
598
|
+
case "view_search_results" /* VIEW_SEARCH_RESULTS */:
|
|
599
|
+
this.trackViewSearchResults(event);
|
|
600
|
+
break;
|
|
601
|
+
case "order_placed" /* ORDER_PLACED */:
|
|
602
|
+
this.trackOrderPlaced(event);
|
|
603
|
+
break;
|
|
604
|
+
case "begin_checkout" /* BEGIN_CHECKOUT */:
|
|
605
|
+
this.trackBeginCheckout(event);
|
|
606
|
+
break;
|
|
607
|
+
case "custom" /* CUSTOM */:
|
|
608
|
+
this.trackCustomEvent(event);
|
|
609
|
+
break;
|
|
610
|
+
default: {
|
|
611
|
+
const params = this.eventToParams(event);
|
|
612
|
+
window.gtag(
|
|
613
|
+
"event",
|
|
614
|
+
event.type,
|
|
615
|
+
this.enhanceWithAffiliateParams(params)
|
|
616
|
+
);
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Track a page view event
|
|
623
|
+
* @param event The page view event
|
|
624
|
+
* @param measurementId The Google Analytics measurement ID
|
|
625
|
+
*/
|
|
626
|
+
trackPageView(event, measurementId) {
|
|
627
|
+
const params = {
|
|
628
|
+
page_path: event.path,
|
|
629
|
+
page_title: event.title || document.title,
|
|
630
|
+
page_location: event.page_location || window.location.href,
|
|
631
|
+
page_referrer: event.page_referrer || document.referrer || void 0,
|
|
632
|
+
ga_session_id: event.ga_session_id || "",
|
|
633
|
+
ga_session_number: event.ga_session_number || "",
|
|
634
|
+
gclid: event.gclid || "",
|
|
635
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
636
|
+
campaign: event.campaign || "",
|
|
637
|
+
campaign_id: event.campaign_id || "",
|
|
638
|
+
content: event.content || "",
|
|
639
|
+
debug_mode: event.debug_mode,
|
|
640
|
+
medium: event.medium || "",
|
|
641
|
+
source: event.page_source || "",
|
|
642
|
+
page_term: event.page_term || "",
|
|
643
|
+
ignore_referrer: event.ignore_referrer,
|
|
644
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
645
|
+
batch_page_id: event.batch_page_id || "",
|
|
646
|
+
user_id: event.user_id,
|
|
647
|
+
user_properties: event.user_properties,
|
|
648
|
+
session_engaged: event.session_engaged
|
|
649
|
+
};
|
|
650
|
+
window.gtag?.(
|
|
651
|
+
"event",
|
|
652
|
+
"page_view",
|
|
653
|
+
this.enhanceWithAffiliateParams(params)
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
trackUserEngagement() {
|
|
657
|
+
const params = {
|
|
658
|
+
batch_ordering_id: "",
|
|
659
|
+
batch_page_id: "",
|
|
660
|
+
campaign: "",
|
|
661
|
+
ga_session_id: "",
|
|
662
|
+
ga_session_number: "",
|
|
663
|
+
gclid: "",
|
|
664
|
+
ignore_referrer: "",
|
|
665
|
+
medium: "",
|
|
666
|
+
page_location: window.location.href,
|
|
667
|
+
page_path: window.location.pathname,
|
|
668
|
+
page_referrer: document.referrer,
|
|
669
|
+
page_title: document.title,
|
|
670
|
+
source: "",
|
|
671
|
+
srsltid: "",
|
|
672
|
+
term: ""
|
|
673
|
+
};
|
|
674
|
+
window.gtag?.(
|
|
675
|
+
"event",
|
|
676
|
+
"user_engagement",
|
|
677
|
+
this.enhanceWithAffiliateParams(params)
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
trackSessionStart() {
|
|
681
|
+
const params = {
|
|
682
|
+
batch_ordering_id: "",
|
|
683
|
+
batch_page_id: "",
|
|
684
|
+
campaign: "",
|
|
685
|
+
campaign_id: "",
|
|
686
|
+
content: "",
|
|
687
|
+
ga_session_id: "",
|
|
688
|
+
ga_session_number: "",
|
|
689
|
+
gclid: "",
|
|
690
|
+
ignore_referrer: "",
|
|
691
|
+
medium: "",
|
|
692
|
+
page_location: window.location.href,
|
|
693
|
+
page_path: window.location.pathname,
|
|
694
|
+
page_referrer: document.referrer,
|
|
695
|
+
page_title: document.title,
|
|
696
|
+
source: "",
|
|
697
|
+
srsltid: "",
|
|
698
|
+
term: ""
|
|
699
|
+
};
|
|
700
|
+
window.gtag?.(
|
|
701
|
+
"event",
|
|
702
|
+
"session_start",
|
|
703
|
+
this.enhanceWithAffiliateParams(params)
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
trackFirstVisit() {
|
|
707
|
+
const params = {
|
|
708
|
+
batch_ordering_id: "",
|
|
709
|
+
batch_page_id: "",
|
|
710
|
+
campaign: "",
|
|
711
|
+
campaign_id: "",
|
|
712
|
+
content: "",
|
|
713
|
+
debug_mode: "",
|
|
714
|
+
engagement_time_msec: 0,
|
|
715
|
+
entrances: 1,
|
|
716
|
+
ga_session_id: "",
|
|
717
|
+
ga_session_number: "",
|
|
718
|
+
gclid: "",
|
|
719
|
+
ignore_referrer: "",
|
|
720
|
+
medium: "",
|
|
721
|
+
page_location: window.location.href,
|
|
722
|
+
page_path: window.location.pathname,
|
|
723
|
+
page_referrer: document.referrer,
|
|
724
|
+
page_title: document.title,
|
|
725
|
+
page_source: "",
|
|
726
|
+
page_term: ""
|
|
727
|
+
};
|
|
728
|
+
window.gtag?.(
|
|
729
|
+
"event",
|
|
730
|
+
"first_visit",
|
|
731
|
+
this.enhanceWithAffiliateParams(params)
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
trackViewItem(event) {
|
|
735
|
+
window.gtag?.(
|
|
736
|
+
"event",
|
|
737
|
+
"view_item",
|
|
738
|
+
this.enhanceWithAffiliateParams({
|
|
739
|
+
currency: event.currency,
|
|
740
|
+
value: event.value,
|
|
741
|
+
items: event.items
|
|
742
|
+
})
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
trackScroll() {
|
|
746
|
+
const params = {
|
|
747
|
+
batch_ordering_id: "",
|
|
748
|
+
batch_page_id: "",
|
|
749
|
+
engagement_time_msec: void 0,
|
|
750
|
+
ga_session_id: "",
|
|
751
|
+
ga_session_number: "",
|
|
752
|
+
ignore_referrer: void 0,
|
|
753
|
+
page_location: window.location.href,
|
|
754
|
+
page_path: window.location.pathname,
|
|
755
|
+
page_referrer: document.referrer,
|
|
756
|
+
page_title: document.title,
|
|
757
|
+
percent_scrolled: 90
|
|
758
|
+
// or dynamically captured
|
|
759
|
+
};
|
|
760
|
+
window.gtag?.("event", "scroll", this.enhanceWithAffiliateParams(params));
|
|
761
|
+
}
|
|
762
|
+
trackCheckoutPayment(event) {
|
|
763
|
+
window.gtag?.(
|
|
764
|
+
"event",
|
|
765
|
+
"checkout_payment",
|
|
766
|
+
this.enhanceWithAffiliateParams({
|
|
767
|
+
currency: event.currency,
|
|
768
|
+
value: event.cartValue,
|
|
769
|
+
items: event.items.map((item) => ({
|
|
770
|
+
item_id: item.productId,
|
|
771
|
+
item_name: item.productName,
|
|
772
|
+
price: item.price,
|
|
773
|
+
quantity: item.quantity
|
|
774
|
+
}))
|
|
775
|
+
})
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
trackViewedProduct(event) {
|
|
779
|
+
window.gtag?.(
|
|
780
|
+
"event",
|
|
781
|
+
"viewed_product",
|
|
782
|
+
this.enhanceWithAffiliateParams({
|
|
783
|
+
currency: event.currency,
|
|
784
|
+
value: event.price,
|
|
785
|
+
items: [
|
|
786
|
+
{
|
|
787
|
+
item_id: event.productId,
|
|
788
|
+
item_name: event.productName,
|
|
789
|
+
price: event.price,
|
|
790
|
+
currency: event.currency
|
|
791
|
+
}
|
|
792
|
+
],
|
|
793
|
+
view_duration: event.viewDuration
|
|
794
|
+
})
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
trackAddToCart(event) {
|
|
798
|
+
this.logger.debug("Processing add_to_cart event", { event });
|
|
799
|
+
const params = {
|
|
800
|
+
currency: event.currency || "INR",
|
|
801
|
+
value: event.price * (event.quantity || 1),
|
|
802
|
+
// Calculate total value
|
|
803
|
+
items: [
|
|
804
|
+
{
|
|
805
|
+
item_id: event.productId,
|
|
806
|
+
item_name: event.productName,
|
|
807
|
+
price: event.price,
|
|
808
|
+
quantity: event.quantity || 1,
|
|
809
|
+
item_variant: event.variant
|
|
810
|
+
}
|
|
811
|
+
],
|
|
812
|
+
// GA4-specific parameters
|
|
813
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
814
|
+
batch_page_id: event.batch_page_id || "",
|
|
815
|
+
campaign: event.campaign || "",
|
|
816
|
+
ga_session_id: event.ga_session_id || "",
|
|
817
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
818
|
+
session_engaged: event.session_engaged,
|
|
819
|
+
page_title: event.page_title || document.title,
|
|
820
|
+
page_location: event.page_location || window.location.href,
|
|
821
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
822
|
+
user_id: event.user_id,
|
|
823
|
+
user_properties: event.user_properties
|
|
824
|
+
};
|
|
825
|
+
const enhancedParams = this.enhanceWithAffiliateParams(params);
|
|
826
|
+
this.logger.debug("Sending add_to_cart event to gtag", {
|
|
827
|
+
params: enhancedParams
|
|
828
|
+
});
|
|
829
|
+
window.gtag?.("event", "add_to_cart", enhancedParams);
|
|
830
|
+
}
|
|
831
|
+
trackFormStart() {
|
|
832
|
+
const params = {
|
|
833
|
+
batch_ordering_id: "",
|
|
834
|
+
batch_page_id: "",
|
|
835
|
+
engagement_time_msec: void 0,
|
|
836
|
+
first_field_id: "",
|
|
837
|
+
first_field_name: "",
|
|
838
|
+
first_field_position: "",
|
|
839
|
+
first_field_type: "",
|
|
840
|
+
form_destination: "",
|
|
841
|
+
form_length: "",
|
|
842
|
+
form_id: "",
|
|
843
|
+
ga_session_id: "",
|
|
844
|
+
ga_session_number: "",
|
|
845
|
+
ignore_referrer: void 0,
|
|
846
|
+
page_location: window.location.href,
|
|
847
|
+
page_referrer: document.referrer,
|
|
848
|
+
page_title: document.title
|
|
849
|
+
};
|
|
850
|
+
window.gtag?.(
|
|
851
|
+
"event",
|
|
852
|
+
"form_start",
|
|
853
|
+
this.enhanceWithAffiliateParams(params)
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
trackCheckoutStarted(event) {
|
|
857
|
+
const params = {
|
|
858
|
+
batch_ordering_id: "",
|
|
859
|
+
batch_page_id: "",
|
|
860
|
+
currency: event.currency || "INR",
|
|
861
|
+
ecomm_pagetype: "",
|
|
862
|
+
ecomm_prodid: "",
|
|
863
|
+
ecomm_totalvalue: event.cartValue,
|
|
864
|
+
value: event.cartValue,
|
|
865
|
+
engagement_time_msec: void 0,
|
|
866
|
+
ga_session_id: "",
|
|
867
|
+
ga_session_number: "",
|
|
868
|
+
ignore_referrer: void 0,
|
|
869
|
+
page_location: window.location.href,
|
|
870
|
+
page_referrer: document.referrer,
|
|
871
|
+
page_title: document.title,
|
|
872
|
+
items: event.items.map((item) => ({
|
|
873
|
+
item_id: item.productId,
|
|
874
|
+
item_name: item.productName,
|
|
875
|
+
price: item.price,
|
|
876
|
+
quantity: item.quantity,
|
|
877
|
+
item_variant: item.variant
|
|
878
|
+
}))
|
|
879
|
+
};
|
|
880
|
+
window.gtag?.(
|
|
881
|
+
"event",
|
|
882
|
+
"begin_checkout",
|
|
883
|
+
this.enhanceWithAffiliateParams(params)
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
trackFormSubmission(event) {
|
|
887
|
+
const params = {
|
|
888
|
+
batch_ordering_id: "",
|
|
889
|
+
batch_page_id: "",
|
|
890
|
+
engagement_time_msec: void 0,
|
|
891
|
+
form_destination: "",
|
|
892
|
+
form_length: "",
|
|
893
|
+
form_id: event.formId,
|
|
894
|
+
ga_session_id: "",
|
|
895
|
+
ga_session_number: "",
|
|
896
|
+
ignore_referrer: void 0,
|
|
897
|
+
page_location: window.location.href,
|
|
898
|
+
page_referrer: document.referrer,
|
|
899
|
+
page_title: document.title
|
|
900
|
+
};
|
|
901
|
+
window.gtag?.(
|
|
902
|
+
"event",
|
|
903
|
+
"form_submit",
|
|
904
|
+
this.enhanceWithAffiliateParams(params)
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
trackSearch(event) {
|
|
908
|
+
const params = {
|
|
909
|
+
batch_ordering_id: "",
|
|
910
|
+
batch_page_id: "",
|
|
911
|
+
engagement_time_msec: void 0,
|
|
912
|
+
ga_session_id: "",
|
|
913
|
+
ga_session_number: "",
|
|
914
|
+
ignore_referrer: void 0,
|
|
915
|
+
page_location: window.location.href,
|
|
916
|
+
page_referrer: document.referrer,
|
|
917
|
+
page_title: document.title,
|
|
918
|
+
search_term: event.searchTerm
|
|
919
|
+
};
|
|
920
|
+
window.gtag?.("event", "search", this.enhanceWithAffiliateParams(params));
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Track a checkout completed event
|
|
924
|
+
* @param event The checkout completed event
|
|
925
|
+
*/
|
|
926
|
+
trackCheckoutCompleted(event) {
|
|
927
|
+
const params = {
|
|
928
|
+
transaction_id: event.orderId,
|
|
929
|
+
currency: event.currency || "INR",
|
|
930
|
+
value: event.cartValue,
|
|
931
|
+
items: event.items.map((item) => ({
|
|
932
|
+
item_id: item.productId,
|
|
933
|
+
item_name: item.productName,
|
|
934
|
+
price: item.price,
|
|
935
|
+
quantity: item.quantity,
|
|
936
|
+
item_variant: item.variant
|
|
937
|
+
}))
|
|
938
|
+
};
|
|
939
|
+
window.gtag?.("event", "purchase", this.enhanceWithAffiliateParams(params));
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* Track a custom event
|
|
943
|
+
* @param event The custom event
|
|
944
|
+
*/
|
|
945
|
+
trackCustomEvent(event) {
|
|
946
|
+
const params = event.properties || {};
|
|
947
|
+
window.gtag?.("event", event.name, this.enhanceWithAffiliateParams(params));
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Track an add payment info event
|
|
951
|
+
* @param event The add payment info event
|
|
952
|
+
*/
|
|
953
|
+
trackAddPaymentInfo(event) {
|
|
954
|
+
const params = {
|
|
955
|
+
currency: event.currency || "INR",
|
|
956
|
+
value: event.cartValue,
|
|
957
|
+
payment_type: event.paymentType || "",
|
|
958
|
+
items: event.items.map((item) => ({
|
|
959
|
+
item_id: item.productId,
|
|
960
|
+
item_name: item.productName,
|
|
961
|
+
price: item.price,
|
|
962
|
+
quantity: item.quantity,
|
|
963
|
+
item_variant: item.variant
|
|
964
|
+
}))
|
|
965
|
+
};
|
|
966
|
+
window.gtag?.(
|
|
967
|
+
"event",
|
|
968
|
+
"add_payment_info",
|
|
969
|
+
this.enhanceWithAffiliateParams(params)
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* Track a view content event
|
|
974
|
+
* @param event The view content event
|
|
975
|
+
*/
|
|
976
|
+
trackViewContent(event) {
|
|
977
|
+
const params = {
|
|
978
|
+
currency: event.currency || "USD",
|
|
979
|
+
value: event.value || 0,
|
|
980
|
+
items: event.items?.map((item) => ({
|
|
981
|
+
item_id: item.item_id,
|
|
982
|
+
item_name: item.item_name,
|
|
983
|
+
item_category: item.item_category,
|
|
984
|
+
item_category2: item.item_category2,
|
|
985
|
+
item_category3: item.item_category3,
|
|
986
|
+
item_category4: item.item_category4,
|
|
987
|
+
item_category5: item.item_category5,
|
|
988
|
+
item_brand: item.item_brand,
|
|
989
|
+
item_variant: item.item_variant,
|
|
990
|
+
price: item.price,
|
|
991
|
+
quantity: item.quantity
|
|
992
|
+
})) || [],
|
|
993
|
+
// GA4-specific parameters
|
|
994
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
995
|
+
batch_page_id: event.batch_page_id || "",
|
|
996
|
+
campaign: event.campaign || "",
|
|
997
|
+
ga_session_id: event.ga_session_id || "",
|
|
998
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
999
|
+
session_engaged: event.session_engaged,
|
|
1000
|
+
page_title: event.page_title || document.title,
|
|
1001
|
+
page_location: event.page_location || window.location.href,
|
|
1002
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
1003
|
+
user_id: event.user_id,
|
|
1004
|
+
user_properties: event.user_properties
|
|
1005
|
+
};
|
|
1006
|
+
window.gtag?.(
|
|
1007
|
+
"event",
|
|
1008
|
+
"view_item",
|
|
1009
|
+
this.enhanceWithAffiliateParams(params)
|
|
1010
|
+
);
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Track a purchase event
|
|
1014
|
+
* @param event The purchase event
|
|
1015
|
+
*/
|
|
1016
|
+
trackPurchase(event) {
|
|
1017
|
+
const params = {
|
|
1018
|
+
transaction_id: event.transaction_id,
|
|
1019
|
+
value: event.value,
|
|
1020
|
+
currency: event.currency || "USD",
|
|
1021
|
+
coupon: event.coupon,
|
|
1022
|
+
shipping: event.shipping,
|
|
1023
|
+
tax: event.tax,
|
|
1024
|
+
items: event.items?.map((item) => ({
|
|
1025
|
+
item_id: item.item_id,
|
|
1026
|
+
item_name: item.item_name,
|
|
1027
|
+
item_category: item.item_category,
|
|
1028
|
+
item_category2: item.item_category2,
|
|
1029
|
+
item_category3: item.item_category3,
|
|
1030
|
+
item_category4: item.item_category4,
|
|
1031
|
+
item_category5: item.item_category5,
|
|
1032
|
+
item_brand: item.item_brand,
|
|
1033
|
+
item_variant: item.item_variant,
|
|
1034
|
+
price: item.price,
|
|
1035
|
+
quantity: item.quantity
|
|
1036
|
+
})) || [],
|
|
1037
|
+
// GA4-specific parameters
|
|
1038
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
1039
|
+
batch_page_id: event.batch_page_id || "",
|
|
1040
|
+
campaign: event.campaign || "",
|
|
1041
|
+
ga_session_id: event.ga_session_id || "",
|
|
1042
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
1043
|
+
session_engaged: event.session_engaged,
|
|
1044
|
+
page_title: event.page_title || document.title,
|
|
1045
|
+
page_location: event.page_location || window.location.href,
|
|
1046
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
1047
|
+
user_id: event.user_id,
|
|
1048
|
+
user_properties: event.user_properties
|
|
1049
|
+
};
|
|
1050
|
+
window.gtag?.("event", "purchase", this.enhanceWithAffiliateParams(params));
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Track a view search results event
|
|
1054
|
+
* @param event The view search results event
|
|
1055
|
+
*/
|
|
1056
|
+
trackViewSearchResults(event) {
|
|
1057
|
+
const params = {
|
|
1058
|
+
search_term: event.search_term,
|
|
1059
|
+
// GA4-specific parameters
|
|
1060
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
1061
|
+
batch_page_id: event.batch_page_id || "",
|
|
1062
|
+
campaign: event.campaign || "",
|
|
1063
|
+
ga_session_id: event.ga_session_id || "",
|
|
1064
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
1065
|
+
session_engaged: event.session_engaged,
|
|
1066
|
+
page_title: event.page_title || document.title,
|
|
1067
|
+
page_location: event.page_location || window.location.href,
|
|
1068
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
1069
|
+
user_id: event.user_id,
|
|
1070
|
+
user_properties: event.user_properties
|
|
1071
|
+
};
|
|
1072
|
+
window.gtag?.(
|
|
1073
|
+
"event",
|
|
1074
|
+
"view_search_results",
|
|
1075
|
+
this.enhanceWithAffiliateParams(params)
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Track an order placed event
|
|
1080
|
+
* @param event The order placed event
|
|
1081
|
+
*/
|
|
1082
|
+
trackOrderPlaced(event) {
|
|
1083
|
+
const params = {
|
|
1084
|
+
transaction_id: event.order_id,
|
|
1085
|
+
value: event.total_amount,
|
|
1086
|
+
currency: event.currency || "USD",
|
|
1087
|
+
items: event.items?.map((item) => ({
|
|
1088
|
+
item_id: item.product_id,
|
|
1089
|
+
item_name: item.product_name,
|
|
1090
|
+
item_category: item.category,
|
|
1091
|
+
item_brand: item.brand,
|
|
1092
|
+
item_variant: item.variant,
|
|
1093
|
+
price: item.price,
|
|
1094
|
+
quantity: item.quantity
|
|
1095
|
+
})) || [],
|
|
1096
|
+
// GA4-specific parameters
|
|
1097
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
1098
|
+
batch_page_id: event.batch_page_id || "",
|
|
1099
|
+
campaign: event.campaign || "",
|
|
1100
|
+
ga_session_id: event.ga_session_id || "",
|
|
1101
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
1102
|
+
session_engaged: event.session_engaged,
|
|
1103
|
+
page_title: event.page_title || document.title,
|
|
1104
|
+
page_location: event.page_location || window.location.href,
|
|
1105
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
1106
|
+
user_id: event.user_id,
|
|
1107
|
+
user_properties: event.user_properties
|
|
1108
|
+
};
|
|
1109
|
+
window.gtag?.("event", "purchase", this.enhanceWithAffiliateParams(params));
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Track a begin checkout event
|
|
1113
|
+
* @param event The begin checkout event
|
|
1114
|
+
*/
|
|
1115
|
+
trackBeginCheckout(event) {
|
|
1116
|
+
const params = {
|
|
1117
|
+
currency: event.currency || "USD",
|
|
1118
|
+
value: event.value || 0,
|
|
1119
|
+
coupon: event.coupon,
|
|
1120
|
+
items: event.items?.map((item) => ({
|
|
1121
|
+
item_id: item.item_id,
|
|
1122
|
+
item_name: item.item_name,
|
|
1123
|
+
item_category: item.item_category,
|
|
1124
|
+
item_category2: item.item_category2,
|
|
1125
|
+
item_category3: item.item_category3,
|
|
1126
|
+
item_category4: item.item_category4,
|
|
1127
|
+
item_category5: item.item_category5,
|
|
1128
|
+
item_brand: item.item_brand,
|
|
1129
|
+
item_variant: item.item_variant,
|
|
1130
|
+
price: item.price,
|
|
1131
|
+
quantity: item.quantity
|
|
1132
|
+
})) || [],
|
|
1133
|
+
// GA4-specific parameters
|
|
1134
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
1135
|
+
batch_page_id: event.batch_page_id || "",
|
|
1136
|
+
campaign: event.campaign || "",
|
|
1137
|
+
ga_session_id: event.ga_session_id || "",
|
|
1138
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
1139
|
+
session_engaged: event.session_engaged,
|
|
1140
|
+
page_title: event.page_title || document.title,
|
|
1141
|
+
page_location: event.page_location || window.location.href,
|
|
1142
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
1143
|
+
user_id: event.user_id,
|
|
1144
|
+
user_properties: event.user_properties
|
|
1145
|
+
};
|
|
1146
|
+
window.gtag?.(
|
|
1147
|
+
"event",
|
|
1148
|
+
"begin_checkout",
|
|
1149
|
+
this.enhanceWithAffiliateParams(params)
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Convert an event to Google Analytics parameters
|
|
1154
|
+
* @param event The event to convert
|
|
1155
|
+
*/
|
|
1156
|
+
eventToParams(event) {
|
|
1157
|
+
const { type, timestamp, ...params } = event;
|
|
1158
|
+
return this.enhanceWithAffiliateParams(params);
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1162
|
+
// src/constants.ts
|
|
1163
|
+
var EventNames = {
|
|
1164
|
+
// Page events
|
|
1165
|
+
PAGE_VIEWED: "Page Viewed",
|
|
1166
|
+
// Interaction events
|
|
1167
|
+
BUTTON_CLICKED: "Button Clicked",
|
|
1168
|
+
FORM_SUBMITTED: "Form Submitted",
|
|
1169
|
+
// Product events
|
|
1170
|
+
PRODUCT_VIEWED: "Product Viewed",
|
|
1171
|
+
ADDED_TO_CART: "Added To Cart",
|
|
1172
|
+
REMOVED_FROM_CART: "Removed From Cart",
|
|
1173
|
+
// Checkout events
|
|
1174
|
+
CHECKOUT_STARTED: "Checkout Started",
|
|
1175
|
+
PURCHASE_COMPLETED: "Purchase Completed",
|
|
1176
|
+
// Search events
|
|
1177
|
+
SEARCH: "Search",
|
|
1178
|
+
// User events
|
|
1179
|
+
USER_SIGNED_UP: "User Signed Up",
|
|
1180
|
+
USER_LOGGED_IN: "User Logged In",
|
|
1181
|
+
// MoEngage events
|
|
1182
|
+
ITEM_PURCHASED: "Item Purchased",
|
|
1183
|
+
UPDATE_CART: "Update Cart",
|
|
1184
|
+
CUSTOMER_REGISTERED: "Customer Registered",
|
|
1185
|
+
CUSTOMER_LOGGED_IN: "Customer Logged In",
|
|
1186
|
+
SHOPIFY_CHECKOUT_UPDATED: "Shopify - Checkout Updated",
|
|
1187
|
+
SHOPIFY_ABANDONED_CHECKOUT: "Shopify - Abandoned Checkout",
|
|
1188
|
+
SHOPIFY_ORDER_FULFILLED: "Shopify - Order Fulfilled",
|
|
1189
|
+
SHOPIFY_CHECKOUT_STARTED: "Shopify - Checkout Started",
|
|
1190
|
+
SHOPIFY_ADD_TO_CART: "Shopify - Add To Cart",
|
|
1191
|
+
SHOPIFY_REMOVED_FROM_CART: "Shopify - Removed From Cart",
|
|
1192
|
+
SHOPIFY_UPDATE_CART: "Shopify - Update Cart",
|
|
1193
|
+
SPINFORM_RESULT: "Spinform Result",
|
|
1194
|
+
COUPON_COPIED: "Coupon Copied",
|
|
1195
|
+
STARTED_CHECKOUT_GK: "Started Checkout GK",
|
|
1196
|
+
MOBILE_ADDED_GK: "Mobile Added GK",
|
|
1197
|
+
ADDRESS_SELECTED_GK: "Address Selected GK",
|
|
1198
|
+
ADDRESS_COMPLETED_GK: "Address Completed GK",
|
|
1199
|
+
PAYMENT_METHOD_SELECTED_GK: "Payment Method Selected GK",
|
|
1200
|
+
PAYMENT_COMPLETED_GK: "Payment Completed GK",
|
|
1201
|
+
ORDER_SUCCESS: "Order Success",
|
|
1202
|
+
ORDER_COMPLETED: "Order Completed",
|
|
1203
|
+
PIN_CODE_ADDED_GK: "PIN Code Added GK",
|
|
1204
|
+
ADDRESS_ADDED_GK: "Address Added GK",
|
|
1205
|
+
KP_MP_PHONE_NUMBER_LOGGED_IN: "KP MP Phone Number Logged In",
|
|
1206
|
+
KP_PHONE_NUMBER_LOGGED_IN: "KP Phone Number Logged In",
|
|
1207
|
+
KP_MP_SHOPIFY_LOGGED_IN: "KP MP Shopify Logged In",
|
|
1208
|
+
KP_MP_SUCCESSFULLY_LOGGED_OUT: "KP MP Successfully Logged Out",
|
|
1209
|
+
KP_WHATSAPP_LOGGED_IN: "KP Whatsapp Logged In",
|
|
1210
|
+
KP_MP_TRUECALLER_LOGGED_IN: "KP MP Truecaller Logged In",
|
|
1211
|
+
KP_MP_WHATSAPP_LOGGED_IN: "KP MP Whatsapp Logged In",
|
|
1212
|
+
KP_TRUECALLER_LOGGED_IN: "KP Truecaller Logged In",
|
|
1213
|
+
KP_SHOPIFY_LOGGED_IN: "KP Shopify Logged In",
|
|
1214
|
+
KP_SUCCESSFULLY_LOGGED_OUT: "KP Successfully Logged Out"
|
|
1215
|
+
};
|
|
1216
|
+
var DEFAULT_CURRENCY = "INR";
|
|
1217
|
+
|
|
1218
|
+
// src/adapters/moengage-adapter.ts
|
|
1219
|
+
var import_web_sdk = __toESM(require("@moengage/web-sdk"));
|
|
1220
|
+
var MoengageAdapter = class extends BaseAdapter {
|
|
1221
|
+
constructor(config) {
|
|
1222
|
+
super(config);
|
|
1223
|
+
this.name = "MoEngage";
|
|
1224
|
+
this.sdk = null;
|
|
1225
|
+
this.initializeLogger();
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Initialize the MoenGage adapter using the Web SDK
|
|
1229
|
+
*/
|
|
1230
|
+
async initialize() {
|
|
1231
|
+
if (this.initialized) {
|
|
1232
|
+
this.logger.debug("Already initialized");
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
if (typeof window === "undefined") {
|
|
1236
|
+
this.logger.debug("Skipping initialization on server");
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
try {
|
|
1240
|
+
const appId = this.getConfig("appId");
|
|
1241
|
+
if (!appId) {
|
|
1242
|
+
this.logger.warn("App ID is required for initialization");
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
const region = this.getConfig("region", "dc_01");
|
|
1246
|
+
const config = {
|
|
1247
|
+
app_id: appId,
|
|
1248
|
+
debug_logs: this.getConfig("debug", false) ? 1 : 0,
|
|
1249
|
+
cluster: region
|
|
1250
|
+
};
|
|
1251
|
+
this.logger.info("Initializing with config", {
|
|
1252
|
+
region,
|
|
1253
|
+
debug: this.getConfig("debug", false),
|
|
1254
|
+
appId: "***"
|
|
1255
|
+
// Hide sensitive data
|
|
1256
|
+
});
|
|
1257
|
+
import_web_sdk.default.initialize(config);
|
|
1258
|
+
this.sdk = window.Moengage;
|
|
1259
|
+
this.logger.info("Successfully initialized with SDK");
|
|
1260
|
+
this.initialized = true;
|
|
1261
|
+
} catch (error) {
|
|
1262
|
+
this.logger.error("Failed to initialize", error);
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Track an event with MoenGage SDK
|
|
1267
|
+
* @param event The event to track
|
|
1268
|
+
*/
|
|
1269
|
+
async trackEvent(event) {
|
|
1270
|
+
if (!this.initialized || typeof window === "undefined" || !this.sdk) {
|
|
1271
|
+
this.logger.warn(
|
|
1272
|
+
"Cannot track event, adapter not initialized or SDK not available",
|
|
1273
|
+
{
|
|
1274
|
+
eventType: event.type,
|
|
1275
|
+
initialized: this.initialized,
|
|
1276
|
+
hasWindow: typeof window !== "undefined",
|
|
1277
|
+
hasSdk: !!this.sdk
|
|
1278
|
+
}
|
|
1279
|
+
);
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
this.logger.debug("Tracking event", { eventType: event.type });
|
|
1283
|
+
switch (event.type) {
|
|
1284
|
+
case "page_view" /* PAGE_VIEW */:
|
|
1285
|
+
this.trackPageView(event);
|
|
1286
|
+
break;
|
|
1287
|
+
case "button_click" /* BUTTON_CLICK */:
|
|
1288
|
+
this.trackButtonClick(event);
|
|
1289
|
+
break;
|
|
1290
|
+
case "form_submission" /* FORM_SUBMISSION */:
|
|
1291
|
+
this.trackFormSubmission(event);
|
|
1292
|
+
break;
|
|
1293
|
+
case "product_view" /* PRODUCT_VIEW */:
|
|
1294
|
+
this.trackProductView(event);
|
|
1295
|
+
break;
|
|
1296
|
+
case "add_to_cart" /* ADD_TO_CART */:
|
|
1297
|
+
this.trackAddToCart(event);
|
|
1298
|
+
break;
|
|
1299
|
+
case "remove_from_cart" /* REMOVE_FROM_CART */:
|
|
1300
|
+
this.trackRemoveFromCart(event);
|
|
1301
|
+
break;
|
|
1302
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
1303
|
+
this.trackCheckoutStarted(event);
|
|
1304
|
+
break;
|
|
1305
|
+
case "checkout_completed" /* CHECKOUT_COMPLETED */:
|
|
1306
|
+
this.trackCheckoutCompleted(event);
|
|
1307
|
+
break;
|
|
1308
|
+
case "search" /* SEARCH */:
|
|
1309
|
+
this.trackSearch(event);
|
|
1310
|
+
break;
|
|
1311
|
+
case "user_signup" /* USER_SIGNUP */:
|
|
1312
|
+
this.trackUserSignup(event);
|
|
1313
|
+
break;
|
|
1314
|
+
case "user_login" /* USER_LOGIN */:
|
|
1315
|
+
this.trackUserLogin(event);
|
|
1316
|
+
break;
|
|
1317
|
+
case "custom" /* CUSTOM */:
|
|
1318
|
+
this.trackCustomEvent(event);
|
|
1319
|
+
break;
|
|
1320
|
+
default:
|
|
1321
|
+
this.sdk.track_event(event.type, this.eventToParams(event));
|
|
1322
|
+
break;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Track a page view event
|
|
1327
|
+
* @param event The page view event
|
|
1328
|
+
*/
|
|
1329
|
+
trackPageView(event) {
|
|
1330
|
+
if (!this.sdk?.track_event) {
|
|
1331
|
+
this.logger.warn("track_event not available for PageView event");
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
const eventData = {
|
|
1335
|
+
page_path: event.path,
|
|
1336
|
+
page_title: event.title,
|
|
1337
|
+
page_url: window.location.href,
|
|
1338
|
+
referrer: event.referrer || document.referrer
|
|
1339
|
+
};
|
|
1340
|
+
this.sdk.track_event(EventNames.PAGE_VIEWED, eventData);
|
|
1341
|
+
this.logger.debug("PageView event tracked", { eventData });
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Track a button click event
|
|
1345
|
+
* @param event The button click event
|
|
1346
|
+
*/
|
|
1347
|
+
trackButtonClick(event) {
|
|
1348
|
+
this.sdk?.track_event(EventNames.BUTTON_CLICKED, {
|
|
1349
|
+
button_id: event.buttonId,
|
|
1350
|
+
button_text: event.buttonText,
|
|
1351
|
+
location: event.location
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Track a form submission event
|
|
1356
|
+
* @param event The form submission event
|
|
1357
|
+
*/
|
|
1358
|
+
trackFormSubmission(event) {
|
|
1359
|
+
this.sdk?.track_event(EventNames.FORM_SUBMITTED, {
|
|
1360
|
+
form_id: event.formId,
|
|
1361
|
+
form_name: event.formName,
|
|
1362
|
+
success: event.success
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Track a product view event
|
|
1367
|
+
* @param event The product view event
|
|
1368
|
+
*/
|
|
1369
|
+
trackProductView(event) {
|
|
1370
|
+
this.sdk?.track_event(EventNames.PRODUCT_VIEWED, {
|
|
1371
|
+
product_id: event.productId,
|
|
1372
|
+
product_name: event.productName,
|
|
1373
|
+
price: event.price,
|
|
1374
|
+
currency: event.currency || DEFAULT_CURRENCY,
|
|
1375
|
+
category: event.category
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
/**
|
|
1379
|
+
* Track an add to cart event
|
|
1380
|
+
* @param event The add to cart event
|
|
1381
|
+
*/
|
|
1382
|
+
trackAddToCart(event) {
|
|
1383
|
+
const quantity = event.quantity ?? 1;
|
|
1384
|
+
this.sdk?.track_event(EventNames.ADDED_TO_CART, {
|
|
1385
|
+
product_id: event.productId,
|
|
1386
|
+
product_name: event.productName,
|
|
1387
|
+
price: event.price,
|
|
1388
|
+
currency: event.currency || DEFAULT_CURRENCY,
|
|
1389
|
+
quantity,
|
|
1390
|
+
variant: event.variant,
|
|
1391
|
+
total_value: event.price * quantity
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Track a remove from cart event
|
|
1396
|
+
* @param event The remove from cart event
|
|
1397
|
+
*/
|
|
1398
|
+
trackRemoveFromCart(event) {
|
|
1399
|
+
this.sdk?.track_event(EventNames.REMOVED_FROM_CART, {
|
|
1400
|
+
product_id: event.productId,
|
|
1401
|
+
product_name: event.productName,
|
|
1402
|
+
price: event.price,
|
|
1403
|
+
currency: event.currency || DEFAULT_CURRENCY,
|
|
1404
|
+
quantity: event.quantity,
|
|
1405
|
+
variant: event.variant,
|
|
1406
|
+
total_value: event.price * event.quantity
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Track a checkout started event
|
|
1411
|
+
* @param event The checkout started event
|
|
1412
|
+
*/
|
|
1413
|
+
trackCheckoutStarted(event) {
|
|
1414
|
+
this.sdk?.track_event(EventNames.CHECKOUT_STARTED, {
|
|
1415
|
+
cart_value: event.cartValue,
|
|
1416
|
+
currency: event.currency || DEFAULT_CURRENCY,
|
|
1417
|
+
item_count: event.itemCount,
|
|
1418
|
+
items: event.items.map((item) => ({
|
|
1419
|
+
product_id: item.productId,
|
|
1420
|
+
product_name: item.productName,
|
|
1421
|
+
price: item.price,
|
|
1422
|
+
quantity: item.quantity,
|
|
1423
|
+
variant: item.variant
|
|
1424
|
+
}))
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Track a checkout completed event
|
|
1429
|
+
* @param event The checkout completed event
|
|
1430
|
+
*/
|
|
1431
|
+
trackCheckoutCompleted(event) {
|
|
1432
|
+
this.sdk?.track_event(EventNames.PURCHASE_COMPLETED, {
|
|
1433
|
+
order_id: event.orderId,
|
|
1434
|
+
cart_value: event.cartValue,
|
|
1435
|
+
currency: event.currency || DEFAULT_CURRENCY,
|
|
1436
|
+
item_count: event.itemCount,
|
|
1437
|
+
items: event.items.map((item) => ({
|
|
1438
|
+
product_id: item.productId,
|
|
1439
|
+
product_name: item.productName,
|
|
1440
|
+
price: item.price,
|
|
1441
|
+
quantity: item.quantity,
|
|
1442
|
+
variant: item.variant
|
|
1443
|
+
}))
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Track a search event
|
|
1448
|
+
* @param event The search event
|
|
1449
|
+
*/
|
|
1450
|
+
trackSearch(event) {
|
|
1451
|
+
this.sdk?.track_event(EventNames.SEARCH, {
|
|
1452
|
+
search_term: event.searchTerm,
|
|
1453
|
+
results_count: event.resultsCount
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
/**
|
|
1457
|
+
* Track a user signup event
|
|
1458
|
+
* @param event The user signup event
|
|
1459
|
+
*/
|
|
1460
|
+
trackUserSignup(event) {
|
|
1461
|
+
this.sdk?.track_event(EventNames.USER_SIGNED_UP, {
|
|
1462
|
+
user_id: event.userId,
|
|
1463
|
+
method: event.method,
|
|
1464
|
+
success: event.success
|
|
1465
|
+
});
|
|
1466
|
+
if (event.userId && this.getConfig("enableUserIdentification", true)) {
|
|
1467
|
+
this.sdk?.add_unique_user_id(event.userId);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Track a user login event
|
|
1472
|
+
* @param event The user login event
|
|
1473
|
+
*/
|
|
1474
|
+
trackUserLogin(event) {
|
|
1475
|
+
this.sdk?.track_event(EventNames.USER_LOGGED_IN, {
|
|
1476
|
+
user_id: event.userId,
|
|
1477
|
+
method: event.method,
|
|
1478
|
+
success: event.success
|
|
1479
|
+
});
|
|
1480
|
+
if (event.userId && this.getConfig("enableUserIdentification", true)) {
|
|
1481
|
+
this.sdk?.add_unique_user_id(event.userId);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Track a custom event
|
|
1486
|
+
* @param event The custom event
|
|
1487
|
+
*/
|
|
1488
|
+
trackCustomEvent(event) {
|
|
1489
|
+
this.sdk?.track_event(event.name, event.properties);
|
|
1490
|
+
}
|
|
1491
|
+
/**
|
|
1492
|
+
* Convert an event to MoenGage parameters
|
|
1493
|
+
* @param event The event to convert
|
|
1494
|
+
*/
|
|
1495
|
+
eventToParams(event) {
|
|
1496
|
+
const { type, timestamp, ...params } = event;
|
|
1497
|
+
return params;
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Set user attributes in MoenGage
|
|
1501
|
+
* @param attributes User attributes to set
|
|
1502
|
+
*/
|
|
1503
|
+
setUserAttributes(attributes) {
|
|
1504
|
+
if (!this.initialized || typeof window === "undefined" || !this.sdk) {
|
|
1505
|
+
this.logger.warn("Cannot set user attributes, adapter not initialized");
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
this.logger.debug("Setting user attributes", {
|
|
1509
|
+
attributeKeys: Object.keys(attributes)
|
|
1510
|
+
});
|
|
1511
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
1512
|
+
switch (key) {
|
|
1513
|
+
case "firstName":
|
|
1514
|
+
this.sdk?.add_first_name(value);
|
|
1515
|
+
break;
|
|
1516
|
+
case "lastName":
|
|
1517
|
+
this.sdk?.add_last_name(value);
|
|
1518
|
+
break;
|
|
1519
|
+
case "email":
|
|
1520
|
+
this.sdk?.add_email(value);
|
|
1521
|
+
break;
|
|
1522
|
+
case "mobile":
|
|
1523
|
+
this.sdk?.add_mobile(value);
|
|
1524
|
+
break;
|
|
1525
|
+
case "username":
|
|
1526
|
+
this.sdk?.add_user_name(value);
|
|
1527
|
+
break;
|
|
1528
|
+
case "gender":
|
|
1529
|
+
this.sdk?.add_gender(value);
|
|
1530
|
+
break;
|
|
1531
|
+
case "birthday":
|
|
1532
|
+
this.sdk?.add_birthday(value);
|
|
1533
|
+
break;
|
|
1534
|
+
case "userId":
|
|
1535
|
+
this.sdk?.add_unique_user_id(value);
|
|
1536
|
+
break;
|
|
1537
|
+
default:
|
|
1538
|
+
this.sdk?.add_user_attribute(key, value);
|
|
1539
|
+
break;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
|
|
1545
|
+
// src/adapters/posthog-adapter.ts
|
|
1546
|
+
var PostHogAdapter = class extends BaseAdapter {
|
|
1547
|
+
constructor(config = {}) {
|
|
1548
|
+
super(config);
|
|
1549
|
+
this.name = "PostHog";
|
|
1550
|
+
this.initializeLogger();
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Initialize PostHog
|
|
1554
|
+
*/
|
|
1555
|
+
async initialize() {
|
|
1556
|
+
if (this.initialized) {
|
|
1557
|
+
this.logger.debug("Already initialized");
|
|
1558
|
+
return;
|
|
1559
|
+
}
|
|
1560
|
+
if (typeof window === "undefined") {
|
|
1561
|
+
this.logger.debug("Skipping initialization on server");
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1564
|
+
if (!window.posthog) {
|
|
1565
|
+
this.logger.warn(
|
|
1566
|
+
"PostHog object not found. Make sure the script is loaded."
|
|
1567
|
+
);
|
|
1568
|
+
return;
|
|
1569
|
+
}
|
|
1570
|
+
this.logger.info("Successfully initialized");
|
|
1571
|
+
this.initialized = true;
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Track an event with PostHog
|
|
1575
|
+
* @param event The event to track
|
|
1576
|
+
*/
|
|
1577
|
+
async trackEvent(event) {
|
|
1578
|
+
if (!this.initialized || typeof window === "undefined" || !window.posthog) {
|
|
1579
|
+
this.logger.warn(
|
|
1580
|
+
"Cannot track event, adapter not initialized or posthog not available",
|
|
1581
|
+
{
|
|
1582
|
+
eventType: event.type,
|
|
1583
|
+
initialized: this.initialized,
|
|
1584
|
+
hasWindow: typeof window !== "undefined",
|
|
1585
|
+
hasPosthog: !!window?.posthog
|
|
1586
|
+
}
|
|
1587
|
+
);
|
|
1588
|
+
return;
|
|
1589
|
+
}
|
|
1590
|
+
this.logger.debug("Tracking event", { eventType: event.type });
|
|
1591
|
+
switch (event.type) {
|
|
1592
|
+
case "page_view" /* PAGE_VIEW */:
|
|
1593
|
+
this.trackPageView(event);
|
|
1594
|
+
break;
|
|
1595
|
+
case "product_view" /* PRODUCT_VIEW */:
|
|
1596
|
+
this.trackProductView(event);
|
|
1597
|
+
break;
|
|
1598
|
+
case "add_to_cart" /* ADD_TO_CART */:
|
|
1599
|
+
this.trackAddToCart(event);
|
|
1600
|
+
break;
|
|
1601
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
1602
|
+
this.trackCheckoutStarted(event);
|
|
1603
|
+
break;
|
|
1604
|
+
case "checkout_completed" /* CHECKOUT_COMPLETED */:
|
|
1605
|
+
this.trackCheckoutCompleted(event);
|
|
1606
|
+
break;
|
|
1607
|
+
case "add_payment_info" /* ADD_PAYMENT_INFO */:
|
|
1608
|
+
this.trackAddPaymentInfo(event);
|
|
1609
|
+
break;
|
|
1610
|
+
case "search" /* SEARCH */:
|
|
1611
|
+
this.trackSearch(event);
|
|
1612
|
+
break;
|
|
1613
|
+
default:
|
|
1614
|
+
const params = this.eventToParams(event);
|
|
1615
|
+
window.posthog?.capture(
|
|
1616
|
+
event.type,
|
|
1617
|
+
this.enhanceWithAffiliateParams(params)
|
|
1618
|
+
);
|
|
1619
|
+
break;
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Track a page view event
|
|
1624
|
+
* @param event The page view event
|
|
1625
|
+
*/
|
|
1626
|
+
trackPageView(event) {
|
|
1627
|
+
const params = {
|
|
1628
|
+
path: event.path,
|
|
1629
|
+
title: event.title,
|
|
1630
|
+
referrer: event.referrer
|
|
1631
|
+
};
|
|
1632
|
+
window.posthog?.capture(
|
|
1633
|
+
"$pageview",
|
|
1634
|
+
this.enhanceWithAffiliateParams(params)
|
|
1635
|
+
);
|
|
1636
|
+
}
|
|
1637
|
+
/**
|
|
1638
|
+
* Track a product view event
|
|
1639
|
+
* @param event The product view event
|
|
1640
|
+
*/
|
|
1641
|
+
trackProductView(event) {
|
|
1642
|
+
const params = {
|
|
1643
|
+
product_id: event.productId,
|
|
1644
|
+
product_name: event.productName,
|
|
1645
|
+
category: event.category,
|
|
1646
|
+
price: event.price,
|
|
1647
|
+
currency: event.currency || "INR"
|
|
1648
|
+
};
|
|
1649
|
+
window.posthog?.capture(
|
|
1650
|
+
"product_viewed",
|
|
1651
|
+
this.enhanceWithAffiliateParams(params)
|
|
1652
|
+
);
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Track an add to cart event
|
|
1656
|
+
* @param event The add to cart event
|
|
1657
|
+
*/
|
|
1658
|
+
trackAddToCart(event) {
|
|
1659
|
+
this.logger.debug("Handling ADD_TO_CART event", { event });
|
|
1660
|
+
const params = {
|
|
1661
|
+
product_id: event.productId,
|
|
1662
|
+
product_name: event.productName,
|
|
1663
|
+
price: event.price,
|
|
1664
|
+
currency: event.currency || "INR",
|
|
1665
|
+
quantity: event.quantity,
|
|
1666
|
+
variant: event.variant
|
|
1667
|
+
};
|
|
1668
|
+
this.logger.debug("Sending to PostHog with params", { params });
|
|
1669
|
+
if (!window.posthog) {
|
|
1670
|
+
this.logger.error("window.posthog is not available");
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
window.posthog.capture(
|
|
1674
|
+
"add_to_cart",
|
|
1675
|
+
this.enhanceWithAffiliateParams(params)
|
|
1676
|
+
);
|
|
1677
|
+
this.logger.debug("Event sent to PostHog successfully");
|
|
1678
|
+
}
|
|
1679
|
+
/**
|
|
1680
|
+
* Track a checkout started event
|
|
1681
|
+
* @param event The checkout started event
|
|
1682
|
+
*/
|
|
1683
|
+
trackCheckoutStarted(event) {
|
|
1684
|
+
const params = {
|
|
1685
|
+
cart_value: event.cartValue,
|
|
1686
|
+
currency: event.currency || "INR",
|
|
1687
|
+
item_count: event.itemCount,
|
|
1688
|
+
items: event.items.map((item) => ({
|
|
1689
|
+
product_id: item.productId,
|
|
1690
|
+
product_name: item.productName,
|
|
1691
|
+
price: item.price,
|
|
1692
|
+
quantity: item.quantity,
|
|
1693
|
+
variant: item.variant
|
|
1694
|
+
}))
|
|
1695
|
+
};
|
|
1696
|
+
window.posthog?.capture(
|
|
1697
|
+
"checkout_started",
|
|
1698
|
+
this.enhanceWithAffiliateParams(params)
|
|
1699
|
+
);
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Track a checkout completed event
|
|
1703
|
+
* @param event The checkout completed event
|
|
1704
|
+
*/
|
|
1705
|
+
trackCheckoutCompleted(event) {
|
|
1706
|
+
const params = {
|
|
1707
|
+
order_id: event.orderId,
|
|
1708
|
+
cart_value: event.cartValue,
|
|
1709
|
+
currency: event.currency || "INR",
|
|
1710
|
+
item_count: event.itemCount,
|
|
1711
|
+
items: event.items.map((item) => ({
|
|
1712
|
+
product_id: item.productId,
|
|
1713
|
+
product_name: item.productName,
|
|
1714
|
+
price: item.price,
|
|
1715
|
+
quantity: item.quantity,
|
|
1716
|
+
variant: item.variant
|
|
1717
|
+
}))
|
|
1718
|
+
};
|
|
1719
|
+
window.posthog?.capture(
|
|
1720
|
+
"purchase",
|
|
1721
|
+
this.enhanceWithAffiliateParams(params)
|
|
1722
|
+
);
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* Track a search event
|
|
1726
|
+
* @param event The search event
|
|
1727
|
+
*/
|
|
1728
|
+
trackSearch(event) {
|
|
1729
|
+
const params = {
|
|
1730
|
+
search_term: event.searchTerm,
|
|
1731
|
+
results_count: event.resultsCount,
|
|
1732
|
+
content_ids: event.content_ids
|
|
1733
|
+
};
|
|
1734
|
+
window.posthog?.capture("search", this.enhanceWithAffiliateParams(params));
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Track an add payment info event
|
|
1738
|
+
* @param event The add payment info event
|
|
1739
|
+
*/
|
|
1740
|
+
trackAddPaymentInfo(event) {
|
|
1741
|
+
const params = {
|
|
1742
|
+
cart_value: event.cartValue,
|
|
1743
|
+
currency: event.currency || "INR",
|
|
1744
|
+
payment_type: event.paymentType,
|
|
1745
|
+
item_count: event.itemCount,
|
|
1746
|
+
items: event.items.map((item) => ({
|
|
1747
|
+
product_id: item.productId,
|
|
1748
|
+
product_name: item.productName,
|
|
1749
|
+
price: item.price,
|
|
1750
|
+
quantity: item.quantity,
|
|
1751
|
+
variant: item.variant
|
|
1752
|
+
}))
|
|
1753
|
+
};
|
|
1754
|
+
window.posthog?.capture(
|
|
1755
|
+
"add_payment_info",
|
|
1756
|
+
this.enhanceWithAffiliateParams(params)
|
|
1757
|
+
);
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* Convert an event to PostHog parameters
|
|
1761
|
+
* @param event The event to convert
|
|
1762
|
+
*/
|
|
1763
|
+
eventToParams(event) {
|
|
1764
|
+
const { type, timestamp, ...params } = event;
|
|
1765
|
+
return params;
|
|
1766
|
+
}
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1769
|
+
// src/adapters/shopify-adapter.ts
|
|
1770
|
+
var import_hydrogen_react = require("@shopify/hydrogen-react");
|
|
1771
|
+
var DEFAULT_CURRENCY2 = "INR";
|
|
1772
|
+
var DEFAULT_LANGUAGE = "en";
|
|
1773
|
+
var ShopifyAdapter = class extends BaseAdapter {
|
|
1774
|
+
constructor(config) {
|
|
1775
|
+
super(config);
|
|
1776
|
+
this.name = "ShopifyAnalytics";
|
|
1777
|
+
/**
|
|
1778
|
+
* Send page view event using the enhanced functionality
|
|
1779
|
+
*/
|
|
1780
|
+
this.sendPageView = (eventName, payload) => {
|
|
1781
|
+
const enhancedPayload = {
|
|
1782
|
+
...this.createBasePayload(),
|
|
1783
|
+
...payload
|
|
1784
|
+
};
|
|
1785
|
+
return (0, import_hydrogen_react.sendShopifyAnalytics)({
|
|
1786
|
+
eventName,
|
|
1787
|
+
payload: enhancedPayload
|
|
1788
|
+
});
|
|
1789
|
+
};
|
|
1790
|
+
/**
|
|
1791
|
+
* Send add to cart event using the enhanced functionality
|
|
1792
|
+
*/
|
|
1793
|
+
this.sendAddToCart = ({
|
|
1794
|
+
cartId,
|
|
1795
|
+
totalValue,
|
|
1796
|
+
products
|
|
1797
|
+
}) => {
|
|
1798
|
+
return this.sendPageView(import_hydrogen_react.AnalyticsEventName.ADD_TO_CART, {
|
|
1799
|
+
cartId,
|
|
1800
|
+
totalValue,
|
|
1801
|
+
products
|
|
1802
|
+
});
|
|
1803
|
+
};
|
|
1804
|
+
this.shopId = config.shopId;
|
|
1805
|
+
this.domain = config.domain;
|
|
1806
|
+
this.currency = config.currency || DEFAULT_CURRENCY2;
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Initialize the Shopify Analytics adapter
|
|
1810
|
+
*/
|
|
1811
|
+
async initialize() {
|
|
1812
|
+
this.initializeLogger();
|
|
1813
|
+
try {
|
|
1814
|
+
if (typeof window !== "undefined") {
|
|
1815
|
+
this.logger.info("Shopify Analytics adapter initialized successfully", {
|
|
1816
|
+
shopId: this.shopId,
|
|
1817
|
+
domain: this.domain,
|
|
1818
|
+
currency: this.currency
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
this.initialized = true;
|
|
1822
|
+
} catch (error) {
|
|
1823
|
+
this.logger.error(
|
|
1824
|
+
"Failed to initialize Shopify Analytics",
|
|
1825
|
+
error instanceof Error ? error : new Error(String(error))
|
|
1826
|
+
);
|
|
1827
|
+
throw error;
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Convert product ID to Shopify GID format if it's not already
|
|
1832
|
+
*/
|
|
1833
|
+
formatProductGid(productId) {
|
|
1834
|
+
return productId.startsWith("gid://shopify/Product/") ? productId : `gid://shopify/Product/${productId}`;
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Get user consent status from your consent management system
|
|
1838
|
+
*/
|
|
1839
|
+
getUserConsent() {
|
|
1840
|
+
const hasConsent = this.checkUserConsent();
|
|
1841
|
+
return {
|
|
1842
|
+
hasUserConsent: hasConsent,
|
|
1843
|
+
analyticsAllowed: hasConsent && this.checkAnalyticsConsent(),
|
|
1844
|
+
marketingAllowed: hasConsent && this.checkMarketingConsent(),
|
|
1845
|
+
saleOfDataAllowed: hasConsent && this.checkSaleOfDataConsent()
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
/**
|
|
1849
|
+
* Check user consent (implement based on your consent management)
|
|
1850
|
+
*/
|
|
1851
|
+
checkUserConsent() {
|
|
1852
|
+
return true;
|
|
1853
|
+
}
|
|
1854
|
+
checkAnalyticsConsent() {
|
|
1855
|
+
return true;
|
|
1856
|
+
}
|
|
1857
|
+
checkMarketingConsent() {
|
|
1858
|
+
return true;
|
|
1859
|
+
}
|
|
1860
|
+
checkSaleOfDataConsent() {
|
|
1861
|
+
return true;
|
|
1862
|
+
}
|
|
1863
|
+
/**
|
|
1864
|
+
* Create base payload for all events
|
|
1865
|
+
*/
|
|
1866
|
+
createBasePayload() {
|
|
1867
|
+
const consent = this.getUserConsent();
|
|
1868
|
+
return {
|
|
1869
|
+
...(0, import_hydrogen_react.getClientBrowserParameters)(),
|
|
1870
|
+
...consent,
|
|
1871
|
+
storefrontId: this.domain,
|
|
1872
|
+
shopifySalesChannel: import_hydrogen_react.ShopifySalesChannel.headless,
|
|
1873
|
+
shopId: `gid://shopify/Shop/${this.shopId}`,
|
|
1874
|
+
currency: this.currency,
|
|
1875
|
+
acceptedLanguage: DEFAULT_LANGUAGE,
|
|
1876
|
+
...this.enhanceWithAffiliateParams({})
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* Track an event using Shopify Analytics
|
|
1881
|
+
*/
|
|
1882
|
+
async trackEvent(event) {
|
|
1883
|
+
if (!this.initialized || typeof window === "undefined") {
|
|
1884
|
+
this.logger.warn(
|
|
1885
|
+
"Shopify Analytics not initialized or not in browser environment"
|
|
1886
|
+
);
|
|
1887
|
+
return;
|
|
1888
|
+
}
|
|
1889
|
+
this.logger.debug("Processing Shopify Analytics event", {
|
|
1890
|
+
eventType: event.type,
|
|
1891
|
+
eventData: event
|
|
1892
|
+
});
|
|
1893
|
+
try {
|
|
1894
|
+
switch (event.type) {
|
|
1895
|
+
case "page_view" /* PAGE_VIEW */:
|
|
1896
|
+
this.sendPageView(import_hydrogen_react.AnalyticsEventName.PAGE_VIEW);
|
|
1897
|
+
this.logger.debug("Sent PAGE_VIEW event to Shopify Analytics");
|
|
1898
|
+
break;
|
|
1899
|
+
case "view_content" /* VIEW_CONTENT */:
|
|
1900
|
+
this.sendPageView(import_hydrogen_react.AnalyticsEventName.PRODUCT_VIEW);
|
|
1901
|
+
this.logger.debug("Sent PRODUCT_VIEW event to Shopify Analytics");
|
|
1902
|
+
break;
|
|
1903
|
+
case "add_to_cart" /* ADD_TO_CART */:
|
|
1904
|
+
this.trackAddToCart(event);
|
|
1905
|
+
break;
|
|
1906
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
1907
|
+
case "begin_checkout" /* BEGIN_CHECKOUT */:
|
|
1908
|
+
this.sendPageView(import_hydrogen_react.AnalyticsEventName.PAGE_VIEW, {
|
|
1909
|
+
pageType: "checkout"
|
|
1910
|
+
});
|
|
1911
|
+
this.logger.debug(
|
|
1912
|
+
"Sent checkout PAGE_VIEW event to Shopify Analytics"
|
|
1913
|
+
);
|
|
1914
|
+
break;
|
|
1915
|
+
default:
|
|
1916
|
+
this.logger.debug("Event not supported by Shopify Analytics", {
|
|
1917
|
+
eventType: event.type
|
|
1918
|
+
});
|
|
1919
|
+
break;
|
|
1920
|
+
}
|
|
1921
|
+
} catch (error) {
|
|
1922
|
+
this.logger.error(
|
|
1923
|
+
"Error tracking Shopify Analytics event",
|
|
1924
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
1925
|
+
{ eventType: event.type }
|
|
1926
|
+
);
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
/**
|
|
1930
|
+
* Check if Shopify session is properly established
|
|
1931
|
+
*/
|
|
1932
|
+
isSessionValid() {
|
|
1933
|
+
if (typeof window === "undefined") return false;
|
|
1934
|
+
const shopifyY = document.cookie.includes("_shopify_y=");
|
|
1935
|
+
const shopifyS = document.cookie.includes("_shopify_s=");
|
|
1936
|
+
return shopifyY && shopifyS;
|
|
1937
|
+
}
|
|
1938
|
+
/**
|
|
1939
|
+
* Get session debug information
|
|
1940
|
+
*/
|
|
1941
|
+
getSessionDebugInfo() {
|
|
1942
|
+
if (typeof window === "undefined")
|
|
1943
|
+
return { error: "Not in browser environment" };
|
|
1944
|
+
return {
|
|
1945
|
+
sessionValid: this.isSessionValid(),
|
|
1946
|
+
cookies: {
|
|
1947
|
+
shopify_y: document.cookie.includes("_shopify_y="),
|
|
1948
|
+
shopify_s: document.cookie.includes("_shopify_s="),
|
|
1949
|
+
all: document.cookie
|
|
1950
|
+
},
|
|
1951
|
+
shopId: this.shopId,
|
|
1952
|
+
initialized: this.initialized
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
/**
|
|
1956
|
+
* Track add to cart event with enhanced error handling
|
|
1957
|
+
*/
|
|
1958
|
+
trackAddToCart(event) {
|
|
1959
|
+
if (!event.productId) {
|
|
1960
|
+
this.logger.warn("ADD_TO_CART event missing productId");
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
try {
|
|
1964
|
+
const productGid = this.formatProductGid(event.productId);
|
|
1965
|
+
const cartKey = `merchant_${process.env.NEXT_PUBLIC_MERCHANT_NAME}_cartId`;
|
|
1966
|
+
const cartId = localStorage.getItem(cartKey) || "";
|
|
1967
|
+
if (!cartId) {
|
|
1968
|
+
this.logger.warn("No cart ID found, creating anonymous session");
|
|
1969
|
+
}
|
|
1970
|
+
if (!event.price || event.price <= 0) {
|
|
1971
|
+
this.logger.warn("Invalid or missing price for ADD_TO_CART", {
|
|
1972
|
+
price: event.price
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
const productPrice = Math.max(0, event.price || 0);
|
|
1976
|
+
const productQuantity = Math.max(1, event.quantity || 1);
|
|
1977
|
+
const products = [
|
|
1978
|
+
{
|
|
1979
|
+
productGid,
|
|
1980
|
+
variantGid: event.variantId || productGid.replace("Product", "ProductVariant"),
|
|
1981
|
+
quantity: productQuantity,
|
|
1982
|
+
price: productPrice.toString(),
|
|
1983
|
+
// Convert to string as required by ShopifyAnalyticsProduct
|
|
1984
|
+
name: event.productName || "Unknown Product",
|
|
1985
|
+
brand: event.brand || "Unknown Brand"
|
|
1986
|
+
}
|
|
1987
|
+
];
|
|
1988
|
+
const totalValue = productPrice * productQuantity;
|
|
1989
|
+
this.logger.debug("ADD_TO_CART event tracked successfully", {
|
|
1990
|
+
productGid,
|
|
1991
|
+
quantity: productQuantity,
|
|
1992
|
+
price: productPrice,
|
|
1993
|
+
totalValue
|
|
1994
|
+
});
|
|
1995
|
+
this.sendAddToCart({
|
|
1996
|
+
cartId,
|
|
1997
|
+
products,
|
|
1998
|
+
totalValue
|
|
1999
|
+
});
|
|
2000
|
+
} catch (error) {
|
|
2001
|
+
this.logger.error(
|
|
2002
|
+
"Error in trackAddToCart",
|
|
2003
|
+
error instanceof Error ? error : new Error(String(error))
|
|
2004
|
+
);
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
};
|
|
2008
|
+
|
|
2009
|
+
// src/adapters/kwikpass-adapter.ts
|
|
2010
|
+
var KwikPassAdapter = class extends BaseAdapter {
|
|
2011
|
+
constructor(config = {}) {
|
|
2012
|
+
super(config);
|
|
2013
|
+
this.name = "KwikPass";
|
|
2014
|
+
this.enableKwikPassEvents = config.enableKwikPassEvents ?? true;
|
|
2015
|
+
this.initializeLogger();
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
2018
|
+
* Initialize the KwikPass adapter
|
|
2019
|
+
*/
|
|
2020
|
+
async initialize() {
|
|
2021
|
+
try {
|
|
2022
|
+
if (typeof window !== "undefined") {
|
|
2023
|
+
this.logger.info("KwikPass adapter initialized successfully", {
|
|
2024
|
+
eventsEnabled: this.enableKwikPassEvents
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
this.initialized = true;
|
|
2028
|
+
} catch (error) {
|
|
2029
|
+
this.logger.error(
|
|
2030
|
+
"Failed to initialize KwikPass adapter",
|
|
2031
|
+
error
|
|
2032
|
+
);
|
|
2033
|
+
throw error;
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* Track an event using KwikPass
|
|
2038
|
+
*/
|
|
2039
|
+
async trackEvent(event) {
|
|
2040
|
+
if (!this.initialized || typeof window === "undefined") {
|
|
2041
|
+
this.logger.warn(
|
|
2042
|
+
"KwikPass adapter not initialized or not in browser environment"
|
|
2043
|
+
);
|
|
2044
|
+
return;
|
|
2045
|
+
}
|
|
2046
|
+
if (!this.enableKwikPassEvents) {
|
|
2047
|
+
this.logger.debug("KwikPass events disabled, skipping event", {
|
|
2048
|
+
eventType: event.type
|
|
2049
|
+
});
|
|
2050
|
+
return;
|
|
2051
|
+
}
|
|
2052
|
+
try {
|
|
2053
|
+
this.logger.debug("Processing event", { eventType: event.type });
|
|
2054
|
+
const enhancedEvent = this.enhanceWithAffiliateParams(event);
|
|
2055
|
+
switch (event.type) {
|
|
2056
|
+
case "product_view" /* PRODUCT_VIEW */:
|
|
2057
|
+
this.trackProductView(enhancedEvent);
|
|
2058
|
+
break;
|
|
2059
|
+
case "collection_view" /* COLLECTION_VIEW */:
|
|
2060
|
+
this.trackCollectionView(enhancedEvent);
|
|
2061
|
+
break;
|
|
2062
|
+
case "page_view" /* PAGE_VIEW */:
|
|
2063
|
+
this.trackPageView(enhancedEvent);
|
|
2064
|
+
break;
|
|
2065
|
+
default:
|
|
2066
|
+
this.logger.debug("Event not supported", { eventType: event.type });
|
|
2067
|
+
break;
|
|
2068
|
+
}
|
|
2069
|
+
} catch (error) {
|
|
2070
|
+
this.logger.error("Error tracking KwikPass event", error, {
|
|
2071
|
+
eventType: event.type
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* Send event to KwikPass platform
|
|
2077
|
+
*/
|
|
2078
|
+
sendKwikPassEvent(type, eventData) {
|
|
2079
|
+
this.logger.debug(`Sending ${type}`, { eventData });
|
|
2080
|
+
if (typeof window !== "undefined") {
|
|
2081
|
+
const customEvent = new CustomEvent(`page_view_kp`, {
|
|
2082
|
+
detail: {
|
|
2083
|
+
type,
|
|
2084
|
+
detail: eventData
|
|
2085
|
+
}
|
|
2086
|
+
});
|
|
2087
|
+
window.dispatchEvent(customEvent);
|
|
2088
|
+
this.logger.debug(`${type} sent successfully`);
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
/**
|
|
2092
|
+
* Track product view event
|
|
2093
|
+
*/
|
|
2094
|
+
trackCollectionView(event) {
|
|
2095
|
+
this.sendKwikPassEvent("collection", {
|
|
2096
|
+
product_id: event.productId,
|
|
2097
|
+
product_name: event.productName,
|
|
2098
|
+
price: event.price,
|
|
2099
|
+
currency: event.currency,
|
|
2100
|
+
category: event.category,
|
|
2101
|
+
timestamp: event.timestamp || Date.now()
|
|
2102
|
+
});
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Track collection view event
|
|
2106
|
+
*/
|
|
2107
|
+
trackProductView(event) {
|
|
2108
|
+
this.sendKwikPassEvent("product", {
|
|
2109
|
+
product_id: event.productId,
|
|
2110
|
+
product_name: event.productName,
|
|
2111
|
+
price: event.price,
|
|
2112
|
+
currency: event.currency,
|
|
2113
|
+
category: event.category,
|
|
2114
|
+
timestamp: event.timestamp || Date.now()
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
/**
|
|
2118
|
+
* Track page view event
|
|
2119
|
+
*/
|
|
2120
|
+
trackPageView(event) {
|
|
2121
|
+
this.sendKwikPassEvent("other", {
|
|
2122
|
+
path: event.path,
|
|
2123
|
+
title: event.title,
|
|
2124
|
+
referrer: event.referrer,
|
|
2125
|
+
timestamp: event.timestamp || Date.now()
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
};
|
|
2129
|
+
|
|
2130
|
+
// src/adapters/kwik-checkout-adapter.ts
|
|
2131
|
+
var KwikCheckoutAdapter = class extends BaseAdapter {
|
|
2132
|
+
constructor(config) {
|
|
2133
|
+
super(config);
|
|
2134
|
+
this.name = "KwikCheckout";
|
|
2135
|
+
this.mid = config.mid || "";
|
|
2136
|
+
this.environment = config.environment || "production";
|
|
2137
|
+
this.storeId = config.storeId || "";
|
|
2138
|
+
this.initializeLogger();
|
|
2139
|
+
}
|
|
2140
|
+
/**
|
|
2141
|
+
* Initialize the GoKwik adapter
|
|
2142
|
+
*/
|
|
2143
|
+
async initialize() {
|
|
2144
|
+
try {
|
|
2145
|
+
if (typeof window !== "undefined") {
|
|
2146
|
+
this.logger.info("GoKwik adapter initialized successfully", {
|
|
2147
|
+
mid: this.mid,
|
|
2148
|
+
environment: this.environment,
|
|
2149
|
+
storeId: this.storeId
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
this.initialized = true;
|
|
2153
|
+
} catch (error) {
|
|
2154
|
+
this.logger.error("Failed to initialize GoKwik adapter", error);
|
|
2155
|
+
throw error;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
/**
|
|
2159
|
+
* Track an event using GoKwik
|
|
2160
|
+
*/
|
|
2161
|
+
async trackEvent(event) {
|
|
2162
|
+
if (!this.initialized || typeof window === "undefined") {
|
|
2163
|
+
this.logger.warn(
|
|
2164
|
+
"GoKwik adapter not initialized or not in browser environment"
|
|
2165
|
+
);
|
|
2166
|
+
return;
|
|
2167
|
+
}
|
|
2168
|
+
try {
|
|
2169
|
+
this.logger.debug("Processing event", { eventType: event.type });
|
|
2170
|
+
const enhancedEvent = this.enhanceWithAffiliateParams(event);
|
|
2171
|
+
switch (event.type) {
|
|
2172
|
+
case "started_checkout_gk" /* STARTED_CHECKOUT_GK */:
|
|
2173
|
+
this.trackStartedCheckoutGK(enhancedEvent);
|
|
2174
|
+
break;
|
|
2175
|
+
case "mobile_added_gk" /* MOBILE_ADDED_GK */:
|
|
2176
|
+
this.trackMobileAddedGK(enhancedEvent);
|
|
2177
|
+
break;
|
|
2178
|
+
case "address_selected_gk" /* ADDRESS_SELECTED_GK */:
|
|
2179
|
+
this.trackAddressSelectedGK(enhancedEvent);
|
|
2180
|
+
break;
|
|
2181
|
+
case "address_completed_gk" /* ADDRESS_COMPLETED_GK */:
|
|
2182
|
+
this.trackAddressCompletedGK(enhancedEvent);
|
|
2183
|
+
break;
|
|
2184
|
+
case "address_added_gk" /* ADDRESS_ADDED_GK */:
|
|
2185
|
+
this.trackAddressAddedGK(enhancedEvent);
|
|
2186
|
+
break;
|
|
2187
|
+
case "pin_code_added_gk" /* PIN_CODE_ADDED_GK */:
|
|
2188
|
+
this.trackPinCodeAddedGK(enhancedEvent);
|
|
2189
|
+
break;
|
|
2190
|
+
case "payment_method_selected_gk" /* PAYMENT_METHOD_SELECTED_GK */:
|
|
2191
|
+
this.trackPaymentMethodSelectedGK(enhancedEvent);
|
|
2192
|
+
break;
|
|
2193
|
+
case "payment_completed_gk" /* PAYMENT_COMPLETED_GK */:
|
|
2194
|
+
this.trackPaymentCompletedGK(enhancedEvent);
|
|
2195
|
+
break;
|
|
2196
|
+
case "order_success" /* ORDER_SUCCESS */:
|
|
2197
|
+
this.trackOrderSuccess(enhancedEvent);
|
|
2198
|
+
break;
|
|
2199
|
+
case "order_completed" /* ORDER_COMPLETED */:
|
|
2200
|
+
this.trackOrderCompleted(enhancedEvent);
|
|
2201
|
+
break;
|
|
2202
|
+
case "cart_viewed" /* CART_VIEWED */:
|
|
2203
|
+
this.trackCartViewed(enhancedEvent);
|
|
2204
|
+
break;
|
|
2205
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
2206
|
+
this.trackCheckoutStarted(enhancedEvent);
|
|
2207
|
+
break;
|
|
2208
|
+
case "checkout_completed" /* CHECKOUT_COMPLETED */:
|
|
2209
|
+
this.trackCheckoutCompleted(enhancedEvent);
|
|
2210
|
+
break;
|
|
2211
|
+
case "add_payment_info" /* ADD_PAYMENT_INFO */:
|
|
2212
|
+
this.trackAddPaymentInfo(enhancedEvent);
|
|
2213
|
+
break;
|
|
2214
|
+
default:
|
|
2215
|
+
this.logger.debug("Event not supported", { eventType: event.type });
|
|
2216
|
+
break;
|
|
2217
|
+
}
|
|
2218
|
+
} catch (error) {
|
|
2219
|
+
this.logger.error("Error tracking GoKwik event", error, {
|
|
2220
|
+
eventType: event.type
|
|
2221
|
+
});
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
/**
|
|
2225
|
+
* Send event to GoKwik platform
|
|
2226
|
+
*/
|
|
2227
|
+
sendGoKwikEvent(eventName, eventData) {
|
|
2228
|
+
this.logger.debug(`Sending ${eventName}`, { eventData });
|
|
2229
|
+
if (typeof window !== "undefined" && window.gokwikSdk) {
|
|
2230
|
+
try {
|
|
2231
|
+
window.gokwikSdk.track?.(eventName, eventData);
|
|
2232
|
+
this.logger.debug(`${eventName} sent via SDK successfully`);
|
|
2233
|
+
} catch (error) {
|
|
2234
|
+
this.logger.error(
|
|
2235
|
+
`Error sending GoKwik event ${eventName} via SDK`,
|
|
2236
|
+
error
|
|
2237
|
+
);
|
|
2238
|
+
}
|
|
2239
|
+
} else {
|
|
2240
|
+
if (typeof window !== "undefined") {
|
|
2241
|
+
const customEvent = new CustomEvent(`gokwik_${eventName}`, {
|
|
2242
|
+
detail: eventData
|
|
2243
|
+
});
|
|
2244
|
+
window.dispatchEvent(customEvent);
|
|
2245
|
+
this.logger.debug(`${eventName} sent via custom event successfully`);
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
/**
|
|
2250
|
+
* Track started checkout GK event
|
|
2251
|
+
*/
|
|
2252
|
+
trackStartedCheckoutGK(event) {
|
|
2253
|
+
this.sendGoKwikEvent("started_checkout", {
|
|
2254
|
+
cart_value: event.cartValue,
|
|
2255
|
+
currency: event.currency,
|
|
2256
|
+
timestamp: event.timestamp || Date.now()
|
|
2257
|
+
});
|
|
2258
|
+
}
|
|
2259
|
+
/**
|
|
2260
|
+
* Track mobile added GK event
|
|
2261
|
+
*/
|
|
2262
|
+
trackMobileAddedGK(event) {
|
|
2263
|
+
this.sendGoKwikEvent("mobile_added", {
|
|
2264
|
+
mobile: event.mobile,
|
|
2265
|
+
timestamp: event.timestamp || Date.now()
|
|
2266
|
+
});
|
|
2267
|
+
}
|
|
2268
|
+
/**
|
|
2269
|
+
* Track address selected GK event
|
|
2270
|
+
*/
|
|
2271
|
+
trackAddressSelectedGK(event) {
|
|
2272
|
+
this.sendGoKwikEvent("address_selected", {
|
|
2273
|
+
address_id: event.addressId,
|
|
2274
|
+
timestamp: event.timestamp || Date.now()
|
|
2275
|
+
});
|
|
2276
|
+
}
|
|
2277
|
+
/**
|
|
2278
|
+
* Track address completed GK event
|
|
2279
|
+
*/
|
|
2280
|
+
trackAddressCompletedGK(event) {
|
|
2281
|
+
this.sendGoKwikEvent("address_completed", {
|
|
2282
|
+
address_id: event.addressId,
|
|
2283
|
+
timestamp: event.timestamp || Date.now()
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
/**
|
|
2287
|
+
* Track address added GK event
|
|
2288
|
+
*/
|
|
2289
|
+
trackAddressAddedGK(event) {
|
|
2290
|
+
this.sendGoKwikEvent("address_added", {
|
|
2291
|
+
address_id: event.addressId,
|
|
2292
|
+
timestamp: event.timestamp || Date.now()
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* Track PIN code added GK event
|
|
2297
|
+
*/
|
|
2298
|
+
trackPinCodeAddedGK(event) {
|
|
2299
|
+
this.sendGoKwikEvent("pin_code_added", {
|
|
2300
|
+
pin_code: event.pinCode,
|
|
2301
|
+
timestamp: event.timestamp || Date.now()
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
/**
|
|
2305
|
+
* Track payment method selected GK event
|
|
2306
|
+
*/
|
|
2307
|
+
trackPaymentMethodSelectedGK(event) {
|
|
2308
|
+
this.sendGoKwikEvent("payment_method_selected", {
|
|
2309
|
+
payment_method: event.paymentMethod,
|
|
2310
|
+
timestamp: event.timestamp || Date.now()
|
|
2311
|
+
});
|
|
2312
|
+
}
|
|
2313
|
+
/**
|
|
2314
|
+
* Track payment completed GK event
|
|
2315
|
+
*/
|
|
2316
|
+
trackPaymentCompletedGK(event) {
|
|
2317
|
+
this.sendGoKwikEvent("payment_completed", {
|
|
2318
|
+
amount: event.amount,
|
|
2319
|
+
currency: event.currency,
|
|
2320
|
+
timestamp: event.timestamp || Date.now()
|
|
2321
|
+
});
|
|
2322
|
+
}
|
|
2323
|
+
/**
|
|
2324
|
+
* Track order success event
|
|
2325
|
+
*/
|
|
2326
|
+
trackOrderSuccess(event) {
|
|
2327
|
+
this.sendGoKwikEvent("order_success", {
|
|
2328
|
+
order_id: event.orderId,
|
|
2329
|
+
amount: event.amount,
|
|
2330
|
+
currency: event.currency,
|
|
2331
|
+
timestamp: event.timestamp || Date.now()
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2334
|
+
/**
|
|
2335
|
+
* Track order completed event
|
|
2336
|
+
*/
|
|
2337
|
+
trackOrderCompleted(event) {
|
|
2338
|
+
this.sendGoKwikEvent("order_completed", {
|
|
2339
|
+
order_id: event.orderId,
|
|
2340
|
+
amount: event.amount,
|
|
2341
|
+
currency: event.currency,
|
|
2342
|
+
timestamp: event.timestamp || Date.now()
|
|
2343
|
+
});
|
|
2344
|
+
}
|
|
2345
|
+
/**
|
|
2346
|
+
* Track cart viewed event
|
|
2347
|
+
*/
|
|
2348
|
+
trackCartViewed(event) {
|
|
2349
|
+
this.sendGoKwikEvent("cart_viewed", {
|
|
2350
|
+
cart_id: event.cartId,
|
|
2351
|
+
products: event.products,
|
|
2352
|
+
timestamp: event.timestamp || Date.now()
|
|
2353
|
+
});
|
|
2354
|
+
}
|
|
2355
|
+
/**
|
|
2356
|
+
* Track checkout started event
|
|
2357
|
+
*/
|
|
2358
|
+
trackCheckoutStarted(event) {
|
|
2359
|
+
this.sendGoKwikEvent("checkout_started", {
|
|
2360
|
+
cart_value: event.cartValue,
|
|
2361
|
+
currency: event.currency,
|
|
2362
|
+
item_count: event.itemCount,
|
|
2363
|
+
items: event.items,
|
|
2364
|
+
timestamp: event.timestamp || Date.now()
|
|
2365
|
+
});
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* Track checkout completed event
|
|
2369
|
+
*/
|
|
2370
|
+
trackCheckoutCompleted(event) {
|
|
2371
|
+
this.sendGoKwikEvent("checkout_completed", {
|
|
2372
|
+
order_id: event.orderId,
|
|
2373
|
+
cart_value: event.cartValue,
|
|
2374
|
+
currency: event.currency,
|
|
2375
|
+
item_count: event.itemCount,
|
|
2376
|
+
items: event.items,
|
|
2377
|
+
timestamp: event.timestamp || Date.now()
|
|
2378
|
+
});
|
|
2379
|
+
}
|
|
2380
|
+
/**
|
|
2381
|
+
* Track add payment info event
|
|
2382
|
+
*/
|
|
2383
|
+
trackAddPaymentInfo(event) {
|
|
2384
|
+
this.sendGoKwikEvent("add_payment_info", {
|
|
2385
|
+
cart_value: event.cartValue,
|
|
2386
|
+
currency: event.currency,
|
|
2387
|
+
item_count: event.itemCount,
|
|
2388
|
+
payment_type: event.paymentType,
|
|
2389
|
+
items: event.items,
|
|
2390
|
+
timestamp: event.timestamp || Date.now()
|
|
2391
|
+
});
|
|
2392
|
+
}
|
|
2393
|
+
};
|
|
2394
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2395
|
+
0 && (module.exports = {
|
|
2396
|
+
BaseAdapter,
|
|
2397
|
+
GoogleAdapter,
|
|
2398
|
+
KwikCheckoutAdapter,
|
|
2399
|
+
KwikPassAdapter,
|
|
2400
|
+
MoengageAdapter,
|
|
2401
|
+
PixelAdapter,
|
|
2402
|
+
PostHogAdapter,
|
|
2403
|
+
ShopifyAdapter
|
|
2404
|
+
});
|
|
2405
|
+
//# sourceMappingURL=index.js.map
|