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
package/dist/index.js
ADDED
|
@@ -0,0 +1,3269 @@
|
|
|
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 __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
|
|
34
|
+
// src/events/publisher.ts
|
|
35
|
+
function publishEvent(event) {
|
|
36
|
+
try {
|
|
37
|
+
eventPublisher.publish(event);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error("Error in publishEvent helper:", error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
var EventPublisher, eventPublisher;
|
|
43
|
+
var init_publisher = __esm({
|
|
44
|
+
"src/events/publisher.ts"() {
|
|
45
|
+
"use strict";
|
|
46
|
+
EventPublisher = class _EventPublisher {
|
|
47
|
+
/**
|
|
48
|
+
* Private constructor to enforce singleton pattern
|
|
49
|
+
*/
|
|
50
|
+
constructor() {
|
|
51
|
+
this.subscribers = [];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the singleton instance of EventPublisher
|
|
55
|
+
*/
|
|
56
|
+
static getInstance() {
|
|
57
|
+
if (!_EventPublisher.instance) {
|
|
58
|
+
_EventPublisher.instance = new _EventPublisher();
|
|
59
|
+
}
|
|
60
|
+
return _EventPublisher.instance;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Subscribe to events
|
|
64
|
+
* @param callback Function to be called when an event is published
|
|
65
|
+
* @returns Unsubscribe function
|
|
66
|
+
*/
|
|
67
|
+
subscribe(callback) {
|
|
68
|
+
this.subscribers.push(callback);
|
|
69
|
+
return () => {
|
|
70
|
+
this.subscribers = this.subscribers.filter(
|
|
71
|
+
(subscriber) => subscriber !== callback
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Publish an event to all subscribers
|
|
77
|
+
* @param event The event to publish
|
|
78
|
+
*/
|
|
79
|
+
publish(event) {
|
|
80
|
+
try {
|
|
81
|
+
console.log("EventPublisher: Received event", {
|
|
82
|
+
type: event.type,
|
|
83
|
+
data: event
|
|
84
|
+
});
|
|
85
|
+
const eventWithTimestamp = !event.timestamp ? { ...event, timestamp: Date.now() } : event;
|
|
86
|
+
console.log("EventPublisher: Number of subscribers:", this.subscribers.length);
|
|
87
|
+
for (const subscriber of this.subscribers) {
|
|
88
|
+
try {
|
|
89
|
+
console.log("EventPublisher: Notifying subscriber");
|
|
90
|
+
subscriber(eventWithTimestamp);
|
|
91
|
+
console.log("EventPublisher: Subscriber notified successfully");
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error("EventPublisher: Error in subscriber:", error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
console.log("EventPublisher: Event processing completed");
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error("Error publishing event:", error, event);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
eventPublisher = EventPublisher.getInstance();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// src/events/subscriber.ts
|
|
107
|
+
var subscriber_exports = {};
|
|
108
|
+
__export(subscriber_exports, {
|
|
109
|
+
eventSubscriber: () => eventSubscriber
|
|
110
|
+
});
|
|
111
|
+
var EventSubscriber, eventSubscriber;
|
|
112
|
+
var init_subscriber = __esm({
|
|
113
|
+
"src/events/subscriber.ts"() {
|
|
114
|
+
"use strict";
|
|
115
|
+
init_publisher();
|
|
116
|
+
EventSubscriber = class _EventSubscriber {
|
|
117
|
+
/**
|
|
118
|
+
* Private constructor to enforce singleton pattern
|
|
119
|
+
*/
|
|
120
|
+
constructor() {
|
|
121
|
+
this.adapters = [];
|
|
122
|
+
this.initialized = false;
|
|
123
|
+
this.eventQueue = [];
|
|
124
|
+
this.unsubscribe = null;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get the singleton instance of EventSubscriber
|
|
128
|
+
*/
|
|
129
|
+
static getInstance() {
|
|
130
|
+
if (!_EventSubscriber.instance) {
|
|
131
|
+
_EventSubscriber.instance = new _EventSubscriber();
|
|
132
|
+
}
|
|
133
|
+
return _EventSubscriber.instance;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Register a tracking adapter
|
|
137
|
+
* @param adapter The tracking adapter to register
|
|
138
|
+
*/
|
|
139
|
+
registerAdapter(adapter) {
|
|
140
|
+
const existingAdapter = this.adapters.find((a) => a.name === adapter.name);
|
|
141
|
+
if (existingAdapter) {
|
|
142
|
+
console.warn(
|
|
143
|
+
`Tracking adapter with name "${adapter.name}" is already registered. Skipping.`
|
|
144
|
+
);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
this.adapters.push(adapter);
|
|
148
|
+
if (this.initialized) {
|
|
149
|
+
this.initializeAdapter(adapter).catch((error) => {
|
|
150
|
+
console.error(`Failed to initialize adapter "${adapter.name}":`, error);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Unregister a tracking adapter by name
|
|
156
|
+
* @param adapterName The name of the adapter to unregister
|
|
157
|
+
*/
|
|
158
|
+
unregisterAdapter(adapterName) {
|
|
159
|
+
this.adapters = this.adapters.filter(
|
|
160
|
+
(adapter) => adapter.name !== adapterName
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Initialize all registered adapters
|
|
165
|
+
*/
|
|
166
|
+
async initialize() {
|
|
167
|
+
console.log("Initializing EventSubscriber...");
|
|
168
|
+
if (this.initialized) {
|
|
169
|
+
console.log("EventSubscriber already initialized");
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
this.unsubscribe = eventPublisher.subscribe(this.handleEvent.bind(this));
|
|
173
|
+
console.log("Subscribed to event publisher");
|
|
174
|
+
console.log(`Initializing ${this.adapters.length} adapters...`);
|
|
175
|
+
await Promise.all(
|
|
176
|
+
this.adapters.map((adapter) => this.initializeAdapter(adapter))
|
|
177
|
+
);
|
|
178
|
+
this.initialized = true;
|
|
179
|
+
console.log("EventSubscriber initialization complete");
|
|
180
|
+
this.processEventQueue();
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Initialize a single adapter
|
|
184
|
+
* @param adapter The adapter to initialize
|
|
185
|
+
*/
|
|
186
|
+
async initializeAdapter(adapter) {
|
|
187
|
+
try {
|
|
188
|
+
await adapter.initialize();
|
|
189
|
+
console.log(
|
|
190
|
+
`Tracking adapter "${adapter.name}" initialized successfully.`
|
|
191
|
+
);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
console.error(`Failed to initialize adapter "${adapter.name}":`, error);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Handle an event by forwarding it to all enabled adapters
|
|
198
|
+
* @param event The event to handle
|
|
199
|
+
*/
|
|
200
|
+
handleEvent(event) {
|
|
201
|
+
console.log("Handling event:", event.type);
|
|
202
|
+
if (!this.initialized) {
|
|
203
|
+
console.log("Subscriber not initialized, queueing event");
|
|
204
|
+
this.eventQueue.push(event);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
for (const adapter of this.adapters) {
|
|
208
|
+
if (adapter.isEnabled()) {
|
|
209
|
+
console.log(`Forwarding event to adapter: ${adapter.name}`);
|
|
210
|
+
adapter.trackEvent(event).catch((error) => {
|
|
211
|
+
console.error(
|
|
212
|
+
`Error tracking event in adapter "${adapter.name}":`,
|
|
213
|
+
error
|
|
214
|
+
);
|
|
215
|
+
});
|
|
216
|
+
} else {
|
|
217
|
+
console.log(`Adapter ${adapter.name} is disabled, skipping`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Process any events that were queued before initialization
|
|
223
|
+
*/
|
|
224
|
+
processEventQueue() {
|
|
225
|
+
if (this.eventQueue.length === 0) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
console.log(`Processing ${this.eventQueue.length} queued events.`);
|
|
229
|
+
for (const event of this.eventQueue) {
|
|
230
|
+
this.handleEvent(event);
|
|
231
|
+
}
|
|
232
|
+
this.eventQueue = [];
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Shutdown the subscriber and all adapters
|
|
236
|
+
*/
|
|
237
|
+
shutdown() {
|
|
238
|
+
if (this.unsubscribe) {
|
|
239
|
+
this.unsubscribe();
|
|
240
|
+
this.unsubscribe = null;
|
|
241
|
+
}
|
|
242
|
+
this.initialized = false;
|
|
243
|
+
this.eventQueue = [];
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Get all registered adapters
|
|
247
|
+
*/
|
|
248
|
+
getAdapters() {
|
|
249
|
+
return [...this.adapters];
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
eventSubscriber = EventSubscriber.getInstance();
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// src/index.ts
|
|
257
|
+
var src_exports = {};
|
|
258
|
+
__export(src_exports, {
|
|
259
|
+
AffiliateTracker: () => AffiliateTracker_default,
|
|
260
|
+
BaseAdapter: () => BaseAdapter,
|
|
261
|
+
DEFAULT_CURRENCY: () => DEFAULT_CURRENCY,
|
|
262
|
+
EventNames: () => EventNames,
|
|
263
|
+
EventType: () => EventType,
|
|
264
|
+
GoogleAdapter: () => GoogleAdapter,
|
|
265
|
+
HARDCODED_HANDLE: () => HARDCODED_HANDLE,
|
|
266
|
+
KwikCheckoutAdapter: () => KwikCheckoutAdapter,
|
|
267
|
+
KwikPassAdapter: () => KwikPassAdapter,
|
|
268
|
+
MoengageAdapter: () => MoengageAdapter,
|
|
269
|
+
PixelAdapter: () => PixelAdapter,
|
|
270
|
+
PostHogAdapter: () => PostHogAdapter,
|
|
271
|
+
ShopifyAdapter: () => ShopifyAdapter,
|
|
272
|
+
ShopkitAnalytics: () => ShopkitAnalytics_default,
|
|
273
|
+
captureAffiliateParams: () => captureAffiliateParams,
|
|
274
|
+
clearAffiliateParams: () => clearAffiliateParams,
|
|
275
|
+
createAdapterLogger: () => createAdapterLogger,
|
|
276
|
+
createLogger: () => createLogger,
|
|
277
|
+
default: () => ShopkitAnalytics_default,
|
|
278
|
+
eventPublisher: () => eventPublisher,
|
|
279
|
+
eventSubscriber: () => eventSubscriber,
|
|
280
|
+
getAffiliateParams: () => getAffiliateParams,
|
|
281
|
+
getAffiliateSource: () => getAffiliateSource,
|
|
282
|
+
hasAffiliateData: () => hasAffiliateData,
|
|
283
|
+
initTracking: () => initTracking,
|
|
284
|
+
initializeEventTracking: () => initializeEventTracking,
|
|
285
|
+
logger: () => logger,
|
|
286
|
+
publishEvent: () => publishEvent,
|
|
287
|
+
useAffiliateSource: () => useAffiliateSource,
|
|
288
|
+
useAffiliateTracker: () => useAffiliateTracker,
|
|
289
|
+
useHasAffiliateData: () => useHasAffiliateData
|
|
290
|
+
});
|
|
291
|
+
module.exports = __toCommonJS(src_exports);
|
|
292
|
+
|
|
293
|
+
// src/ShopkitAnalytics.tsx
|
|
294
|
+
var import_react3 = require("react");
|
|
295
|
+
var import_hydrogen_react2 = require("@shopify/hydrogen-react");
|
|
296
|
+
|
|
297
|
+
// src/logger/index.ts
|
|
298
|
+
var import_pino = __toESM(require("pino"));
|
|
299
|
+
var NoOpLogger = class _NoOpLogger {
|
|
300
|
+
trace() {
|
|
301
|
+
}
|
|
302
|
+
debug() {
|
|
303
|
+
}
|
|
304
|
+
info() {
|
|
305
|
+
}
|
|
306
|
+
warn() {
|
|
307
|
+
}
|
|
308
|
+
error() {
|
|
309
|
+
}
|
|
310
|
+
fatal() {
|
|
311
|
+
}
|
|
312
|
+
child() {
|
|
313
|
+
return new _NoOpLogger();
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
var PinoLogger = class _PinoLogger {
|
|
317
|
+
constructor(logger2) {
|
|
318
|
+
this.logger = logger2;
|
|
319
|
+
}
|
|
320
|
+
trace(message, ...args) {
|
|
321
|
+
this.logger.trace({ args }, message);
|
|
322
|
+
}
|
|
323
|
+
debug(message, ...args) {
|
|
324
|
+
this.logger.debug({ args }, message);
|
|
325
|
+
}
|
|
326
|
+
info(message, ...args) {
|
|
327
|
+
this.logger.info({ args }, message);
|
|
328
|
+
}
|
|
329
|
+
warn(message, ...args) {
|
|
330
|
+
this.logger.warn({ args }, message);
|
|
331
|
+
}
|
|
332
|
+
error(message, error, ...args) {
|
|
333
|
+
this.logger.error({ error, args }, message);
|
|
334
|
+
}
|
|
335
|
+
fatal(message, error, ...args) {
|
|
336
|
+
this.logger.fatal({ error, args }, message);
|
|
337
|
+
}
|
|
338
|
+
child(bindings) {
|
|
339
|
+
return new _PinoLogger(this.logger.child(bindings));
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
function createLogger(config = {}) {
|
|
343
|
+
const {
|
|
344
|
+
level = "info",
|
|
345
|
+
enabled = true,
|
|
346
|
+
name = "@shopkit/analytics",
|
|
347
|
+
prettyPrint = false,
|
|
348
|
+
redact = []
|
|
349
|
+
} = config;
|
|
350
|
+
if (!enabled) {
|
|
351
|
+
return new NoOpLogger();
|
|
352
|
+
}
|
|
353
|
+
const pinoConfig = {
|
|
354
|
+
name,
|
|
355
|
+
level,
|
|
356
|
+
redact,
|
|
357
|
+
browser: {
|
|
358
|
+
asObject: true,
|
|
359
|
+
serialize: true,
|
|
360
|
+
write: {
|
|
361
|
+
trace: (o) => console.trace(formatBrowserLog(o)),
|
|
362
|
+
debug: (o) => console.debug(formatBrowserLog(o)),
|
|
363
|
+
info: (o) => console.info(formatBrowserLog(o)),
|
|
364
|
+
warn: (o) => console.warn(formatBrowserLog(o)),
|
|
365
|
+
error: (o) => console.error(formatBrowserLog(o)),
|
|
366
|
+
fatal: (o) => console.error(formatBrowserLog(o))
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
if (prettyPrint && typeof window === "undefined") {
|
|
371
|
+
pinoConfig.transport = {
|
|
372
|
+
target: "pino-pretty",
|
|
373
|
+
options: {
|
|
374
|
+
colorize: true,
|
|
375
|
+
translateTime: "HH:MM:ss Z",
|
|
376
|
+
ignore: "pid,hostname"
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
const pinoLogger = (0, import_pino.default)(pinoConfig);
|
|
381
|
+
return new PinoLogger(pinoLogger);
|
|
382
|
+
}
|
|
383
|
+
function formatBrowserLog(logObj) {
|
|
384
|
+
const { level, time, msg, name, args, error, ...rest } = logObj;
|
|
385
|
+
let message = `[${name}] ${msg}`;
|
|
386
|
+
if (args && args.length > 0) {
|
|
387
|
+
message += ` ${args.map(
|
|
388
|
+
(arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)
|
|
389
|
+
).join(" ")}`;
|
|
390
|
+
}
|
|
391
|
+
if (error) {
|
|
392
|
+
message += ` Error: ${error.message}`;
|
|
393
|
+
if (error.stack) {
|
|
394
|
+
message += `
|
|
395
|
+
${error.stack}`;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (Object.keys(rest).length > 0) {
|
|
399
|
+
message += ` ${JSON.stringify(rest)}`;
|
|
400
|
+
}
|
|
401
|
+
return message;
|
|
402
|
+
}
|
|
403
|
+
var logger = createLogger({
|
|
404
|
+
enabled: true,
|
|
405
|
+
level: "info",
|
|
406
|
+
prettyPrint: false
|
|
407
|
+
});
|
|
408
|
+
function createAdapterLogger(adapterName, config = {}) {
|
|
409
|
+
const baseLogger = createLogger(config);
|
|
410
|
+
return baseLogger.child({ adapter: adapterName });
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// src/adapters/base-adapter.ts
|
|
414
|
+
var BaseAdapter = class {
|
|
415
|
+
/**
|
|
416
|
+
* Constructor
|
|
417
|
+
* @param config Configuration for the adapter
|
|
418
|
+
*/
|
|
419
|
+
constructor(config = {}) {
|
|
420
|
+
/**
|
|
421
|
+
* Whether the adapter has been initialized
|
|
422
|
+
*/
|
|
423
|
+
this.initialized = false;
|
|
424
|
+
this.config = config;
|
|
425
|
+
const loggerConfig = {
|
|
426
|
+
enabled: config.enableDebugLogs ?? true,
|
|
427
|
+
level: config.logLevel ?? "info",
|
|
428
|
+
name: "@shopkit/analytics"
|
|
429
|
+
};
|
|
430
|
+
this.logger = createAdapterLogger("BaseAdapter", loggerConfig);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Initialize logger with proper adapter name
|
|
434
|
+
* Should be called by subclasses after name is available
|
|
435
|
+
*/
|
|
436
|
+
initializeLogger() {
|
|
437
|
+
const loggerConfig = {
|
|
438
|
+
enabled: this.config.enableDebugLogs ?? true,
|
|
439
|
+
level: this.config.logLevel ?? "info",
|
|
440
|
+
name: "@shopkit/analytics"
|
|
441
|
+
};
|
|
442
|
+
this.logger = createAdapterLogger(this.name, loggerConfig);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Check if the adapter is enabled
|
|
446
|
+
*/
|
|
447
|
+
isEnabled() {
|
|
448
|
+
return this.initialized;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Get a configuration value
|
|
452
|
+
* @param key The configuration key
|
|
453
|
+
* @param defaultValue The default value if the key is not found
|
|
454
|
+
*/
|
|
455
|
+
getConfig(key, defaultValue) {
|
|
456
|
+
return key in this.config ? this.config[key] : defaultValue;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Get affiliate parameters from session storage or custom implementation
|
|
460
|
+
* Override this method to provide your own affiliate tracking implementation
|
|
461
|
+
* @returns Affiliate parameters or null if not available
|
|
462
|
+
*/
|
|
463
|
+
getAffiliateParams() {
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Enhance event parameters with affiliate data
|
|
468
|
+
* @param params The original parameters
|
|
469
|
+
* @returns Parameters enhanced with affiliate data
|
|
470
|
+
*/
|
|
471
|
+
enhanceWithAffiliateParams(params) {
|
|
472
|
+
const affiliateParams = this.getAffiliateParams();
|
|
473
|
+
if (!affiliateParams) return params;
|
|
474
|
+
return {
|
|
475
|
+
...params,
|
|
476
|
+
// Add affiliate parameters
|
|
477
|
+
...affiliateParams
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// src/types.ts
|
|
483
|
+
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
484
|
+
EventType2["PRODUCT_VIEW"] = "product_view";
|
|
485
|
+
EventType2["STARTED_ORDER"] = "started_order";
|
|
486
|
+
EventType2["PAGE_VIEW"] = "page_view";
|
|
487
|
+
EventType2["BUTTON_CLICK"] = "button_click";
|
|
488
|
+
EventType2["FORM_SUBMISSION"] = "form_submission";
|
|
489
|
+
EventType2["VIEW_ITEM"] = "view_item";
|
|
490
|
+
EventType2["VIEWED_PRODUCT"] = "viewed_product";
|
|
491
|
+
EventType2["CHECKOUT_PAYMENT"] = "checkout_payment";
|
|
492
|
+
EventType2["COLLECTION_VIEW"] = "collection_view";
|
|
493
|
+
EventType2["ADD_TO_CART"] = "add_to_cart";
|
|
494
|
+
EventType2["REMOVE_FROM_CART"] = "remove_from_cart";
|
|
495
|
+
EventType2["CHECKOUT_STARTED"] = "checkout_started";
|
|
496
|
+
EventType2["CHECKOUT_COMPLETED"] = "checkout_completed";
|
|
497
|
+
EventType2["SEARCH"] = "search";
|
|
498
|
+
EventType2["CART_PAGE_LAND"] = "cart_page_land";
|
|
499
|
+
EventType2["CLOSE_CART"] = "close_cart";
|
|
500
|
+
EventType2["QUANTITY_CHANGE"] = "quantity_change";
|
|
501
|
+
EventType2["FILTER_APPLIED"] = "filter_applied";
|
|
502
|
+
EventType2["NEWSLETTER_SUBSCRIPTION"] = "newsletter_subscription";
|
|
503
|
+
EventType2["USER_SIGNUP"] = "user_signup";
|
|
504
|
+
EventType2["USER_LOGIN"] = "user_login";
|
|
505
|
+
EventType2["CUSTOM"] = "custom";
|
|
506
|
+
EventType2["USER_ENGAGEMENT"] = "user_engagement";
|
|
507
|
+
EventType2["SESSION_START"] = "session_start";
|
|
508
|
+
EventType2["FIRST_VISIT"] = "first_visit";
|
|
509
|
+
EventType2["SCROLL"] = "scroll";
|
|
510
|
+
EventType2["FORM_START"] = "form_start";
|
|
511
|
+
EventType2["ADD_PAYMENT_INFO"] = "add_payment_info";
|
|
512
|
+
EventType2["CART_VIEWED"] = "cart_viewed";
|
|
513
|
+
EventType2["PAGES_SCREENS_PER_SESSION"] = "pages_screens_per_session";
|
|
514
|
+
EventType2["VIEW_CONTENT"] = "view_content";
|
|
515
|
+
EventType2["PURCHASE"] = "purchase";
|
|
516
|
+
EventType2["VIEW_SEARCH_RESULTS"] = "view_search_results";
|
|
517
|
+
EventType2["ORDER_PLACED"] = "order_placed";
|
|
518
|
+
EventType2["BEGIN_CHECKOUT"] = "begin_checkout";
|
|
519
|
+
EventType2["ITEM_PURCHASED"] = "item_purchased";
|
|
520
|
+
EventType2["UPDATE_CART"] = "update_cart";
|
|
521
|
+
EventType2["CUSTOMER_REGISTERED"] = "customer_registered";
|
|
522
|
+
EventType2["CUSTOMER_LOGGED_IN"] = "customer_logged_in";
|
|
523
|
+
EventType2["SHOPIFY_CHECKOUT_UPDATED"] = "shopify_checkout_updated";
|
|
524
|
+
EventType2["SHOPIFY_ABANDONED_CHECKOUT"] = "shopify_abandoned_checkout";
|
|
525
|
+
EventType2["SHOPIFY_ORDER_FULFILLED"] = "shopify_order_fulfilled";
|
|
526
|
+
EventType2["SHOPIFY_CHECKOUT_STARTED"] = "shopify_checkout_started";
|
|
527
|
+
EventType2["SHOPIFY_ADD_TO_CART"] = "shopify_add_to_cart";
|
|
528
|
+
EventType2["SHOPIFY_REMOVED_FROM_CART"] = "shopify_removed_from_cart";
|
|
529
|
+
EventType2["SHOPIFY_UPDATE_CART"] = "shopify_update_cart";
|
|
530
|
+
EventType2["SPINFORM_RESULT"] = "spinform_result";
|
|
531
|
+
EventType2["COUPON_COPIED"] = "coupon_copied";
|
|
532
|
+
EventType2["STARTED_CHECKOUT_GK"] = "started_checkout_gk";
|
|
533
|
+
EventType2["MOBILE_ADDED_GK"] = "mobile_added_gk";
|
|
534
|
+
EventType2["ADDRESS_SELECTED_GK"] = "address_selected_gk";
|
|
535
|
+
EventType2["ADDRESS_COMPLETED_GK"] = "address_completed_gk";
|
|
536
|
+
EventType2["PAYMENT_METHOD_SELECTED_GK"] = "payment_method_selected_gk";
|
|
537
|
+
EventType2["PAYMENT_COMPLETED_GK"] = "payment_completed_gk";
|
|
538
|
+
EventType2["ORDER_SUCCESS"] = "order_success";
|
|
539
|
+
EventType2["ORDER_COMPLETED"] = "order_completed";
|
|
540
|
+
EventType2["PIN_CODE_ADDED_GK"] = "pin_code_added_gk";
|
|
541
|
+
EventType2["ADDRESS_ADDED_GK"] = "address_added_gk";
|
|
542
|
+
EventType2["KP_MP_PHONE_NUMBER_LOGGED_IN"] = "kp_mp_phone_number_logged_in";
|
|
543
|
+
EventType2["KP_PHONE_NUMBER_LOGGED_IN"] = "kp_phone_number_logged_in";
|
|
544
|
+
EventType2["KP_MP_SHOPIFY_LOGGED_IN"] = "kp_mp_shopify_logged_in";
|
|
545
|
+
EventType2["KP_MP_SUCCESSFULLY_LOGGED_OUT"] = "kp_mp_successfully_logged_out";
|
|
546
|
+
EventType2["KP_WHATSAPP_LOGGED_IN"] = "kp_whatsapp_logged_in";
|
|
547
|
+
EventType2["KP_MP_TRUECALLER_LOGGED_IN"] = "kp_mp_truecaller_logged_in";
|
|
548
|
+
EventType2["KP_MP_WHATSAPP_LOGGED_IN"] = "kp_mp_whatsapp_logged_in";
|
|
549
|
+
EventType2["KP_TRUECALLER_LOGGED_IN"] = "kp_truecaller_logged_in";
|
|
550
|
+
EventType2["KP_SHOPIFY_LOGGED_IN"] = "kp_shopify_logged_in";
|
|
551
|
+
EventType2["KP_SUCCESSFULLY_LOGGED_OUT"] = "kp_successfully_logged_out";
|
|
552
|
+
return EventType2;
|
|
553
|
+
})(EventType || {});
|
|
554
|
+
|
|
555
|
+
// src/adapters/pixel-adapter.ts
|
|
556
|
+
var PixelAdapter = class extends BaseAdapter {
|
|
557
|
+
constructor(config) {
|
|
558
|
+
super(config);
|
|
559
|
+
this.name = "FacebookPixel";
|
|
560
|
+
this.initializeLogger();
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Initialize the Facebook Pixel
|
|
564
|
+
*/
|
|
565
|
+
async initialize() {
|
|
566
|
+
if (this.initialized) {
|
|
567
|
+
this.logger.debug("Already initialized");
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
if (typeof window === "undefined") {
|
|
571
|
+
this.logger.debug("Skipping initialization on server");
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
if (!window.fbq) {
|
|
575
|
+
this.logger.warn(
|
|
576
|
+
"Facebook Pixel fbq not found. Make sure the script is loaded."
|
|
577
|
+
);
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
const pixelId = this.getConfig("pixelId");
|
|
581
|
+
this.logger.info("Successfully initialized", { pixelId: "***" });
|
|
582
|
+
this.initialized = true;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Track an event with Facebook Pixel
|
|
586
|
+
* @param event The event to track
|
|
587
|
+
*/
|
|
588
|
+
async trackEvent(event) {
|
|
589
|
+
if (!this.initialized || typeof window === "undefined" || !window.fbq) {
|
|
590
|
+
this.logger.warn(
|
|
591
|
+
"Cannot track event, adapter not initialized or fbq not available",
|
|
592
|
+
{
|
|
593
|
+
eventType: event.type,
|
|
594
|
+
initialized: this.initialized,
|
|
595
|
+
hasWindow: typeof window !== "undefined",
|
|
596
|
+
hasFbq: !!window?.fbq
|
|
597
|
+
}
|
|
598
|
+
);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
this.logger.debug("Tracking event", { eventType: event.type });
|
|
602
|
+
switch (event.type) {
|
|
603
|
+
case "page_view" /* PAGE_VIEW */:
|
|
604
|
+
this.trackPageView(event);
|
|
605
|
+
break;
|
|
606
|
+
case "view_content" /* VIEW_CONTENT */:
|
|
607
|
+
this.trackViewContent(event);
|
|
608
|
+
break;
|
|
609
|
+
case "product_view" /* PRODUCT_VIEW */:
|
|
610
|
+
this.trackProductView(event);
|
|
611
|
+
break;
|
|
612
|
+
case "add_to_cart" /* ADD_TO_CART */:
|
|
613
|
+
this.trackAddToCart(event);
|
|
614
|
+
break;
|
|
615
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
616
|
+
this.trackCheckoutStarted(event);
|
|
617
|
+
break;
|
|
618
|
+
case "checkout_completed" /* CHECKOUT_COMPLETED */:
|
|
619
|
+
this.trackCheckoutCompleted(event);
|
|
620
|
+
break;
|
|
621
|
+
case "purchase" /* PURCHASE */:
|
|
622
|
+
this.trackPurchase(event);
|
|
623
|
+
break;
|
|
624
|
+
case "add_payment_info" /* ADD_PAYMENT_INFO */:
|
|
625
|
+
this.trackAddPaymentInfo(event);
|
|
626
|
+
break;
|
|
627
|
+
case "search" /* SEARCH */:
|
|
628
|
+
this.trackSearch(event);
|
|
629
|
+
break;
|
|
630
|
+
default:
|
|
631
|
+
this.logger.debug("Unhandled event type", { eventType: event.type });
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Track a page view event
|
|
637
|
+
* @param event The page view event
|
|
638
|
+
*/
|
|
639
|
+
trackPageView(event) {
|
|
640
|
+
const params = this.enhanceWithAffiliateParams({});
|
|
641
|
+
window.fbq?.("track", "PageView", params);
|
|
642
|
+
this.logger.debug("PageView event tracked", { params });
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Track a product view event
|
|
646
|
+
* @param event The product view event
|
|
647
|
+
*/
|
|
648
|
+
trackProductView(event) {
|
|
649
|
+
const params = {
|
|
650
|
+
content_type: "product_group",
|
|
651
|
+
content_ids: [event.productId],
|
|
652
|
+
content_name: event.productName,
|
|
653
|
+
content_category: event.category,
|
|
654
|
+
value: event.price,
|
|
655
|
+
currency: event.currency || "INR"
|
|
656
|
+
};
|
|
657
|
+
window.fbq?.(
|
|
658
|
+
"track",
|
|
659
|
+
"ViewContent",
|
|
660
|
+
this.enhanceWithAffiliateParams(params)
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Track an add to cart event
|
|
665
|
+
* @param event The add to cart event
|
|
666
|
+
*/
|
|
667
|
+
trackAddToCart(event) {
|
|
668
|
+
const params = {
|
|
669
|
+
content_type: "product_group",
|
|
670
|
+
content_ids: [event.productId],
|
|
671
|
+
content_name: event.productName,
|
|
672
|
+
value: event.price,
|
|
673
|
+
currency: event.currency || "INR"
|
|
674
|
+
};
|
|
675
|
+
const enhancedParams = this.enhanceWithAffiliateParams(params);
|
|
676
|
+
window.fbq?.("track", "AddToCart", enhancedParams);
|
|
677
|
+
this.logger.debug("AddToCart event tracked", { params: enhancedParams });
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Track a checkout started event
|
|
681
|
+
* @param event The checkout started event
|
|
682
|
+
*/
|
|
683
|
+
trackCheckoutStarted(event) {
|
|
684
|
+
const params = {
|
|
685
|
+
content_ids: event.items.map((item) => item.productId),
|
|
686
|
+
content_type: "product_group",
|
|
687
|
+
value: event.cartValue,
|
|
688
|
+
currency: event.currency || "INR",
|
|
689
|
+
num_items: event.itemCount,
|
|
690
|
+
contents: event.items.map((item) => ({
|
|
691
|
+
id: item.productId,
|
|
692
|
+
quantity: item.quantity,
|
|
693
|
+
item_price: item.price
|
|
694
|
+
}))
|
|
695
|
+
};
|
|
696
|
+
window.fbq?.(
|
|
697
|
+
"track",
|
|
698
|
+
"InitiateCheckout",
|
|
699
|
+
this.enhanceWithAffiliateParams(params)
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Track a checkout completed event
|
|
704
|
+
* @param event The checkout completed event
|
|
705
|
+
*/
|
|
706
|
+
trackCheckoutCompleted(event) {
|
|
707
|
+
const params = {
|
|
708
|
+
value: event.cartValue,
|
|
709
|
+
currency: event.currency || "INR",
|
|
710
|
+
content_type: "product_group",
|
|
711
|
+
content_ids: event.items.map((item) => item.productId),
|
|
712
|
+
num_items: event.itemCount,
|
|
713
|
+
contents: event.items.map((item) => ({
|
|
714
|
+
id: item.productId,
|
|
715
|
+
quantity: item.quantity,
|
|
716
|
+
item_price: item.price
|
|
717
|
+
}))
|
|
718
|
+
};
|
|
719
|
+
window.fbq?.("track", "Purchase", this.enhanceWithAffiliateParams(params));
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Track a search event
|
|
723
|
+
* @param event The search event
|
|
724
|
+
*/
|
|
725
|
+
trackSearch(event) {
|
|
726
|
+
const params = {
|
|
727
|
+
search_string: event.searchTerm,
|
|
728
|
+
content_category: "product",
|
|
729
|
+
content_ids: event.content_ids || []
|
|
730
|
+
};
|
|
731
|
+
window.fbq?.("track", "Search", this.enhanceWithAffiliateParams(params));
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Track an add payment info event
|
|
735
|
+
* @param event The add payment info event
|
|
736
|
+
*/
|
|
737
|
+
trackAddPaymentInfo(event) {
|
|
738
|
+
const params = {
|
|
739
|
+
value: event.cartValue,
|
|
740
|
+
currency: event.currency || "INR",
|
|
741
|
+
content_type: "product_group",
|
|
742
|
+
content_ids: event.items.map((item) => item.productId),
|
|
743
|
+
contents: event.items.map((item) => ({
|
|
744
|
+
id: item.productId,
|
|
745
|
+
quantity: item.quantity,
|
|
746
|
+
item_price: item.price
|
|
747
|
+
})),
|
|
748
|
+
payment_type: event.paymentType || ""
|
|
749
|
+
};
|
|
750
|
+
window.fbq?.(
|
|
751
|
+
"track",
|
|
752
|
+
"AddPaymentInfo",
|
|
753
|
+
this.enhanceWithAffiliateParams(params)
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Track a view content event
|
|
758
|
+
* @param event The view content event
|
|
759
|
+
*/
|
|
760
|
+
trackViewContent(event) {
|
|
761
|
+
const params = {
|
|
762
|
+
content_type: event.content_type || "product",
|
|
763
|
+
content_ids: event.content_ids || [],
|
|
764
|
+
content_name: event.content_name || "",
|
|
765
|
+
content_category: event.content_category || "",
|
|
766
|
+
value: event.value || 0,
|
|
767
|
+
currency: event.currency || "INR"
|
|
768
|
+
};
|
|
769
|
+
window.fbq?.(
|
|
770
|
+
"track",
|
|
771
|
+
"ViewContent",
|
|
772
|
+
this.enhanceWithAffiliateParams(params)
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Track a purchase event
|
|
777
|
+
* @param event The purchase event
|
|
778
|
+
*/
|
|
779
|
+
trackPurchase(event) {
|
|
780
|
+
const params = {
|
|
781
|
+
value: event.value,
|
|
782
|
+
currency: event.currency || "INR",
|
|
783
|
+
content_type: event.content_type || "product_group",
|
|
784
|
+
content_ids: event.content_ids || [],
|
|
785
|
+
num_items: event.num_items || 1,
|
|
786
|
+
contents: event.contents || []
|
|
787
|
+
};
|
|
788
|
+
window.fbq?.("track", "Purchase", this.enhanceWithAffiliateParams(params));
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Convert an event to Facebook Pixel parameters
|
|
792
|
+
* @param event The event to convert
|
|
793
|
+
*/
|
|
794
|
+
eventToParams(event) {
|
|
795
|
+
const { type, timestamp, ...params } = event;
|
|
796
|
+
return this.enhanceWithAffiliateParams(params);
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
// src/adapters/google-adapter.ts
|
|
801
|
+
var GoogleAdapter = class extends BaseAdapter {
|
|
802
|
+
constructor(config) {
|
|
803
|
+
super(config);
|
|
804
|
+
this.name = "GoogleAnalytics";
|
|
805
|
+
this.initializeLogger();
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Initialize Google Analytics adapter
|
|
809
|
+
* This just checks if gtag is available
|
|
810
|
+
*/
|
|
811
|
+
isEnabled() {
|
|
812
|
+
const enabled = this.initialized && typeof window !== "undefined" && !!window.gtag;
|
|
813
|
+
this.logger.debug("Checking if enabled", {
|
|
814
|
+
initialized: this.initialized,
|
|
815
|
+
hasWindow: typeof window !== "undefined",
|
|
816
|
+
hasGtag: !!window?.gtag,
|
|
817
|
+
enabled
|
|
818
|
+
});
|
|
819
|
+
return enabled;
|
|
820
|
+
}
|
|
821
|
+
async initialize() {
|
|
822
|
+
this.logger.info("Starting initialization");
|
|
823
|
+
if (this.initialized) {
|
|
824
|
+
this.logger.debug("Already initialized");
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
if (typeof window === "undefined") {
|
|
828
|
+
this.logger.debug("Skipping initialization on server");
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
const measurementId = this.getConfig("measurementId");
|
|
832
|
+
this.logger.info("Using measurement ID", { measurementId });
|
|
833
|
+
if (!window.gtag) {
|
|
834
|
+
this.logger.warn(
|
|
835
|
+
"Google Analytics gtag not found. Make sure the script is loaded."
|
|
836
|
+
);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
this.initialized = true;
|
|
840
|
+
this.logger.info("Successfully initialized", { measurementId });
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Track an event with Google Analytics
|
|
844
|
+
* @param event The event to track
|
|
845
|
+
*/
|
|
846
|
+
async trackEvent(event) {
|
|
847
|
+
this.logger.debug("Attempting to track event", {
|
|
848
|
+
initialized: this.initialized,
|
|
849
|
+
hasWindow: typeof window !== "undefined",
|
|
850
|
+
hasGtag: !!window?.gtag,
|
|
851
|
+
eventType: event.type
|
|
852
|
+
});
|
|
853
|
+
if (!this.initialized || typeof window === "undefined" || !window.gtag) {
|
|
854
|
+
this.logger.warn(
|
|
855
|
+
"Cannot track event, adapter not initialized or gtag not available",
|
|
856
|
+
{
|
|
857
|
+
eventType: event.type,
|
|
858
|
+
initialized: this.initialized,
|
|
859
|
+
hasWindow: typeof window !== "undefined",
|
|
860
|
+
hasGtag: !!window?.gtag
|
|
861
|
+
}
|
|
862
|
+
);
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
const measurementId = this.getConfig("measurementId");
|
|
866
|
+
this.logger.info("Tracking event", {
|
|
867
|
+
eventType: event.type,
|
|
868
|
+
measurementId
|
|
869
|
+
});
|
|
870
|
+
switch (event.type) {
|
|
871
|
+
case "page_view" /* PAGE_VIEW */:
|
|
872
|
+
this.trackPageView(event, measurementId);
|
|
873
|
+
break;
|
|
874
|
+
case "user_engagement" /* USER_ENGAGEMENT */:
|
|
875
|
+
this.trackUserEngagement();
|
|
876
|
+
break;
|
|
877
|
+
case "session_start" /* SESSION_START */:
|
|
878
|
+
this.trackSessionStart();
|
|
879
|
+
break;
|
|
880
|
+
case "first_visit" /* FIRST_VISIT */:
|
|
881
|
+
this.trackFirstVisit();
|
|
882
|
+
break;
|
|
883
|
+
case "view_item" /* VIEW_ITEM */:
|
|
884
|
+
this.trackViewItem(event);
|
|
885
|
+
break;
|
|
886
|
+
case "viewed_product" /* VIEWED_PRODUCT */:
|
|
887
|
+
this.trackViewedProduct(event);
|
|
888
|
+
break;
|
|
889
|
+
case "checkout_payment" /* CHECKOUT_PAYMENT */:
|
|
890
|
+
this.trackCheckoutPayment(event);
|
|
891
|
+
break;
|
|
892
|
+
case "scroll" /* SCROLL */:
|
|
893
|
+
this.trackScroll();
|
|
894
|
+
break;
|
|
895
|
+
case "add_to_cart" /* ADD_TO_CART */:
|
|
896
|
+
case "shopify_add_to_cart" /* SHOPIFY_ADD_TO_CART */:
|
|
897
|
+
this.trackAddToCart(event);
|
|
898
|
+
break;
|
|
899
|
+
case "form_start" /* FORM_START */:
|
|
900
|
+
this.trackFormStart();
|
|
901
|
+
break;
|
|
902
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
903
|
+
this.trackCheckoutStarted(event);
|
|
904
|
+
break;
|
|
905
|
+
case "form_submission" /* FORM_SUBMISSION */:
|
|
906
|
+
this.trackFormSubmission(event);
|
|
907
|
+
break;
|
|
908
|
+
case "search" /* SEARCH */:
|
|
909
|
+
this.trackSearch(event);
|
|
910
|
+
break;
|
|
911
|
+
case "checkout_completed" /* CHECKOUT_COMPLETED */:
|
|
912
|
+
this.trackCheckoutCompleted(event);
|
|
913
|
+
break;
|
|
914
|
+
case "add_payment_info" /* ADD_PAYMENT_INFO */:
|
|
915
|
+
this.trackAddPaymentInfo(event);
|
|
916
|
+
break;
|
|
917
|
+
case "view_content" /* VIEW_CONTENT */:
|
|
918
|
+
this.trackViewContent(event);
|
|
919
|
+
break;
|
|
920
|
+
case "purchase" /* PURCHASE */:
|
|
921
|
+
this.trackPurchase(event);
|
|
922
|
+
break;
|
|
923
|
+
case "view_search_results" /* VIEW_SEARCH_RESULTS */:
|
|
924
|
+
this.trackViewSearchResults(event);
|
|
925
|
+
break;
|
|
926
|
+
case "order_placed" /* ORDER_PLACED */:
|
|
927
|
+
this.trackOrderPlaced(event);
|
|
928
|
+
break;
|
|
929
|
+
case "begin_checkout" /* BEGIN_CHECKOUT */:
|
|
930
|
+
this.trackBeginCheckout(event);
|
|
931
|
+
break;
|
|
932
|
+
case "custom" /* CUSTOM */:
|
|
933
|
+
this.trackCustomEvent(event);
|
|
934
|
+
break;
|
|
935
|
+
default: {
|
|
936
|
+
const params = this.eventToParams(event);
|
|
937
|
+
window.gtag(
|
|
938
|
+
"event",
|
|
939
|
+
event.type,
|
|
940
|
+
this.enhanceWithAffiliateParams(params)
|
|
941
|
+
);
|
|
942
|
+
break;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Track a page view event
|
|
948
|
+
* @param event The page view event
|
|
949
|
+
* @param measurementId The Google Analytics measurement ID
|
|
950
|
+
*/
|
|
951
|
+
trackPageView(event, measurementId) {
|
|
952
|
+
const params = {
|
|
953
|
+
page_path: event.path,
|
|
954
|
+
page_title: event.title || document.title,
|
|
955
|
+
page_location: event.page_location || window.location.href,
|
|
956
|
+
page_referrer: event.page_referrer || document.referrer || void 0,
|
|
957
|
+
ga_session_id: event.ga_session_id || "",
|
|
958
|
+
ga_session_number: event.ga_session_number || "",
|
|
959
|
+
gclid: event.gclid || "",
|
|
960
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
961
|
+
campaign: event.campaign || "",
|
|
962
|
+
campaign_id: event.campaign_id || "",
|
|
963
|
+
content: event.content || "",
|
|
964
|
+
debug_mode: event.debug_mode,
|
|
965
|
+
medium: event.medium || "",
|
|
966
|
+
source: event.page_source || "",
|
|
967
|
+
page_term: event.page_term || "",
|
|
968
|
+
ignore_referrer: event.ignore_referrer,
|
|
969
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
970
|
+
batch_page_id: event.batch_page_id || "",
|
|
971
|
+
user_id: event.user_id,
|
|
972
|
+
user_properties: event.user_properties,
|
|
973
|
+
session_engaged: event.session_engaged
|
|
974
|
+
};
|
|
975
|
+
window.gtag?.(
|
|
976
|
+
"event",
|
|
977
|
+
"page_view",
|
|
978
|
+
this.enhanceWithAffiliateParams(params)
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
trackUserEngagement() {
|
|
982
|
+
const params = {
|
|
983
|
+
batch_ordering_id: "",
|
|
984
|
+
batch_page_id: "",
|
|
985
|
+
campaign: "",
|
|
986
|
+
ga_session_id: "",
|
|
987
|
+
ga_session_number: "",
|
|
988
|
+
gclid: "",
|
|
989
|
+
ignore_referrer: "",
|
|
990
|
+
medium: "",
|
|
991
|
+
page_location: window.location.href,
|
|
992
|
+
page_path: window.location.pathname,
|
|
993
|
+
page_referrer: document.referrer,
|
|
994
|
+
page_title: document.title,
|
|
995
|
+
source: "",
|
|
996
|
+
srsltid: "",
|
|
997
|
+
term: ""
|
|
998
|
+
};
|
|
999
|
+
window.gtag?.(
|
|
1000
|
+
"event",
|
|
1001
|
+
"user_engagement",
|
|
1002
|
+
this.enhanceWithAffiliateParams(params)
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
trackSessionStart() {
|
|
1006
|
+
const params = {
|
|
1007
|
+
batch_ordering_id: "",
|
|
1008
|
+
batch_page_id: "",
|
|
1009
|
+
campaign: "",
|
|
1010
|
+
campaign_id: "",
|
|
1011
|
+
content: "",
|
|
1012
|
+
ga_session_id: "",
|
|
1013
|
+
ga_session_number: "",
|
|
1014
|
+
gclid: "",
|
|
1015
|
+
ignore_referrer: "",
|
|
1016
|
+
medium: "",
|
|
1017
|
+
page_location: window.location.href,
|
|
1018
|
+
page_path: window.location.pathname,
|
|
1019
|
+
page_referrer: document.referrer,
|
|
1020
|
+
page_title: document.title,
|
|
1021
|
+
source: "",
|
|
1022
|
+
srsltid: "",
|
|
1023
|
+
term: ""
|
|
1024
|
+
};
|
|
1025
|
+
window.gtag?.(
|
|
1026
|
+
"event",
|
|
1027
|
+
"session_start",
|
|
1028
|
+
this.enhanceWithAffiliateParams(params)
|
|
1029
|
+
);
|
|
1030
|
+
}
|
|
1031
|
+
trackFirstVisit() {
|
|
1032
|
+
const params = {
|
|
1033
|
+
batch_ordering_id: "",
|
|
1034
|
+
batch_page_id: "",
|
|
1035
|
+
campaign: "",
|
|
1036
|
+
campaign_id: "",
|
|
1037
|
+
content: "",
|
|
1038
|
+
debug_mode: "",
|
|
1039
|
+
engagement_time_msec: 0,
|
|
1040
|
+
entrances: 1,
|
|
1041
|
+
ga_session_id: "",
|
|
1042
|
+
ga_session_number: "",
|
|
1043
|
+
gclid: "",
|
|
1044
|
+
ignore_referrer: "",
|
|
1045
|
+
medium: "",
|
|
1046
|
+
page_location: window.location.href,
|
|
1047
|
+
page_path: window.location.pathname,
|
|
1048
|
+
page_referrer: document.referrer,
|
|
1049
|
+
page_title: document.title,
|
|
1050
|
+
page_source: "",
|
|
1051
|
+
page_term: ""
|
|
1052
|
+
};
|
|
1053
|
+
window.gtag?.(
|
|
1054
|
+
"event",
|
|
1055
|
+
"first_visit",
|
|
1056
|
+
this.enhanceWithAffiliateParams(params)
|
|
1057
|
+
);
|
|
1058
|
+
}
|
|
1059
|
+
trackViewItem(event) {
|
|
1060
|
+
window.gtag?.(
|
|
1061
|
+
"event",
|
|
1062
|
+
"view_item",
|
|
1063
|
+
this.enhanceWithAffiliateParams({
|
|
1064
|
+
currency: event.currency,
|
|
1065
|
+
value: event.value,
|
|
1066
|
+
items: event.items
|
|
1067
|
+
})
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
trackScroll() {
|
|
1071
|
+
const params = {
|
|
1072
|
+
batch_ordering_id: "",
|
|
1073
|
+
batch_page_id: "",
|
|
1074
|
+
engagement_time_msec: void 0,
|
|
1075
|
+
ga_session_id: "",
|
|
1076
|
+
ga_session_number: "",
|
|
1077
|
+
ignore_referrer: void 0,
|
|
1078
|
+
page_location: window.location.href,
|
|
1079
|
+
page_path: window.location.pathname,
|
|
1080
|
+
page_referrer: document.referrer,
|
|
1081
|
+
page_title: document.title,
|
|
1082
|
+
percent_scrolled: 90
|
|
1083
|
+
// or dynamically captured
|
|
1084
|
+
};
|
|
1085
|
+
window.gtag?.("event", "scroll", this.enhanceWithAffiliateParams(params));
|
|
1086
|
+
}
|
|
1087
|
+
trackCheckoutPayment(event) {
|
|
1088
|
+
window.gtag?.(
|
|
1089
|
+
"event",
|
|
1090
|
+
"checkout_payment",
|
|
1091
|
+
this.enhanceWithAffiliateParams({
|
|
1092
|
+
currency: event.currency,
|
|
1093
|
+
value: event.cartValue,
|
|
1094
|
+
items: event.items.map((item) => ({
|
|
1095
|
+
item_id: item.productId,
|
|
1096
|
+
item_name: item.productName,
|
|
1097
|
+
price: item.price,
|
|
1098
|
+
quantity: item.quantity
|
|
1099
|
+
}))
|
|
1100
|
+
})
|
|
1101
|
+
);
|
|
1102
|
+
}
|
|
1103
|
+
trackViewedProduct(event) {
|
|
1104
|
+
window.gtag?.(
|
|
1105
|
+
"event",
|
|
1106
|
+
"viewed_product",
|
|
1107
|
+
this.enhanceWithAffiliateParams({
|
|
1108
|
+
currency: event.currency,
|
|
1109
|
+
value: event.price,
|
|
1110
|
+
items: [
|
|
1111
|
+
{
|
|
1112
|
+
item_id: event.productId,
|
|
1113
|
+
item_name: event.productName,
|
|
1114
|
+
price: event.price,
|
|
1115
|
+
currency: event.currency
|
|
1116
|
+
}
|
|
1117
|
+
],
|
|
1118
|
+
view_duration: event.viewDuration
|
|
1119
|
+
})
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
trackAddToCart(event) {
|
|
1123
|
+
this.logger.debug("Processing add_to_cart event", { event });
|
|
1124
|
+
const params = {
|
|
1125
|
+
currency: event.currency || "INR",
|
|
1126
|
+
value: event.price * (event.quantity || 1),
|
|
1127
|
+
// Calculate total value
|
|
1128
|
+
items: [
|
|
1129
|
+
{
|
|
1130
|
+
item_id: event.productId,
|
|
1131
|
+
item_name: event.productName,
|
|
1132
|
+
price: event.price,
|
|
1133
|
+
quantity: event.quantity || 1,
|
|
1134
|
+
item_variant: event.variant
|
|
1135
|
+
}
|
|
1136
|
+
],
|
|
1137
|
+
// GA4-specific parameters
|
|
1138
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
1139
|
+
batch_page_id: event.batch_page_id || "",
|
|
1140
|
+
campaign: event.campaign || "",
|
|
1141
|
+
ga_session_id: event.ga_session_id || "",
|
|
1142
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
1143
|
+
session_engaged: event.session_engaged,
|
|
1144
|
+
page_title: event.page_title || document.title,
|
|
1145
|
+
page_location: event.page_location || window.location.href,
|
|
1146
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
1147
|
+
user_id: event.user_id,
|
|
1148
|
+
user_properties: event.user_properties
|
|
1149
|
+
};
|
|
1150
|
+
const enhancedParams = this.enhanceWithAffiliateParams(params);
|
|
1151
|
+
this.logger.debug("Sending add_to_cart event to gtag", {
|
|
1152
|
+
params: enhancedParams
|
|
1153
|
+
});
|
|
1154
|
+
window.gtag?.("event", "add_to_cart", enhancedParams);
|
|
1155
|
+
}
|
|
1156
|
+
trackFormStart() {
|
|
1157
|
+
const params = {
|
|
1158
|
+
batch_ordering_id: "",
|
|
1159
|
+
batch_page_id: "",
|
|
1160
|
+
engagement_time_msec: void 0,
|
|
1161
|
+
first_field_id: "",
|
|
1162
|
+
first_field_name: "",
|
|
1163
|
+
first_field_position: "",
|
|
1164
|
+
first_field_type: "",
|
|
1165
|
+
form_destination: "",
|
|
1166
|
+
form_length: "",
|
|
1167
|
+
form_id: "",
|
|
1168
|
+
ga_session_id: "",
|
|
1169
|
+
ga_session_number: "",
|
|
1170
|
+
ignore_referrer: void 0,
|
|
1171
|
+
page_location: window.location.href,
|
|
1172
|
+
page_referrer: document.referrer,
|
|
1173
|
+
page_title: document.title
|
|
1174
|
+
};
|
|
1175
|
+
window.gtag?.(
|
|
1176
|
+
"event",
|
|
1177
|
+
"form_start",
|
|
1178
|
+
this.enhanceWithAffiliateParams(params)
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
trackCheckoutStarted(event) {
|
|
1182
|
+
const params = {
|
|
1183
|
+
batch_ordering_id: "",
|
|
1184
|
+
batch_page_id: "",
|
|
1185
|
+
currency: event.currency || "INR",
|
|
1186
|
+
ecomm_pagetype: "",
|
|
1187
|
+
ecomm_prodid: "",
|
|
1188
|
+
ecomm_totalvalue: event.cartValue,
|
|
1189
|
+
value: event.cartValue,
|
|
1190
|
+
engagement_time_msec: void 0,
|
|
1191
|
+
ga_session_id: "",
|
|
1192
|
+
ga_session_number: "",
|
|
1193
|
+
ignore_referrer: void 0,
|
|
1194
|
+
page_location: window.location.href,
|
|
1195
|
+
page_referrer: document.referrer,
|
|
1196
|
+
page_title: document.title,
|
|
1197
|
+
items: event.items.map((item) => ({
|
|
1198
|
+
item_id: item.productId,
|
|
1199
|
+
item_name: item.productName,
|
|
1200
|
+
price: item.price,
|
|
1201
|
+
quantity: item.quantity,
|
|
1202
|
+
item_variant: item.variant
|
|
1203
|
+
}))
|
|
1204
|
+
};
|
|
1205
|
+
window.gtag?.(
|
|
1206
|
+
"event",
|
|
1207
|
+
"begin_checkout",
|
|
1208
|
+
this.enhanceWithAffiliateParams(params)
|
|
1209
|
+
);
|
|
1210
|
+
}
|
|
1211
|
+
trackFormSubmission(event) {
|
|
1212
|
+
const params = {
|
|
1213
|
+
batch_ordering_id: "",
|
|
1214
|
+
batch_page_id: "",
|
|
1215
|
+
engagement_time_msec: void 0,
|
|
1216
|
+
form_destination: "",
|
|
1217
|
+
form_length: "",
|
|
1218
|
+
form_id: event.formId,
|
|
1219
|
+
ga_session_id: "",
|
|
1220
|
+
ga_session_number: "",
|
|
1221
|
+
ignore_referrer: void 0,
|
|
1222
|
+
page_location: window.location.href,
|
|
1223
|
+
page_referrer: document.referrer,
|
|
1224
|
+
page_title: document.title
|
|
1225
|
+
};
|
|
1226
|
+
window.gtag?.(
|
|
1227
|
+
"event",
|
|
1228
|
+
"form_submit",
|
|
1229
|
+
this.enhanceWithAffiliateParams(params)
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
trackSearch(event) {
|
|
1233
|
+
const params = {
|
|
1234
|
+
batch_ordering_id: "",
|
|
1235
|
+
batch_page_id: "",
|
|
1236
|
+
engagement_time_msec: void 0,
|
|
1237
|
+
ga_session_id: "",
|
|
1238
|
+
ga_session_number: "",
|
|
1239
|
+
ignore_referrer: void 0,
|
|
1240
|
+
page_location: window.location.href,
|
|
1241
|
+
page_referrer: document.referrer,
|
|
1242
|
+
page_title: document.title,
|
|
1243
|
+
search_term: event.searchTerm
|
|
1244
|
+
};
|
|
1245
|
+
window.gtag?.("event", "search", this.enhanceWithAffiliateParams(params));
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Track a checkout completed event
|
|
1249
|
+
* @param event The checkout completed event
|
|
1250
|
+
*/
|
|
1251
|
+
trackCheckoutCompleted(event) {
|
|
1252
|
+
const params = {
|
|
1253
|
+
transaction_id: event.orderId,
|
|
1254
|
+
currency: event.currency || "INR",
|
|
1255
|
+
value: event.cartValue,
|
|
1256
|
+
items: event.items.map((item) => ({
|
|
1257
|
+
item_id: item.productId,
|
|
1258
|
+
item_name: item.productName,
|
|
1259
|
+
price: item.price,
|
|
1260
|
+
quantity: item.quantity,
|
|
1261
|
+
item_variant: item.variant
|
|
1262
|
+
}))
|
|
1263
|
+
};
|
|
1264
|
+
window.gtag?.("event", "purchase", this.enhanceWithAffiliateParams(params));
|
|
1265
|
+
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Track a custom event
|
|
1268
|
+
* @param event The custom event
|
|
1269
|
+
*/
|
|
1270
|
+
trackCustomEvent(event) {
|
|
1271
|
+
const params = event.properties || {};
|
|
1272
|
+
window.gtag?.("event", event.name, this.enhanceWithAffiliateParams(params));
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Track an add payment info event
|
|
1276
|
+
* @param event The add payment info event
|
|
1277
|
+
*/
|
|
1278
|
+
trackAddPaymentInfo(event) {
|
|
1279
|
+
const params = {
|
|
1280
|
+
currency: event.currency || "INR",
|
|
1281
|
+
value: event.cartValue,
|
|
1282
|
+
payment_type: event.paymentType || "",
|
|
1283
|
+
items: event.items.map((item) => ({
|
|
1284
|
+
item_id: item.productId,
|
|
1285
|
+
item_name: item.productName,
|
|
1286
|
+
price: item.price,
|
|
1287
|
+
quantity: item.quantity,
|
|
1288
|
+
item_variant: item.variant
|
|
1289
|
+
}))
|
|
1290
|
+
};
|
|
1291
|
+
window.gtag?.(
|
|
1292
|
+
"event",
|
|
1293
|
+
"add_payment_info",
|
|
1294
|
+
this.enhanceWithAffiliateParams(params)
|
|
1295
|
+
);
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Track a view content event
|
|
1299
|
+
* @param event The view content event
|
|
1300
|
+
*/
|
|
1301
|
+
trackViewContent(event) {
|
|
1302
|
+
const params = {
|
|
1303
|
+
currency: event.currency || "USD",
|
|
1304
|
+
value: event.value || 0,
|
|
1305
|
+
items: event.items?.map((item) => ({
|
|
1306
|
+
item_id: item.item_id,
|
|
1307
|
+
item_name: item.item_name,
|
|
1308
|
+
item_category: item.item_category,
|
|
1309
|
+
item_category2: item.item_category2,
|
|
1310
|
+
item_category3: item.item_category3,
|
|
1311
|
+
item_category4: item.item_category4,
|
|
1312
|
+
item_category5: item.item_category5,
|
|
1313
|
+
item_brand: item.item_brand,
|
|
1314
|
+
item_variant: item.item_variant,
|
|
1315
|
+
price: item.price,
|
|
1316
|
+
quantity: item.quantity
|
|
1317
|
+
})) || [],
|
|
1318
|
+
// GA4-specific parameters
|
|
1319
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
1320
|
+
batch_page_id: event.batch_page_id || "",
|
|
1321
|
+
campaign: event.campaign || "",
|
|
1322
|
+
ga_session_id: event.ga_session_id || "",
|
|
1323
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
1324
|
+
session_engaged: event.session_engaged,
|
|
1325
|
+
page_title: event.page_title || document.title,
|
|
1326
|
+
page_location: event.page_location || window.location.href,
|
|
1327
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
1328
|
+
user_id: event.user_id,
|
|
1329
|
+
user_properties: event.user_properties
|
|
1330
|
+
};
|
|
1331
|
+
window.gtag?.(
|
|
1332
|
+
"event",
|
|
1333
|
+
"view_item",
|
|
1334
|
+
this.enhanceWithAffiliateParams(params)
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
/**
|
|
1338
|
+
* Track a purchase event
|
|
1339
|
+
* @param event The purchase event
|
|
1340
|
+
*/
|
|
1341
|
+
trackPurchase(event) {
|
|
1342
|
+
const params = {
|
|
1343
|
+
transaction_id: event.transaction_id,
|
|
1344
|
+
value: event.value,
|
|
1345
|
+
currency: event.currency || "USD",
|
|
1346
|
+
coupon: event.coupon,
|
|
1347
|
+
shipping: event.shipping,
|
|
1348
|
+
tax: event.tax,
|
|
1349
|
+
items: event.items?.map((item) => ({
|
|
1350
|
+
item_id: item.item_id,
|
|
1351
|
+
item_name: item.item_name,
|
|
1352
|
+
item_category: item.item_category,
|
|
1353
|
+
item_category2: item.item_category2,
|
|
1354
|
+
item_category3: item.item_category3,
|
|
1355
|
+
item_category4: item.item_category4,
|
|
1356
|
+
item_category5: item.item_category5,
|
|
1357
|
+
item_brand: item.item_brand,
|
|
1358
|
+
item_variant: item.item_variant,
|
|
1359
|
+
price: item.price,
|
|
1360
|
+
quantity: item.quantity
|
|
1361
|
+
})) || [],
|
|
1362
|
+
// GA4-specific parameters
|
|
1363
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
1364
|
+
batch_page_id: event.batch_page_id || "",
|
|
1365
|
+
campaign: event.campaign || "",
|
|
1366
|
+
ga_session_id: event.ga_session_id || "",
|
|
1367
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
1368
|
+
session_engaged: event.session_engaged,
|
|
1369
|
+
page_title: event.page_title || document.title,
|
|
1370
|
+
page_location: event.page_location || window.location.href,
|
|
1371
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
1372
|
+
user_id: event.user_id,
|
|
1373
|
+
user_properties: event.user_properties
|
|
1374
|
+
};
|
|
1375
|
+
window.gtag?.("event", "purchase", this.enhanceWithAffiliateParams(params));
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Track a view search results event
|
|
1379
|
+
* @param event The view search results event
|
|
1380
|
+
*/
|
|
1381
|
+
trackViewSearchResults(event) {
|
|
1382
|
+
const params = {
|
|
1383
|
+
search_term: event.search_term,
|
|
1384
|
+
// GA4-specific parameters
|
|
1385
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
1386
|
+
batch_page_id: event.batch_page_id || "",
|
|
1387
|
+
campaign: event.campaign || "",
|
|
1388
|
+
ga_session_id: event.ga_session_id || "",
|
|
1389
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
1390
|
+
session_engaged: event.session_engaged,
|
|
1391
|
+
page_title: event.page_title || document.title,
|
|
1392
|
+
page_location: event.page_location || window.location.href,
|
|
1393
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
1394
|
+
user_id: event.user_id,
|
|
1395
|
+
user_properties: event.user_properties
|
|
1396
|
+
};
|
|
1397
|
+
window.gtag?.(
|
|
1398
|
+
"event",
|
|
1399
|
+
"view_search_results",
|
|
1400
|
+
this.enhanceWithAffiliateParams(params)
|
|
1401
|
+
);
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Track an order placed event
|
|
1405
|
+
* @param event The order placed event
|
|
1406
|
+
*/
|
|
1407
|
+
trackOrderPlaced(event) {
|
|
1408
|
+
const params = {
|
|
1409
|
+
transaction_id: event.order_id,
|
|
1410
|
+
value: event.total_amount,
|
|
1411
|
+
currency: event.currency || "USD",
|
|
1412
|
+
items: event.items?.map((item) => ({
|
|
1413
|
+
item_id: item.product_id,
|
|
1414
|
+
item_name: item.product_name,
|
|
1415
|
+
item_category: item.category,
|
|
1416
|
+
item_brand: item.brand,
|
|
1417
|
+
item_variant: item.variant,
|
|
1418
|
+
price: item.price,
|
|
1419
|
+
quantity: item.quantity
|
|
1420
|
+
})) || [],
|
|
1421
|
+
// GA4-specific parameters
|
|
1422
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
1423
|
+
batch_page_id: event.batch_page_id || "",
|
|
1424
|
+
campaign: event.campaign || "",
|
|
1425
|
+
ga_session_id: event.ga_session_id || "",
|
|
1426
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
1427
|
+
session_engaged: event.session_engaged,
|
|
1428
|
+
page_title: event.page_title || document.title,
|
|
1429
|
+
page_location: event.page_location || window.location.href,
|
|
1430
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
1431
|
+
user_id: event.user_id,
|
|
1432
|
+
user_properties: event.user_properties
|
|
1433
|
+
};
|
|
1434
|
+
window.gtag?.("event", "purchase", this.enhanceWithAffiliateParams(params));
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Track a begin checkout event
|
|
1438
|
+
* @param event The begin checkout event
|
|
1439
|
+
*/
|
|
1440
|
+
trackBeginCheckout(event) {
|
|
1441
|
+
const params = {
|
|
1442
|
+
currency: event.currency || "USD",
|
|
1443
|
+
value: event.value || 0,
|
|
1444
|
+
coupon: event.coupon,
|
|
1445
|
+
items: event.items?.map((item) => ({
|
|
1446
|
+
item_id: item.item_id,
|
|
1447
|
+
item_name: item.item_name,
|
|
1448
|
+
item_category: item.item_category,
|
|
1449
|
+
item_category2: item.item_category2,
|
|
1450
|
+
item_category3: item.item_category3,
|
|
1451
|
+
item_category4: item.item_category4,
|
|
1452
|
+
item_category5: item.item_category5,
|
|
1453
|
+
item_brand: item.item_brand,
|
|
1454
|
+
item_variant: item.item_variant,
|
|
1455
|
+
price: item.price,
|
|
1456
|
+
quantity: item.quantity
|
|
1457
|
+
})) || [],
|
|
1458
|
+
// GA4-specific parameters
|
|
1459
|
+
batch_ordering_id: event.batch_ordering_id || "",
|
|
1460
|
+
batch_page_id: event.batch_page_id || "",
|
|
1461
|
+
campaign: event.campaign || "",
|
|
1462
|
+
ga_session_id: event.ga_session_id || "",
|
|
1463
|
+
engagement_time_msec: event.engagement_time_msec,
|
|
1464
|
+
session_engaged: event.session_engaged,
|
|
1465
|
+
page_title: event.page_title || document.title,
|
|
1466
|
+
page_location: event.page_location || window.location.href,
|
|
1467
|
+
page_referrer: event.page_referrer || document.referrer,
|
|
1468
|
+
user_id: event.user_id,
|
|
1469
|
+
user_properties: event.user_properties
|
|
1470
|
+
};
|
|
1471
|
+
window.gtag?.(
|
|
1472
|
+
"event",
|
|
1473
|
+
"begin_checkout",
|
|
1474
|
+
this.enhanceWithAffiliateParams(params)
|
|
1475
|
+
);
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Convert an event to Google Analytics parameters
|
|
1479
|
+
* @param event The event to convert
|
|
1480
|
+
*/
|
|
1481
|
+
eventToParams(event) {
|
|
1482
|
+
const { type, timestamp, ...params } = event;
|
|
1483
|
+
return this.enhanceWithAffiliateParams(params);
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
// src/constants.ts
|
|
1488
|
+
var EventNames = {
|
|
1489
|
+
// Page events
|
|
1490
|
+
PAGE_VIEWED: "Page Viewed",
|
|
1491
|
+
// Interaction events
|
|
1492
|
+
BUTTON_CLICKED: "Button Clicked",
|
|
1493
|
+
FORM_SUBMITTED: "Form Submitted",
|
|
1494
|
+
// Product events
|
|
1495
|
+
PRODUCT_VIEWED: "Product Viewed",
|
|
1496
|
+
ADDED_TO_CART: "Added To Cart",
|
|
1497
|
+
REMOVED_FROM_CART: "Removed From Cart",
|
|
1498
|
+
// Checkout events
|
|
1499
|
+
CHECKOUT_STARTED: "Checkout Started",
|
|
1500
|
+
PURCHASE_COMPLETED: "Purchase Completed",
|
|
1501
|
+
// Search events
|
|
1502
|
+
SEARCH: "Search",
|
|
1503
|
+
// User events
|
|
1504
|
+
USER_SIGNED_UP: "User Signed Up",
|
|
1505
|
+
USER_LOGGED_IN: "User Logged In",
|
|
1506
|
+
// MoEngage events
|
|
1507
|
+
ITEM_PURCHASED: "Item Purchased",
|
|
1508
|
+
UPDATE_CART: "Update Cart",
|
|
1509
|
+
CUSTOMER_REGISTERED: "Customer Registered",
|
|
1510
|
+
CUSTOMER_LOGGED_IN: "Customer Logged In",
|
|
1511
|
+
SHOPIFY_CHECKOUT_UPDATED: "Shopify - Checkout Updated",
|
|
1512
|
+
SHOPIFY_ABANDONED_CHECKOUT: "Shopify - Abandoned Checkout",
|
|
1513
|
+
SHOPIFY_ORDER_FULFILLED: "Shopify - Order Fulfilled",
|
|
1514
|
+
SHOPIFY_CHECKOUT_STARTED: "Shopify - Checkout Started",
|
|
1515
|
+
SHOPIFY_ADD_TO_CART: "Shopify - Add To Cart",
|
|
1516
|
+
SHOPIFY_REMOVED_FROM_CART: "Shopify - Removed From Cart",
|
|
1517
|
+
SHOPIFY_UPDATE_CART: "Shopify - Update Cart",
|
|
1518
|
+
SPINFORM_RESULT: "Spinform Result",
|
|
1519
|
+
COUPON_COPIED: "Coupon Copied",
|
|
1520
|
+
STARTED_CHECKOUT_GK: "Started Checkout GK",
|
|
1521
|
+
MOBILE_ADDED_GK: "Mobile Added GK",
|
|
1522
|
+
ADDRESS_SELECTED_GK: "Address Selected GK",
|
|
1523
|
+
ADDRESS_COMPLETED_GK: "Address Completed GK",
|
|
1524
|
+
PAYMENT_METHOD_SELECTED_GK: "Payment Method Selected GK",
|
|
1525
|
+
PAYMENT_COMPLETED_GK: "Payment Completed GK",
|
|
1526
|
+
ORDER_SUCCESS: "Order Success",
|
|
1527
|
+
ORDER_COMPLETED: "Order Completed",
|
|
1528
|
+
PIN_CODE_ADDED_GK: "PIN Code Added GK",
|
|
1529
|
+
ADDRESS_ADDED_GK: "Address Added GK",
|
|
1530
|
+
KP_MP_PHONE_NUMBER_LOGGED_IN: "KP MP Phone Number Logged In",
|
|
1531
|
+
KP_PHONE_NUMBER_LOGGED_IN: "KP Phone Number Logged In",
|
|
1532
|
+
KP_MP_SHOPIFY_LOGGED_IN: "KP MP Shopify Logged In",
|
|
1533
|
+
KP_MP_SUCCESSFULLY_LOGGED_OUT: "KP MP Successfully Logged Out",
|
|
1534
|
+
KP_WHATSAPP_LOGGED_IN: "KP Whatsapp Logged In",
|
|
1535
|
+
KP_MP_TRUECALLER_LOGGED_IN: "KP MP Truecaller Logged In",
|
|
1536
|
+
KP_MP_WHATSAPP_LOGGED_IN: "KP MP Whatsapp Logged In",
|
|
1537
|
+
KP_TRUECALLER_LOGGED_IN: "KP Truecaller Logged In",
|
|
1538
|
+
KP_SHOPIFY_LOGGED_IN: "KP Shopify Logged In",
|
|
1539
|
+
KP_SUCCESSFULLY_LOGGED_OUT: "KP Successfully Logged Out"
|
|
1540
|
+
};
|
|
1541
|
+
var DEFAULT_CURRENCY = "INR";
|
|
1542
|
+
var HARDCODED_HANDLE = "ryze-gums";
|
|
1543
|
+
|
|
1544
|
+
// src/adapters/moengage-adapter.ts
|
|
1545
|
+
var import_web_sdk = __toESM(require("@moengage/web-sdk"));
|
|
1546
|
+
var MoengageAdapter = class extends BaseAdapter {
|
|
1547
|
+
constructor(config) {
|
|
1548
|
+
super(config);
|
|
1549
|
+
this.name = "MoEngage";
|
|
1550
|
+
this.sdk = null;
|
|
1551
|
+
this.initializeLogger();
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Initialize the MoenGage adapter using the Web SDK
|
|
1555
|
+
*/
|
|
1556
|
+
async initialize() {
|
|
1557
|
+
if (this.initialized) {
|
|
1558
|
+
this.logger.debug("Already initialized");
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
if (typeof window === "undefined") {
|
|
1562
|
+
this.logger.debug("Skipping initialization on server");
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
try {
|
|
1566
|
+
const appId = this.getConfig("appId");
|
|
1567
|
+
if (!appId) {
|
|
1568
|
+
this.logger.warn("App ID is required for initialization");
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
const region = this.getConfig("region", "dc_01");
|
|
1572
|
+
const config = {
|
|
1573
|
+
app_id: appId,
|
|
1574
|
+
debug_logs: this.getConfig("debug", false) ? 1 : 0,
|
|
1575
|
+
cluster: region
|
|
1576
|
+
};
|
|
1577
|
+
this.logger.info("Initializing with config", {
|
|
1578
|
+
region,
|
|
1579
|
+
debug: this.getConfig("debug", false),
|
|
1580
|
+
appId: "***"
|
|
1581
|
+
// Hide sensitive data
|
|
1582
|
+
});
|
|
1583
|
+
import_web_sdk.default.initialize(config);
|
|
1584
|
+
this.sdk = window.Moengage;
|
|
1585
|
+
this.logger.info("Successfully initialized with SDK");
|
|
1586
|
+
this.initialized = true;
|
|
1587
|
+
} catch (error) {
|
|
1588
|
+
this.logger.error("Failed to initialize", error);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Track an event with MoenGage SDK
|
|
1593
|
+
* @param event The event to track
|
|
1594
|
+
*/
|
|
1595
|
+
async trackEvent(event) {
|
|
1596
|
+
if (!this.initialized || typeof window === "undefined" || !this.sdk) {
|
|
1597
|
+
this.logger.warn(
|
|
1598
|
+
"Cannot track event, adapter not initialized or SDK not available",
|
|
1599
|
+
{
|
|
1600
|
+
eventType: event.type,
|
|
1601
|
+
initialized: this.initialized,
|
|
1602
|
+
hasWindow: typeof window !== "undefined",
|
|
1603
|
+
hasSdk: !!this.sdk
|
|
1604
|
+
}
|
|
1605
|
+
);
|
|
1606
|
+
return;
|
|
1607
|
+
}
|
|
1608
|
+
this.logger.debug("Tracking event", { eventType: event.type });
|
|
1609
|
+
switch (event.type) {
|
|
1610
|
+
case "page_view" /* PAGE_VIEW */:
|
|
1611
|
+
this.trackPageView(event);
|
|
1612
|
+
break;
|
|
1613
|
+
case "button_click" /* BUTTON_CLICK */:
|
|
1614
|
+
this.trackButtonClick(event);
|
|
1615
|
+
break;
|
|
1616
|
+
case "form_submission" /* FORM_SUBMISSION */:
|
|
1617
|
+
this.trackFormSubmission(event);
|
|
1618
|
+
break;
|
|
1619
|
+
case "product_view" /* PRODUCT_VIEW */:
|
|
1620
|
+
this.trackProductView(event);
|
|
1621
|
+
break;
|
|
1622
|
+
case "add_to_cart" /* ADD_TO_CART */:
|
|
1623
|
+
this.trackAddToCart(event);
|
|
1624
|
+
break;
|
|
1625
|
+
case "remove_from_cart" /* REMOVE_FROM_CART */:
|
|
1626
|
+
this.trackRemoveFromCart(event);
|
|
1627
|
+
break;
|
|
1628
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
1629
|
+
this.trackCheckoutStarted(event);
|
|
1630
|
+
break;
|
|
1631
|
+
case "checkout_completed" /* CHECKOUT_COMPLETED */:
|
|
1632
|
+
this.trackCheckoutCompleted(event);
|
|
1633
|
+
break;
|
|
1634
|
+
case "search" /* SEARCH */:
|
|
1635
|
+
this.trackSearch(event);
|
|
1636
|
+
break;
|
|
1637
|
+
case "user_signup" /* USER_SIGNUP */:
|
|
1638
|
+
this.trackUserSignup(event);
|
|
1639
|
+
break;
|
|
1640
|
+
case "user_login" /* USER_LOGIN */:
|
|
1641
|
+
this.trackUserLogin(event);
|
|
1642
|
+
break;
|
|
1643
|
+
case "custom" /* CUSTOM */:
|
|
1644
|
+
this.trackCustomEvent(event);
|
|
1645
|
+
break;
|
|
1646
|
+
default:
|
|
1647
|
+
this.sdk.track_event(event.type, this.eventToParams(event));
|
|
1648
|
+
break;
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
/**
|
|
1652
|
+
* Track a page view event
|
|
1653
|
+
* @param event The page view event
|
|
1654
|
+
*/
|
|
1655
|
+
trackPageView(event) {
|
|
1656
|
+
if (!this.sdk?.track_event) {
|
|
1657
|
+
this.logger.warn("track_event not available for PageView event");
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
const eventData = {
|
|
1661
|
+
page_path: event.path,
|
|
1662
|
+
page_title: event.title,
|
|
1663
|
+
page_url: window.location.href,
|
|
1664
|
+
referrer: event.referrer || document.referrer
|
|
1665
|
+
};
|
|
1666
|
+
this.sdk.track_event(EventNames.PAGE_VIEWED, eventData);
|
|
1667
|
+
this.logger.debug("PageView event tracked", { eventData });
|
|
1668
|
+
}
|
|
1669
|
+
/**
|
|
1670
|
+
* Track a button click event
|
|
1671
|
+
* @param event The button click event
|
|
1672
|
+
*/
|
|
1673
|
+
trackButtonClick(event) {
|
|
1674
|
+
this.sdk?.track_event(EventNames.BUTTON_CLICKED, {
|
|
1675
|
+
button_id: event.buttonId,
|
|
1676
|
+
button_text: event.buttonText,
|
|
1677
|
+
location: event.location
|
|
1678
|
+
});
|
|
1679
|
+
}
|
|
1680
|
+
/**
|
|
1681
|
+
* Track a form submission event
|
|
1682
|
+
* @param event The form submission event
|
|
1683
|
+
*/
|
|
1684
|
+
trackFormSubmission(event) {
|
|
1685
|
+
this.sdk?.track_event(EventNames.FORM_SUBMITTED, {
|
|
1686
|
+
form_id: event.formId,
|
|
1687
|
+
form_name: event.formName,
|
|
1688
|
+
success: event.success
|
|
1689
|
+
});
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Track a product view event
|
|
1693
|
+
* @param event The product view event
|
|
1694
|
+
*/
|
|
1695
|
+
trackProductView(event) {
|
|
1696
|
+
this.sdk?.track_event(EventNames.PRODUCT_VIEWED, {
|
|
1697
|
+
product_id: event.productId,
|
|
1698
|
+
product_name: event.productName,
|
|
1699
|
+
price: event.price,
|
|
1700
|
+
currency: event.currency || DEFAULT_CURRENCY,
|
|
1701
|
+
category: event.category
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
/**
|
|
1705
|
+
* Track an add to cart event
|
|
1706
|
+
* @param event The add to cart event
|
|
1707
|
+
*/
|
|
1708
|
+
trackAddToCart(event) {
|
|
1709
|
+
const quantity = event.quantity ?? 1;
|
|
1710
|
+
this.sdk?.track_event(EventNames.ADDED_TO_CART, {
|
|
1711
|
+
product_id: event.productId,
|
|
1712
|
+
product_name: event.productName,
|
|
1713
|
+
price: event.price,
|
|
1714
|
+
currency: event.currency || DEFAULT_CURRENCY,
|
|
1715
|
+
quantity,
|
|
1716
|
+
variant: event.variant,
|
|
1717
|
+
total_value: event.price * quantity
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Track a remove from cart event
|
|
1722
|
+
* @param event The remove from cart event
|
|
1723
|
+
*/
|
|
1724
|
+
trackRemoveFromCart(event) {
|
|
1725
|
+
this.sdk?.track_event(EventNames.REMOVED_FROM_CART, {
|
|
1726
|
+
product_id: event.productId,
|
|
1727
|
+
product_name: event.productName,
|
|
1728
|
+
price: event.price,
|
|
1729
|
+
currency: event.currency || DEFAULT_CURRENCY,
|
|
1730
|
+
quantity: event.quantity,
|
|
1731
|
+
variant: event.variant,
|
|
1732
|
+
total_value: event.price * event.quantity
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
/**
|
|
1736
|
+
* Track a checkout started event
|
|
1737
|
+
* @param event The checkout started event
|
|
1738
|
+
*/
|
|
1739
|
+
trackCheckoutStarted(event) {
|
|
1740
|
+
this.sdk?.track_event(EventNames.CHECKOUT_STARTED, {
|
|
1741
|
+
cart_value: event.cartValue,
|
|
1742
|
+
currency: event.currency || DEFAULT_CURRENCY,
|
|
1743
|
+
item_count: event.itemCount,
|
|
1744
|
+
items: event.items.map((item) => ({
|
|
1745
|
+
product_id: item.productId,
|
|
1746
|
+
product_name: item.productName,
|
|
1747
|
+
price: item.price,
|
|
1748
|
+
quantity: item.quantity,
|
|
1749
|
+
variant: item.variant
|
|
1750
|
+
}))
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Track a checkout completed event
|
|
1755
|
+
* @param event The checkout completed event
|
|
1756
|
+
*/
|
|
1757
|
+
trackCheckoutCompleted(event) {
|
|
1758
|
+
this.sdk?.track_event(EventNames.PURCHASE_COMPLETED, {
|
|
1759
|
+
order_id: event.orderId,
|
|
1760
|
+
cart_value: event.cartValue,
|
|
1761
|
+
currency: event.currency || DEFAULT_CURRENCY,
|
|
1762
|
+
item_count: event.itemCount,
|
|
1763
|
+
items: event.items.map((item) => ({
|
|
1764
|
+
product_id: item.productId,
|
|
1765
|
+
product_name: item.productName,
|
|
1766
|
+
price: item.price,
|
|
1767
|
+
quantity: item.quantity,
|
|
1768
|
+
variant: item.variant
|
|
1769
|
+
}))
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Track a search event
|
|
1774
|
+
* @param event The search event
|
|
1775
|
+
*/
|
|
1776
|
+
trackSearch(event) {
|
|
1777
|
+
this.sdk?.track_event(EventNames.SEARCH, {
|
|
1778
|
+
search_term: event.searchTerm,
|
|
1779
|
+
results_count: event.resultsCount
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
/**
|
|
1783
|
+
* Track a user signup event
|
|
1784
|
+
* @param event The user signup event
|
|
1785
|
+
*/
|
|
1786
|
+
trackUserSignup(event) {
|
|
1787
|
+
this.sdk?.track_event(EventNames.USER_SIGNED_UP, {
|
|
1788
|
+
user_id: event.userId,
|
|
1789
|
+
method: event.method,
|
|
1790
|
+
success: event.success
|
|
1791
|
+
});
|
|
1792
|
+
if (event.userId && this.getConfig("enableUserIdentification", true)) {
|
|
1793
|
+
this.sdk?.add_unique_user_id(event.userId);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
/**
|
|
1797
|
+
* Track a user login event
|
|
1798
|
+
* @param event The user login event
|
|
1799
|
+
*/
|
|
1800
|
+
trackUserLogin(event) {
|
|
1801
|
+
this.sdk?.track_event(EventNames.USER_LOGGED_IN, {
|
|
1802
|
+
user_id: event.userId,
|
|
1803
|
+
method: event.method,
|
|
1804
|
+
success: event.success
|
|
1805
|
+
});
|
|
1806
|
+
if (event.userId && this.getConfig("enableUserIdentification", true)) {
|
|
1807
|
+
this.sdk?.add_unique_user_id(event.userId);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* Track a custom event
|
|
1812
|
+
* @param event The custom event
|
|
1813
|
+
*/
|
|
1814
|
+
trackCustomEvent(event) {
|
|
1815
|
+
this.sdk?.track_event(event.name, event.properties);
|
|
1816
|
+
}
|
|
1817
|
+
/**
|
|
1818
|
+
* Convert an event to MoenGage parameters
|
|
1819
|
+
* @param event The event to convert
|
|
1820
|
+
*/
|
|
1821
|
+
eventToParams(event) {
|
|
1822
|
+
const { type, timestamp, ...params } = event;
|
|
1823
|
+
return params;
|
|
1824
|
+
}
|
|
1825
|
+
/**
|
|
1826
|
+
* Set user attributes in MoenGage
|
|
1827
|
+
* @param attributes User attributes to set
|
|
1828
|
+
*/
|
|
1829
|
+
setUserAttributes(attributes) {
|
|
1830
|
+
if (!this.initialized || typeof window === "undefined" || !this.sdk) {
|
|
1831
|
+
this.logger.warn("Cannot set user attributes, adapter not initialized");
|
|
1832
|
+
return;
|
|
1833
|
+
}
|
|
1834
|
+
this.logger.debug("Setting user attributes", {
|
|
1835
|
+
attributeKeys: Object.keys(attributes)
|
|
1836
|
+
});
|
|
1837
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
1838
|
+
switch (key) {
|
|
1839
|
+
case "firstName":
|
|
1840
|
+
this.sdk?.add_first_name(value);
|
|
1841
|
+
break;
|
|
1842
|
+
case "lastName":
|
|
1843
|
+
this.sdk?.add_last_name(value);
|
|
1844
|
+
break;
|
|
1845
|
+
case "email":
|
|
1846
|
+
this.sdk?.add_email(value);
|
|
1847
|
+
break;
|
|
1848
|
+
case "mobile":
|
|
1849
|
+
this.sdk?.add_mobile(value);
|
|
1850
|
+
break;
|
|
1851
|
+
case "username":
|
|
1852
|
+
this.sdk?.add_user_name(value);
|
|
1853
|
+
break;
|
|
1854
|
+
case "gender":
|
|
1855
|
+
this.sdk?.add_gender(value);
|
|
1856
|
+
break;
|
|
1857
|
+
case "birthday":
|
|
1858
|
+
this.sdk?.add_birthday(value);
|
|
1859
|
+
break;
|
|
1860
|
+
case "userId":
|
|
1861
|
+
this.sdk?.add_unique_user_id(value);
|
|
1862
|
+
break;
|
|
1863
|
+
default:
|
|
1864
|
+
this.sdk?.add_user_attribute(key, value);
|
|
1865
|
+
break;
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
|
|
1871
|
+
// src/adapters/posthog-adapter.ts
|
|
1872
|
+
var PostHogAdapter = class extends BaseAdapter {
|
|
1873
|
+
constructor(config = {}) {
|
|
1874
|
+
super(config);
|
|
1875
|
+
this.name = "PostHog";
|
|
1876
|
+
this.initializeLogger();
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1879
|
+
* Initialize PostHog
|
|
1880
|
+
*/
|
|
1881
|
+
async initialize() {
|
|
1882
|
+
if (this.initialized) {
|
|
1883
|
+
this.logger.debug("Already initialized");
|
|
1884
|
+
return;
|
|
1885
|
+
}
|
|
1886
|
+
if (typeof window === "undefined") {
|
|
1887
|
+
this.logger.debug("Skipping initialization on server");
|
|
1888
|
+
return;
|
|
1889
|
+
}
|
|
1890
|
+
if (!window.posthog) {
|
|
1891
|
+
this.logger.warn(
|
|
1892
|
+
"PostHog object not found. Make sure the script is loaded."
|
|
1893
|
+
);
|
|
1894
|
+
return;
|
|
1895
|
+
}
|
|
1896
|
+
this.logger.info("Successfully initialized");
|
|
1897
|
+
this.initialized = true;
|
|
1898
|
+
}
|
|
1899
|
+
/**
|
|
1900
|
+
* Track an event with PostHog
|
|
1901
|
+
* @param event The event to track
|
|
1902
|
+
*/
|
|
1903
|
+
async trackEvent(event) {
|
|
1904
|
+
if (!this.initialized || typeof window === "undefined" || !window.posthog) {
|
|
1905
|
+
this.logger.warn(
|
|
1906
|
+
"Cannot track event, adapter not initialized or posthog not available",
|
|
1907
|
+
{
|
|
1908
|
+
eventType: event.type,
|
|
1909
|
+
initialized: this.initialized,
|
|
1910
|
+
hasWindow: typeof window !== "undefined",
|
|
1911
|
+
hasPosthog: !!window?.posthog
|
|
1912
|
+
}
|
|
1913
|
+
);
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1916
|
+
this.logger.debug("Tracking event", { eventType: event.type });
|
|
1917
|
+
switch (event.type) {
|
|
1918
|
+
case "page_view" /* PAGE_VIEW */:
|
|
1919
|
+
this.trackPageView(event);
|
|
1920
|
+
break;
|
|
1921
|
+
case "product_view" /* PRODUCT_VIEW */:
|
|
1922
|
+
this.trackProductView(event);
|
|
1923
|
+
break;
|
|
1924
|
+
case "add_to_cart" /* ADD_TO_CART */:
|
|
1925
|
+
this.trackAddToCart(event);
|
|
1926
|
+
break;
|
|
1927
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
1928
|
+
this.trackCheckoutStarted(event);
|
|
1929
|
+
break;
|
|
1930
|
+
case "checkout_completed" /* CHECKOUT_COMPLETED */:
|
|
1931
|
+
this.trackCheckoutCompleted(event);
|
|
1932
|
+
break;
|
|
1933
|
+
case "add_payment_info" /* ADD_PAYMENT_INFO */:
|
|
1934
|
+
this.trackAddPaymentInfo(event);
|
|
1935
|
+
break;
|
|
1936
|
+
case "search" /* SEARCH */:
|
|
1937
|
+
this.trackSearch(event);
|
|
1938
|
+
break;
|
|
1939
|
+
default:
|
|
1940
|
+
const params = this.eventToParams(event);
|
|
1941
|
+
window.posthog?.capture(
|
|
1942
|
+
event.type,
|
|
1943
|
+
this.enhanceWithAffiliateParams(params)
|
|
1944
|
+
);
|
|
1945
|
+
break;
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* Track a page view event
|
|
1950
|
+
* @param event The page view event
|
|
1951
|
+
*/
|
|
1952
|
+
trackPageView(event) {
|
|
1953
|
+
const params = {
|
|
1954
|
+
path: event.path,
|
|
1955
|
+
title: event.title,
|
|
1956
|
+
referrer: event.referrer
|
|
1957
|
+
};
|
|
1958
|
+
window.posthog?.capture(
|
|
1959
|
+
"$pageview",
|
|
1960
|
+
this.enhanceWithAffiliateParams(params)
|
|
1961
|
+
);
|
|
1962
|
+
}
|
|
1963
|
+
/**
|
|
1964
|
+
* Track a product view event
|
|
1965
|
+
* @param event The product view event
|
|
1966
|
+
*/
|
|
1967
|
+
trackProductView(event) {
|
|
1968
|
+
const params = {
|
|
1969
|
+
product_id: event.productId,
|
|
1970
|
+
product_name: event.productName,
|
|
1971
|
+
category: event.category,
|
|
1972
|
+
price: event.price,
|
|
1973
|
+
currency: event.currency || "INR"
|
|
1974
|
+
};
|
|
1975
|
+
window.posthog?.capture(
|
|
1976
|
+
"product_viewed",
|
|
1977
|
+
this.enhanceWithAffiliateParams(params)
|
|
1978
|
+
);
|
|
1979
|
+
}
|
|
1980
|
+
/**
|
|
1981
|
+
* Track an add to cart event
|
|
1982
|
+
* @param event The add to cart event
|
|
1983
|
+
*/
|
|
1984
|
+
trackAddToCart(event) {
|
|
1985
|
+
this.logger.debug("Handling ADD_TO_CART event", { event });
|
|
1986
|
+
const params = {
|
|
1987
|
+
product_id: event.productId,
|
|
1988
|
+
product_name: event.productName,
|
|
1989
|
+
price: event.price,
|
|
1990
|
+
currency: event.currency || "INR",
|
|
1991
|
+
quantity: event.quantity,
|
|
1992
|
+
variant: event.variant
|
|
1993
|
+
};
|
|
1994
|
+
this.logger.debug("Sending to PostHog with params", { params });
|
|
1995
|
+
if (!window.posthog) {
|
|
1996
|
+
this.logger.error("window.posthog is not available");
|
|
1997
|
+
return;
|
|
1998
|
+
}
|
|
1999
|
+
window.posthog.capture(
|
|
2000
|
+
"add_to_cart",
|
|
2001
|
+
this.enhanceWithAffiliateParams(params)
|
|
2002
|
+
);
|
|
2003
|
+
this.logger.debug("Event sent to PostHog successfully");
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Track a checkout started event
|
|
2007
|
+
* @param event The checkout started event
|
|
2008
|
+
*/
|
|
2009
|
+
trackCheckoutStarted(event) {
|
|
2010
|
+
const params = {
|
|
2011
|
+
cart_value: event.cartValue,
|
|
2012
|
+
currency: event.currency || "INR",
|
|
2013
|
+
item_count: event.itemCount,
|
|
2014
|
+
items: event.items.map((item) => ({
|
|
2015
|
+
product_id: item.productId,
|
|
2016
|
+
product_name: item.productName,
|
|
2017
|
+
price: item.price,
|
|
2018
|
+
quantity: item.quantity,
|
|
2019
|
+
variant: item.variant
|
|
2020
|
+
}))
|
|
2021
|
+
};
|
|
2022
|
+
window.posthog?.capture(
|
|
2023
|
+
"checkout_started",
|
|
2024
|
+
this.enhanceWithAffiliateParams(params)
|
|
2025
|
+
);
|
|
2026
|
+
}
|
|
2027
|
+
/**
|
|
2028
|
+
* Track a checkout completed event
|
|
2029
|
+
* @param event The checkout completed event
|
|
2030
|
+
*/
|
|
2031
|
+
trackCheckoutCompleted(event) {
|
|
2032
|
+
const params = {
|
|
2033
|
+
order_id: event.orderId,
|
|
2034
|
+
cart_value: event.cartValue,
|
|
2035
|
+
currency: event.currency || "INR",
|
|
2036
|
+
item_count: event.itemCount,
|
|
2037
|
+
items: event.items.map((item) => ({
|
|
2038
|
+
product_id: item.productId,
|
|
2039
|
+
product_name: item.productName,
|
|
2040
|
+
price: item.price,
|
|
2041
|
+
quantity: item.quantity,
|
|
2042
|
+
variant: item.variant
|
|
2043
|
+
}))
|
|
2044
|
+
};
|
|
2045
|
+
window.posthog?.capture(
|
|
2046
|
+
"purchase",
|
|
2047
|
+
this.enhanceWithAffiliateParams(params)
|
|
2048
|
+
);
|
|
2049
|
+
}
|
|
2050
|
+
/**
|
|
2051
|
+
* Track a search event
|
|
2052
|
+
* @param event The search event
|
|
2053
|
+
*/
|
|
2054
|
+
trackSearch(event) {
|
|
2055
|
+
const params = {
|
|
2056
|
+
search_term: event.searchTerm,
|
|
2057
|
+
results_count: event.resultsCount,
|
|
2058
|
+
content_ids: event.content_ids
|
|
2059
|
+
};
|
|
2060
|
+
window.posthog?.capture("search", this.enhanceWithAffiliateParams(params));
|
|
2061
|
+
}
|
|
2062
|
+
/**
|
|
2063
|
+
* Track an add payment info event
|
|
2064
|
+
* @param event The add payment info event
|
|
2065
|
+
*/
|
|
2066
|
+
trackAddPaymentInfo(event) {
|
|
2067
|
+
const params = {
|
|
2068
|
+
cart_value: event.cartValue,
|
|
2069
|
+
currency: event.currency || "INR",
|
|
2070
|
+
payment_type: event.paymentType,
|
|
2071
|
+
item_count: event.itemCount,
|
|
2072
|
+
items: event.items.map((item) => ({
|
|
2073
|
+
product_id: item.productId,
|
|
2074
|
+
product_name: item.productName,
|
|
2075
|
+
price: item.price,
|
|
2076
|
+
quantity: item.quantity,
|
|
2077
|
+
variant: item.variant
|
|
2078
|
+
}))
|
|
2079
|
+
};
|
|
2080
|
+
window.posthog?.capture(
|
|
2081
|
+
"add_payment_info",
|
|
2082
|
+
this.enhanceWithAffiliateParams(params)
|
|
2083
|
+
);
|
|
2084
|
+
}
|
|
2085
|
+
/**
|
|
2086
|
+
* Convert an event to PostHog parameters
|
|
2087
|
+
* @param event The event to convert
|
|
2088
|
+
*/
|
|
2089
|
+
eventToParams(event) {
|
|
2090
|
+
const { type, timestamp, ...params } = event;
|
|
2091
|
+
return params;
|
|
2092
|
+
}
|
|
2093
|
+
};
|
|
2094
|
+
|
|
2095
|
+
// src/adapters/shopify-adapter.ts
|
|
2096
|
+
var import_hydrogen_react = require("@shopify/hydrogen-react");
|
|
2097
|
+
var DEFAULT_CURRENCY2 = "INR";
|
|
2098
|
+
var DEFAULT_LANGUAGE = "en";
|
|
2099
|
+
var ShopifyAdapter = class extends BaseAdapter {
|
|
2100
|
+
constructor(config) {
|
|
2101
|
+
super(config);
|
|
2102
|
+
this.name = "ShopifyAnalytics";
|
|
2103
|
+
/**
|
|
2104
|
+
* Send page view event using the enhanced functionality
|
|
2105
|
+
*/
|
|
2106
|
+
this.sendPageView = (eventName, payload) => {
|
|
2107
|
+
const enhancedPayload = {
|
|
2108
|
+
...this.createBasePayload(),
|
|
2109
|
+
...payload
|
|
2110
|
+
};
|
|
2111
|
+
return (0, import_hydrogen_react.sendShopifyAnalytics)({
|
|
2112
|
+
eventName,
|
|
2113
|
+
payload: enhancedPayload
|
|
2114
|
+
});
|
|
2115
|
+
};
|
|
2116
|
+
/**
|
|
2117
|
+
* Send add to cart event using the enhanced functionality
|
|
2118
|
+
*/
|
|
2119
|
+
this.sendAddToCart = ({
|
|
2120
|
+
cartId,
|
|
2121
|
+
totalValue,
|
|
2122
|
+
products
|
|
2123
|
+
}) => {
|
|
2124
|
+
return this.sendPageView(import_hydrogen_react.AnalyticsEventName.ADD_TO_CART, {
|
|
2125
|
+
cartId,
|
|
2126
|
+
totalValue,
|
|
2127
|
+
products
|
|
2128
|
+
});
|
|
2129
|
+
};
|
|
2130
|
+
this.shopId = config.shopId;
|
|
2131
|
+
this.domain = config.domain;
|
|
2132
|
+
this.currency = config.currency || DEFAULT_CURRENCY2;
|
|
2133
|
+
}
|
|
2134
|
+
/**
|
|
2135
|
+
* Initialize the Shopify Analytics adapter
|
|
2136
|
+
*/
|
|
2137
|
+
async initialize() {
|
|
2138
|
+
this.initializeLogger();
|
|
2139
|
+
try {
|
|
2140
|
+
if (typeof window !== "undefined") {
|
|
2141
|
+
this.logger.info("Shopify Analytics adapter initialized successfully", {
|
|
2142
|
+
shopId: this.shopId,
|
|
2143
|
+
domain: this.domain,
|
|
2144
|
+
currency: this.currency
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
this.initialized = true;
|
|
2148
|
+
} catch (error) {
|
|
2149
|
+
this.logger.error(
|
|
2150
|
+
"Failed to initialize Shopify Analytics",
|
|
2151
|
+
error instanceof Error ? error : new Error(String(error))
|
|
2152
|
+
);
|
|
2153
|
+
throw error;
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
/**
|
|
2157
|
+
* Convert product ID to Shopify GID format if it's not already
|
|
2158
|
+
*/
|
|
2159
|
+
formatProductGid(productId) {
|
|
2160
|
+
return productId.startsWith("gid://shopify/Product/") ? productId : `gid://shopify/Product/${productId}`;
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Get user consent status from your consent management system
|
|
2164
|
+
*/
|
|
2165
|
+
getUserConsent() {
|
|
2166
|
+
const hasConsent = this.checkUserConsent();
|
|
2167
|
+
return {
|
|
2168
|
+
hasUserConsent: hasConsent,
|
|
2169
|
+
analyticsAllowed: hasConsent && this.checkAnalyticsConsent(),
|
|
2170
|
+
marketingAllowed: hasConsent && this.checkMarketingConsent(),
|
|
2171
|
+
saleOfDataAllowed: hasConsent && this.checkSaleOfDataConsent()
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
/**
|
|
2175
|
+
* Check user consent (implement based on your consent management)
|
|
2176
|
+
*/
|
|
2177
|
+
checkUserConsent() {
|
|
2178
|
+
return true;
|
|
2179
|
+
}
|
|
2180
|
+
checkAnalyticsConsent() {
|
|
2181
|
+
return true;
|
|
2182
|
+
}
|
|
2183
|
+
checkMarketingConsent() {
|
|
2184
|
+
return true;
|
|
2185
|
+
}
|
|
2186
|
+
checkSaleOfDataConsent() {
|
|
2187
|
+
return true;
|
|
2188
|
+
}
|
|
2189
|
+
/**
|
|
2190
|
+
* Create base payload for all events
|
|
2191
|
+
*/
|
|
2192
|
+
createBasePayload() {
|
|
2193
|
+
const consent = this.getUserConsent();
|
|
2194
|
+
return {
|
|
2195
|
+
...(0, import_hydrogen_react.getClientBrowserParameters)(),
|
|
2196
|
+
...consent,
|
|
2197
|
+
storefrontId: this.domain,
|
|
2198
|
+
shopifySalesChannel: import_hydrogen_react.ShopifySalesChannel.headless,
|
|
2199
|
+
shopId: `gid://shopify/Shop/${this.shopId}`,
|
|
2200
|
+
currency: this.currency,
|
|
2201
|
+
acceptedLanguage: DEFAULT_LANGUAGE,
|
|
2202
|
+
...this.enhanceWithAffiliateParams({})
|
|
2203
|
+
};
|
|
2204
|
+
}
|
|
2205
|
+
/**
|
|
2206
|
+
* Track an event using Shopify Analytics
|
|
2207
|
+
*/
|
|
2208
|
+
async trackEvent(event) {
|
|
2209
|
+
if (!this.initialized || typeof window === "undefined") {
|
|
2210
|
+
this.logger.warn(
|
|
2211
|
+
"Shopify Analytics not initialized or not in browser environment"
|
|
2212
|
+
);
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
this.logger.debug("Processing Shopify Analytics event", {
|
|
2216
|
+
eventType: event.type,
|
|
2217
|
+
eventData: event
|
|
2218
|
+
});
|
|
2219
|
+
try {
|
|
2220
|
+
switch (event.type) {
|
|
2221
|
+
case "page_view" /* PAGE_VIEW */:
|
|
2222
|
+
this.sendPageView(import_hydrogen_react.AnalyticsEventName.PAGE_VIEW);
|
|
2223
|
+
this.logger.debug("Sent PAGE_VIEW event to Shopify Analytics");
|
|
2224
|
+
break;
|
|
2225
|
+
case "view_content" /* VIEW_CONTENT */:
|
|
2226
|
+
this.sendPageView(import_hydrogen_react.AnalyticsEventName.PRODUCT_VIEW);
|
|
2227
|
+
this.logger.debug("Sent PRODUCT_VIEW event to Shopify Analytics");
|
|
2228
|
+
break;
|
|
2229
|
+
case "add_to_cart" /* ADD_TO_CART */:
|
|
2230
|
+
this.trackAddToCart(event);
|
|
2231
|
+
break;
|
|
2232
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
2233
|
+
case "begin_checkout" /* BEGIN_CHECKOUT */:
|
|
2234
|
+
this.sendPageView(import_hydrogen_react.AnalyticsEventName.PAGE_VIEW, {
|
|
2235
|
+
pageType: "checkout"
|
|
2236
|
+
});
|
|
2237
|
+
this.logger.debug(
|
|
2238
|
+
"Sent checkout PAGE_VIEW event to Shopify Analytics"
|
|
2239
|
+
);
|
|
2240
|
+
break;
|
|
2241
|
+
default:
|
|
2242
|
+
this.logger.debug("Event not supported by Shopify Analytics", {
|
|
2243
|
+
eventType: event.type
|
|
2244
|
+
});
|
|
2245
|
+
break;
|
|
2246
|
+
}
|
|
2247
|
+
} catch (error) {
|
|
2248
|
+
this.logger.error(
|
|
2249
|
+
"Error tracking Shopify Analytics event",
|
|
2250
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
2251
|
+
{ eventType: event.type }
|
|
2252
|
+
);
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
/**
|
|
2256
|
+
* Check if Shopify session is properly established
|
|
2257
|
+
*/
|
|
2258
|
+
isSessionValid() {
|
|
2259
|
+
if (typeof window === "undefined") return false;
|
|
2260
|
+
const shopifyY = document.cookie.includes("_shopify_y=");
|
|
2261
|
+
const shopifyS = document.cookie.includes("_shopify_s=");
|
|
2262
|
+
return shopifyY && shopifyS;
|
|
2263
|
+
}
|
|
2264
|
+
/**
|
|
2265
|
+
* Get session debug information
|
|
2266
|
+
*/
|
|
2267
|
+
getSessionDebugInfo() {
|
|
2268
|
+
if (typeof window === "undefined")
|
|
2269
|
+
return { error: "Not in browser environment" };
|
|
2270
|
+
return {
|
|
2271
|
+
sessionValid: this.isSessionValid(),
|
|
2272
|
+
cookies: {
|
|
2273
|
+
shopify_y: document.cookie.includes("_shopify_y="),
|
|
2274
|
+
shopify_s: document.cookie.includes("_shopify_s="),
|
|
2275
|
+
all: document.cookie
|
|
2276
|
+
},
|
|
2277
|
+
shopId: this.shopId,
|
|
2278
|
+
initialized: this.initialized
|
|
2279
|
+
};
|
|
2280
|
+
}
|
|
2281
|
+
/**
|
|
2282
|
+
* Track add to cart event with enhanced error handling
|
|
2283
|
+
*/
|
|
2284
|
+
trackAddToCart(event) {
|
|
2285
|
+
if (!event.productId) {
|
|
2286
|
+
this.logger.warn("ADD_TO_CART event missing productId");
|
|
2287
|
+
return;
|
|
2288
|
+
}
|
|
2289
|
+
try {
|
|
2290
|
+
const productGid = this.formatProductGid(event.productId);
|
|
2291
|
+
const cartKey = `merchant_${process.env.NEXT_PUBLIC_MERCHANT_NAME}_cartId`;
|
|
2292
|
+
const cartId = localStorage.getItem(cartKey) || "";
|
|
2293
|
+
if (!cartId) {
|
|
2294
|
+
this.logger.warn("No cart ID found, creating anonymous session");
|
|
2295
|
+
}
|
|
2296
|
+
if (!event.price || event.price <= 0) {
|
|
2297
|
+
this.logger.warn("Invalid or missing price for ADD_TO_CART", {
|
|
2298
|
+
price: event.price
|
|
2299
|
+
});
|
|
2300
|
+
}
|
|
2301
|
+
const productPrice = Math.max(0, event.price || 0);
|
|
2302
|
+
const productQuantity = Math.max(1, event.quantity || 1);
|
|
2303
|
+
const products = [
|
|
2304
|
+
{
|
|
2305
|
+
productGid,
|
|
2306
|
+
variantGid: event.variantId || productGid.replace("Product", "ProductVariant"),
|
|
2307
|
+
quantity: productQuantity,
|
|
2308
|
+
price: productPrice.toString(),
|
|
2309
|
+
// Convert to string as required by ShopifyAnalyticsProduct
|
|
2310
|
+
name: event.productName || "Unknown Product",
|
|
2311
|
+
brand: event.brand || "Unknown Brand"
|
|
2312
|
+
}
|
|
2313
|
+
];
|
|
2314
|
+
const totalValue = productPrice * productQuantity;
|
|
2315
|
+
this.logger.debug("ADD_TO_CART event tracked successfully", {
|
|
2316
|
+
productGid,
|
|
2317
|
+
quantity: productQuantity,
|
|
2318
|
+
price: productPrice,
|
|
2319
|
+
totalValue
|
|
2320
|
+
});
|
|
2321
|
+
this.sendAddToCart({
|
|
2322
|
+
cartId,
|
|
2323
|
+
products,
|
|
2324
|
+
totalValue
|
|
2325
|
+
});
|
|
2326
|
+
} catch (error) {
|
|
2327
|
+
this.logger.error(
|
|
2328
|
+
"Error in trackAddToCart",
|
|
2329
|
+
error instanceof Error ? error : new Error(String(error))
|
|
2330
|
+
);
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
};
|
|
2334
|
+
|
|
2335
|
+
// src/adapters/kwikpass-adapter.ts
|
|
2336
|
+
var KwikPassAdapter = class extends BaseAdapter {
|
|
2337
|
+
constructor(config = {}) {
|
|
2338
|
+
super(config);
|
|
2339
|
+
this.name = "KwikPass";
|
|
2340
|
+
this.enableKwikPassEvents = config.enableKwikPassEvents ?? true;
|
|
2341
|
+
this.initializeLogger();
|
|
2342
|
+
}
|
|
2343
|
+
/**
|
|
2344
|
+
* Initialize the KwikPass adapter
|
|
2345
|
+
*/
|
|
2346
|
+
async initialize() {
|
|
2347
|
+
try {
|
|
2348
|
+
if (typeof window !== "undefined") {
|
|
2349
|
+
this.logger.info("KwikPass adapter initialized successfully", {
|
|
2350
|
+
eventsEnabled: this.enableKwikPassEvents
|
|
2351
|
+
});
|
|
2352
|
+
}
|
|
2353
|
+
this.initialized = true;
|
|
2354
|
+
} catch (error) {
|
|
2355
|
+
this.logger.error(
|
|
2356
|
+
"Failed to initialize KwikPass adapter",
|
|
2357
|
+
error
|
|
2358
|
+
);
|
|
2359
|
+
throw error;
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
/**
|
|
2363
|
+
* Track an event using KwikPass
|
|
2364
|
+
*/
|
|
2365
|
+
async trackEvent(event) {
|
|
2366
|
+
if (!this.initialized || typeof window === "undefined") {
|
|
2367
|
+
this.logger.warn(
|
|
2368
|
+
"KwikPass adapter not initialized or not in browser environment"
|
|
2369
|
+
);
|
|
2370
|
+
return;
|
|
2371
|
+
}
|
|
2372
|
+
if (!this.enableKwikPassEvents) {
|
|
2373
|
+
this.logger.debug("KwikPass events disabled, skipping event", {
|
|
2374
|
+
eventType: event.type
|
|
2375
|
+
});
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2378
|
+
try {
|
|
2379
|
+
this.logger.debug("Processing event", { eventType: event.type });
|
|
2380
|
+
const enhancedEvent = this.enhanceWithAffiliateParams(event);
|
|
2381
|
+
switch (event.type) {
|
|
2382
|
+
case "product_view" /* PRODUCT_VIEW */:
|
|
2383
|
+
this.trackProductView(enhancedEvent);
|
|
2384
|
+
break;
|
|
2385
|
+
case "collection_view" /* COLLECTION_VIEW */:
|
|
2386
|
+
this.trackCollectionView(enhancedEvent);
|
|
2387
|
+
break;
|
|
2388
|
+
case "page_view" /* PAGE_VIEW */:
|
|
2389
|
+
this.trackPageView(enhancedEvent);
|
|
2390
|
+
break;
|
|
2391
|
+
default:
|
|
2392
|
+
this.logger.debug("Event not supported", { eventType: event.type });
|
|
2393
|
+
break;
|
|
2394
|
+
}
|
|
2395
|
+
} catch (error) {
|
|
2396
|
+
this.logger.error("Error tracking KwikPass event", error, {
|
|
2397
|
+
eventType: event.type
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
/**
|
|
2402
|
+
* Send event to KwikPass platform
|
|
2403
|
+
*/
|
|
2404
|
+
sendKwikPassEvent(type, eventData) {
|
|
2405
|
+
this.logger.debug(`Sending ${type}`, { eventData });
|
|
2406
|
+
if (typeof window !== "undefined") {
|
|
2407
|
+
const customEvent = new CustomEvent(`page_view_kp`, {
|
|
2408
|
+
detail: {
|
|
2409
|
+
type,
|
|
2410
|
+
detail: eventData
|
|
2411
|
+
}
|
|
2412
|
+
});
|
|
2413
|
+
window.dispatchEvent(customEvent);
|
|
2414
|
+
this.logger.debug(`${type} sent successfully`);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
/**
|
|
2418
|
+
* Track product view event
|
|
2419
|
+
*/
|
|
2420
|
+
trackCollectionView(event) {
|
|
2421
|
+
this.sendKwikPassEvent("collection", {
|
|
2422
|
+
product_id: event.productId,
|
|
2423
|
+
product_name: event.productName,
|
|
2424
|
+
price: event.price,
|
|
2425
|
+
currency: event.currency,
|
|
2426
|
+
category: event.category,
|
|
2427
|
+
timestamp: event.timestamp || Date.now()
|
|
2428
|
+
});
|
|
2429
|
+
}
|
|
2430
|
+
/**
|
|
2431
|
+
* Track collection view event
|
|
2432
|
+
*/
|
|
2433
|
+
trackProductView(event) {
|
|
2434
|
+
this.sendKwikPassEvent("product", {
|
|
2435
|
+
product_id: event.productId,
|
|
2436
|
+
product_name: event.productName,
|
|
2437
|
+
price: event.price,
|
|
2438
|
+
currency: event.currency,
|
|
2439
|
+
category: event.category,
|
|
2440
|
+
timestamp: event.timestamp || Date.now()
|
|
2441
|
+
});
|
|
2442
|
+
}
|
|
2443
|
+
/**
|
|
2444
|
+
* Track page view event
|
|
2445
|
+
*/
|
|
2446
|
+
trackPageView(event) {
|
|
2447
|
+
this.sendKwikPassEvent("other", {
|
|
2448
|
+
path: event.path,
|
|
2449
|
+
title: event.title,
|
|
2450
|
+
referrer: event.referrer,
|
|
2451
|
+
timestamp: event.timestamp || Date.now()
|
|
2452
|
+
});
|
|
2453
|
+
}
|
|
2454
|
+
};
|
|
2455
|
+
|
|
2456
|
+
// src/adapters/kwik-checkout-adapter.ts
|
|
2457
|
+
var KwikCheckoutAdapter = class extends BaseAdapter {
|
|
2458
|
+
constructor(config) {
|
|
2459
|
+
super(config);
|
|
2460
|
+
this.name = "KwikCheckout";
|
|
2461
|
+
this.mid = config.mid || "";
|
|
2462
|
+
this.environment = config.environment || "production";
|
|
2463
|
+
this.storeId = config.storeId || "";
|
|
2464
|
+
this.initializeLogger();
|
|
2465
|
+
}
|
|
2466
|
+
/**
|
|
2467
|
+
* Initialize the GoKwik adapter
|
|
2468
|
+
*/
|
|
2469
|
+
async initialize() {
|
|
2470
|
+
try {
|
|
2471
|
+
if (typeof window !== "undefined") {
|
|
2472
|
+
this.logger.info("GoKwik adapter initialized successfully", {
|
|
2473
|
+
mid: this.mid,
|
|
2474
|
+
environment: this.environment,
|
|
2475
|
+
storeId: this.storeId
|
|
2476
|
+
});
|
|
2477
|
+
}
|
|
2478
|
+
this.initialized = true;
|
|
2479
|
+
} catch (error) {
|
|
2480
|
+
this.logger.error("Failed to initialize GoKwik adapter", error);
|
|
2481
|
+
throw error;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
/**
|
|
2485
|
+
* Track an event using GoKwik
|
|
2486
|
+
*/
|
|
2487
|
+
async trackEvent(event) {
|
|
2488
|
+
if (!this.initialized || typeof window === "undefined") {
|
|
2489
|
+
this.logger.warn(
|
|
2490
|
+
"GoKwik adapter not initialized or not in browser environment"
|
|
2491
|
+
);
|
|
2492
|
+
return;
|
|
2493
|
+
}
|
|
2494
|
+
try {
|
|
2495
|
+
this.logger.debug("Processing event", { eventType: event.type });
|
|
2496
|
+
const enhancedEvent = this.enhanceWithAffiliateParams(event);
|
|
2497
|
+
switch (event.type) {
|
|
2498
|
+
case "started_checkout_gk" /* STARTED_CHECKOUT_GK */:
|
|
2499
|
+
this.trackStartedCheckoutGK(enhancedEvent);
|
|
2500
|
+
break;
|
|
2501
|
+
case "mobile_added_gk" /* MOBILE_ADDED_GK */:
|
|
2502
|
+
this.trackMobileAddedGK(enhancedEvent);
|
|
2503
|
+
break;
|
|
2504
|
+
case "address_selected_gk" /* ADDRESS_SELECTED_GK */:
|
|
2505
|
+
this.trackAddressSelectedGK(enhancedEvent);
|
|
2506
|
+
break;
|
|
2507
|
+
case "address_completed_gk" /* ADDRESS_COMPLETED_GK */:
|
|
2508
|
+
this.trackAddressCompletedGK(enhancedEvent);
|
|
2509
|
+
break;
|
|
2510
|
+
case "address_added_gk" /* ADDRESS_ADDED_GK */:
|
|
2511
|
+
this.trackAddressAddedGK(enhancedEvent);
|
|
2512
|
+
break;
|
|
2513
|
+
case "pin_code_added_gk" /* PIN_CODE_ADDED_GK */:
|
|
2514
|
+
this.trackPinCodeAddedGK(enhancedEvent);
|
|
2515
|
+
break;
|
|
2516
|
+
case "payment_method_selected_gk" /* PAYMENT_METHOD_SELECTED_GK */:
|
|
2517
|
+
this.trackPaymentMethodSelectedGK(enhancedEvent);
|
|
2518
|
+
break;
|
|
2519
|
+
case "payment_completed_gk" /* PAYMENT_COMPLETED_GK */:
|
|
2520
|
+
this.trackPaymentCompletedGK(enhancedEvent);
|
|
2521
|
+
break;
|
|
2522
|
+
case "order_success" /* ORDER_SUCCESS */:
|
|
2523
|
+
this.trackOrderSuccess(enhancedEvent);
|
|
2524
|
+
break;
|
|
2525
|
+
case "order_completed" /* ORDER_COMPLETED */:
|
|
2526
|
+
this.trackOrderCompleted(enhancedEvent);
|
|
2527
|
+
break;
|
|
2528
|
+
case "cart_viewed" /* CART_VIEWED */:
|
|
2529
|
+
this.trackCartViewed(enhancedEvent);
|
|
2530
|
+
break;
|
|
2531
|
+
case "checkout_started" /* CHECKOUT_STARTED */:
|
|
2532
|
+
this.trackCheckoutStarted(enhancedEvent);
|
|
2533
|
+
break;
|
|
2534
|
+
case "checkout_completed" /* CHECKOUT_COMPLETED */:
|
|
2535
|
+
this.trackCheckoutCompleted(enhancedEvent);
|
|
2536
|
+
break;
|
|
2537
|
+
case "add_payment_info" /* ADD_PAYMENT_INFO */:
|
|
2538
|
+
this.trackAddPaymentInfo(enhancedEvent);
|
|
2539
|
+
break;
|
|
2540
|
+
default:
|
|
2541
|
+
this.logger.debug("Event not supported", { eventType: event.type });
|
|
2542
|
+
break;
|
|
2543
|
+
}
|
|
2544
|
+
} catch (error) {
|
|
2545
|
+
this.logger.error("Error tracking GoKwik event", error, {
|
|
2546
|
+
eventType: event.type
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
/**
|
|
2551
|
+
* Send event to GoKwik platform
|
|
2552
|
+
*/
|
|
2553
|
+
sendGoKwikEvent(eventName, eventData) {
|
|
2554
|
+
this.logger.debug(`Sending ${eventName}`, { eventData });
|
|
2555
|
+
if (typeof window !== "undefined" && window.gokwikSdk) {
|
|
2556
|
+
try {
|
|
2557
|
+
window.gokwikSdk.track?.(eventName, eventData);
|
|
2558
|
+
this.logger.debug(`${eventName} sent via SDK successfully`);
|
|
2559
|
+
} catch (error) {
|
|
2560
|
+
this.logger.error(
|
|
2561
|
+
`Error sending GoKwik event ${eventName} via SDK`,
|
|
2562
|
+
error
|
|
2563
|
+
);
|
|
2564
|
+
}
|
|
2565
|
+
} else {
|
|
2566
|
+
if (typeof window !== "undefined") {
|
|
2567
|
+
const customEvent = new CustomEvent(`gokwik_${eventName}`, {
|
|
2568
|
+
detail: eventData
|
|
2569
|
+
});
|
|
2570
|
+
window.dispatchEvent(customEvent);
|
|
2571
|
+
this.logger.debug(`${eventName} sent via custom event successfully`);
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
/**
|
|
2576
|
+
* Track started checkout GK event
|
|
2577
|
+
*/
|
|
2578
|
+
trackStartedCheckoutGK(event) {
|
|
2579
|
+
this.sendGoKwikEvent("started_checkout", {
|
|
2580
|
+
cart_value: event.cartValue,
|
|
2581
|
+
currency: event.currency,
|
|
2582
|
+
timestamp: event.timestamp || Date.now()
|
|
2583
|
+
});
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* Track mobile added GK event
|
|
2587
|
+
*/
|
|
2588
|
+
trackMobileAddedGK(event) {
|
|
2589
|
+
this.sendGoKwikEvent("mobile_added", {
|
|
2590
|
+
mobile: event.mobile,
|
|
2591
|
+
timestamp: event.timestamp || Date.now()
|
|
2592
|
+
});
|
|
2593
|
+
}
|
|
2594
|
+
/**
|
|
2595
|
+
* Track address selected GK event
|
|
2596
|
+
*/
|
|
2597
|
+
trackAddressSelectedGK(event) {
|
|
2598
|
+
this.sendGoKwikEvent("address_selected", {
|
|
2599
|
+
address_id: event.addressId,
|
|
2600
|
+
timestamp: event.timestamp || Date.now()
|
|
2601
|
+
});
|
|
2602
|
+
}
|
|
2603
|
+
/**
|
|
2604
|
+
* Track address completed GK event
|
|
2605
|
+
*/
|
|
2606
|
+
trackAddressCompletedGK(event) {
|
|
2607
|
+
this.sendGoKwikEvent("address_completed", {
|
|
2608
|
+
address_id: event.addressId,
|
|
2609
|
+
timestamp: event.timestamp || Date.now()
|
|
2610
|
+
});
|
|
2611
|
+
}
|
|
2612
|
+
/**
|
|
2613
|
+
* Track address added GK event
|
|
2614
|
+
*/
|
|
2615
|
+
trackAddressAddedGK(event) {
|
|
2616
|
+
this.sendGoKwikEvent("address_added", {
|
|
2617
|
+
address_id: event.addressId,
|
|
2618
|
+
timestamp: event.timestamp || Date.now()
|
|
2619
|
+
});
|
|
2620
|
+
}
|
|
2621
|
+
/**
|
|
2622
|
+
* Track PIN code added GK event
|
|
2623
|
+
*/
|
|
2624
|
+
trackPinCodeAddedGK(event) {
|
|
2625
|
+
this.sendGoKwikEvent("pin_code_added", {
|
|
2626
|
+
pin_code: event.pinCode,
|
|
2627
|
+
timestamp: event.timestamp || Date.now()
|
|
2628
|
+
});
|
|
2629
|
+
}
|
|
2630
|
+
/**
|
|
2631
|
+
* Track payment method selected GK event
|
|
2632
|
+
*/
|
|
2633
|
+
trackPaymentMethodSelectedGK(event) {
|
|
2634
|
+
this.sendGoKwikEvent("payment_method_selected", {
|
|
2635
|
+
payment_method: event.paymentMethod,
|
|
2636
|
+
timestamp: event.timestamp || Date.now()
|
|
2637
|
+
});
|
|
2638
|
+
}
|
|
2639
|
+
/**
|
|
2640
|
+
* Track payment completed GK event
|
|
2641
|
+
*/
|
|
2642
|
+
trackPaymentCompletedGK(event) {
|
|
2643
|
+
this.sendGoKwikEvent("payment_completed", {
|
|
2644
|
+
amount: event.amount,
|
|
2645
|
+
currency: event.currency,
|
|
2646
|
+
timestamp: event.timestamp || Date.now()
|
|
2647
|
+
});
|
|
2648
|
+
}
|
|
2649
|
+
/**
|
|
2650
|
+
* Track order success event
|
|
2651
|
+
*/
|
|
2652
|
+
trackOrderSuccess(event) {
|
|
2653
|
+
this.sendGoKwikEvent("order_success", {
|
|
2654
|
+
order_id: event.orderId,
|
|
2655
|
+
amount: event.amount,
|
|
2656
|
+
currency: event.currency,
|
|
2657
|
+
timestamp: event.timestamp || Date.now()
|
|
2658
|
+
});
|
|
2659
|
+
}
|
|
2660
|
+
/**
|
|
2661
|
+
* Track order completed event
|
|
2662
|
+
*/
|
|
2663
|
+
trackOrderCompleted(event) {
|
|
2664
|
+
this.sendGoKwikEvent("order_completed", {
|
|
2665
|
+
order_id: event.orderId,
|
|
2666
|
+
amount: event.amount,
|
|
2667
|
+
currency: event.currency,
|
|
2668
|
+
timestamp: event.timestamp || Date.now()
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
/**
|
|
2672
|
+
* Track cart viewed event
|
|
2673
|
+
*/
|
|
2674
|
+
trackCartViewed(event) {
|
|
2675
|
+
this.sendGoKwikEvent("cart_viewed", {
|
|
2676
|
+
cart_id: event.cartId,
|
|
2677
|
+
products: event.products,
|
|
2678
|
+
timestamp: event.timestamp || Date.now()
|
|
2679
|
+
});
|
|
2680
|
+
}
|
|
2681
|
+
/**
|
|
2682
|
+
* Track checkout started event
|
|
2683
|
+
*/
|
|
2684
|
+
trackCheckoutStarted(event) {
|
|
2685
|
+
this.sendGoKwikEvent("checkout_started", {
|
|
2686
|
+
cart_value: event.cartValue,
|
|
2687
|
+
currency: event.currency,
|
|
2688
|
+
item_count: event.itemCount,
|
|
2689
|
+
items: event.items,
|
|
2690
|
+
timestamp: event.timestamp || Date.now()
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
/**
|
|
2694
|
+
* Track checkout completed event
|
|
2695
|
+
*/
|
|
2696
|
+
trackCheckoutCompleted(event) {
|
|
2697
|
+
this.sendGoKwikEvent("checkout_completed", {
|
|
2698
|
+
order_id: event.orderId,
|
|
2699
|
+
cart_value: event.cartValue,
|
|
2700
|
+
currency: event.currency,
|
|
2701
|
+
item_count: event.itemCount,
|
|
2702
|
+
items: event.items,
|
|
2703
|
+
timestamp: event.timestamp || Date.now()
|
|
2704
|
+
});
|
|
2705
|
+
}
|
|
2706
|
+
/**
|
|
2707
|
+
* Track add payment info event
|
|
2708
|
+
*/
|
|
2709
|
+
trackAddPaymentInfo(event) {
|
|
2710
|
+
this.sendGoKwikEvent("add_payment_info", {
|
|
2711
|
+
cart_value: event.cartValue,
|
|
2712
|
+
currency: event.currency,
|
|
2713
|
+
item_count: event.itemCount,
|
|
2714
|
+
payment_type: event.paymentType,
|
|
2715
|
+
items: event.items,
|
|
2716
|
+
timestamp: event.timestamp || Date.now()
|
|
2717
|
+
});
|
|
2718
|
+
}
|
|
2719
|
+
};
|
|
2720
|
+
|
|
2721
|
+
// src/events/init.ts
|
|
2722
|
+
async function initializeEventTracking(adapters) {
|
|
2723
|
+
const { eventSubscriber: eventSubscriber2 } = await Promise.resolve().then(() => (init_subscriber(), subscriber_exports));
|
|
2724
|
+
for (const adapter of adapters) {
|
|
2725
|
+
eventSubscriber2.registerAdapter(adapter);
|
|
2726
|
+
}
|
|
2727
|
+
await eventSubscriber2.initialize();
|
|
2728
|
+
}
|
|
2729
|
+
async function initTracking(config) {
|
|
2730
|
+
console.log("Initializing event tracking system...");
|
|
2731
|
+
const adapters = [];
|
|
2732
|
+
if (config.pixelId) {
|
|
2733
|
+
const pixelAdapter = new PixelAdapter({
|
|
2734
|
+
pixelId: config.pixelId
|
|
2735
|
+
});
|
|
2736
|
+
adapters.push(pixelAdapter);
|
|
2737
|
+
}
|
|
2738
|
+
if (config.gaId) {
|
|
2739
|
+
const gaAdapter = new GoogleAdapter({
|
|
2740
|
+
measurementId: config.gaId
|
|
2741
|
+
});
|
|
2742
|
+
adapters.push(gaAdapter);
|
|
2743
|
+
}
|
|
2744
|
+
if (config.moengageAppId) {
|
|
2745
|
+
const moengageAdapter = new MoengageAdapter({
|
|
2746
|
+
appId: config.moengageAppId,
|
|
2747
|
+
enableUserIdentification: true,
|
|
2748
|
+
region: config.moengageRegion || "dc_01",
|
|
2749
|
+
debug: config.enableDebugLogs || false
|
|
2750
|
+
});
|
|
2751
|
+
adapters.push(moengageAdapter);
|
|
2752
|
+
}
|
|
2753
|
+
const posthogAdapter = new PostHogAdapter({
|
|
2754
|
+
enableDebugLogs: config.enableDebugLogs || false
|
|
2755
|
+
});
|
|
2756
|
+
adapters.push(posthogAdapter);
|
|
2757
|
+
console.log(
|
|
2758
|
+
"Configured adapters:",
|
|
2759
|
+
adapters.map((a) => a.name)
|
|
2760
|
+
);
|
|
2761
|
+
await initializeEventTracking(adapters);
|
|
2762
|
+
console.log("Event tracking system initialized successfully");
|
|
2763
|
+
}
|
|
2764
|
+
|
|
2765
|
+
// src/affiliate/AffiliateTracker.tsx
|
|
2766
|
+
var import_react = require("react");
|
|
2767
|
+
|
|
2768
|
+
// src/affiliate/constants.ts
|
|
2769
|
+
var UTM_PARAMETERS = [
|
|
2770
|
+
"utm_source",
|
|
2771
|
+
"utm_medium",
|
|
2772
|
+
"utm_campaign",
|
|
2773
|
+
"utm_term",
|
|
2774
|
+
"utm_content"
|
|
2775
|
+
];
|
|
2776
|
+
var CLICK_ID_PARAMETERS = [
|
|
2777
|
+
"gclid",
|
|
2778
|
+
// Google Ads
|
|
2779
|
+
"fbclid",
|
|
2780
|
+
// Facebook
|
|
2781
|
+
"msclkid",
|
|
2782
|
+
// Microsoft Ads
|
|
2783
|
+
"ttclid",
|
|
2784
|
+
// TikTok
|
|
2785
|
+
"twclid",
|
|
2786
|
+
// Twitter
|
|
2787
|
+
"li_fat_id"
|
|
2788
|
+
// LinkedIn
|
|
2789
|
+
];
|
|
2790
|
+
var AFFILIATE_PARAMETERS = [
|
|
2791
|
+
"click_id",
|
|
2792
|
+
"affiliate_id",
|
|
2793
|
+
"ref",
|
|
2794
|
+
"source",
|
|
2795
|
+
"referrer"
|
|
2796
|
+
];
|
|
2797
|
+
var ALL_AFFILIATE_PARAMETERS = [
|
|
2798
|
+
...UTM_PARAMETERS,
|
|
2799
|
+
...CLICK_ID_PARAMETERS,
|
|
2800
|
+
...AFFILIATE_PARAMETERS
|
|
2801
|
+
];
|
|
2802
|
+
var STORAGE_CONFIG = {
|
|
2803
|
+
DEFAULT_KEY: "affiliateParams",
|
|
2804
|
+
DEFAULT_TTL: 30 * 24 * 60 * 60 * 1e3
|
|
2805
|
+
// 30 days in milliseconds
|
|
2806
|
+
};
|
|
2807
|
+
var ATTRIBUTION_MODELS = {
|
|
2808
|
+
FIRST_TOUCH: "first-touch",
|
|
2809
|
+
LAST_TOUCH: "last-touch"
|
|
2810
|
+
};
|
|
2811
|
+
var STORAGE_TYPES = {
|
|
2812
|
+
SESSION: "sessionStorage",
|
|
2813
|
+
LOCAL: "localStorage"
|
|
2814
|
+
};
|
|
2815
|
+
|
|
2816
|
+
// src/affiliate/affiliate-tracker.ts
|
|
2817
|
+
var DEFAULT_CONFIG = {
|
|
2818
|
+
storageKey: STORAGE_CONFIG.DEFAULT_KEY,
|
|
2819
|
+
storageType: STORAGE_TYPES.SESSION,
|
|
2820
|
+
attribution: ATTRIBUTION_MODELS.LAST_TOUCH,
|
|
2821
|
+
ttl: STORAGE_CONFIG.DEFAULT_TTL,
|
|
2822
|
+
customParams: [],
|
|
2823
|
+
enableReferrerCapture: true,
|
|
2824
|
+
enableUserAgentCapture: false,
|
|
2825
|
+
onCapture: () => {
|
|
2826
|
+
},
|
|
2827
|
+
onError: () => {
|
|
2828
|
+
}
|
|
2829
|
+
};
|
|
2830
|
+
var currentConfig = { ...DEFAULT_CONFIG };
|
|
2831
|
+
var eventListeners = [];
|
|
2832
|
+
function configureAffiliateTracker(config = {}) {
|
|
2833
|
+
currentConfig = { ...DEFAULT_CONFIG, ...config };
|
|
2834
|
+
}
|
|
2835
|
+
function generateSessionId() {
|
|
2836
|
+
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2837
|
+
}
|
|
2838
|
+
function getStorage() {
|
|
2839
|
+
if (typeof window === "undefined") return null;
|
|
2840
|
+
try {
|
|
2841
|
+
return currentConfig.storageType === "localStorage" ? window.localStorage : window.sessionStorage;
|
|
2842
|
+
} catch (error) {
|
|
2843
|
+
currentConfig.onError(new Error(`Storage not available: ${error}`));
|
|
2844
|
+
return null;
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
function isExpired(timestamp) {
|
|
2848
|
+
return Date.now() - timestamp > currentConfig.ttl;
|
|
2849
|
+
}
|
|
2850
|
+
function emitEvent(event) {
|
|
2851
|
+
eventListeners.forEach((listener) => {
|
|
2852
|
+
try {
|
|
2853
|
+
listener(event);
|
|
2854
|
+
} catch (error) {
|
|
2855
|
+
currentConfig.onError(new Error(`Event listener error: ${error}`));
|
|
2856
|
+
}
|
|
2857
|
+
});
|
|
2858
|
+
}
|
|
2859
|
+
function addEventListener(listener) {
|
|
2860
|
+
eventListeners.push(listener);
|
|
2861
|
+
return () => {
|
|
2862
|
+
const index = eventListeners.indexOf(listener);
|
|
2863
|
+
if (index > -1) {
|
|
2864
|
+
eventListeners.splice(index, 1);
|
|
2865
|
+
}
|
|
2866
|
+
};
|
|
2867
|
+
}
|
|
2868
|
+
function captureAffiliateParams(customConfig) {
|
|
2869
|
+
if (typeof window === "undefined") return null;
|
|
2870
|
+
const originalConfig = currentConfig;
|
|
2871
|
+
if (customConfig) {
|
|
2872
|
+
currentConfig = { ...currentConfig, ...customConfig };
|
|
2873
|
+
}
|
|
2874
|
+
try {
|
|
2875
|
+
const storage = getStorage();
|
|
2876
|
+
if (!storage) return null;
|
|
2877
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
2878
|
+
const allKeys = [
|
|
2879
|
+
...ALL_AFFILIATE_PARAMETERS,
|
|
2880
|
+
...currentConfig.customParams
|
|
2881
|
+
];
|
|
2882
|
+
const affiliateParams = {};
|
|
2883
|
+
for (const key of allKeys) {
|
|
2884
|
+
const value = urlParams.get(key);
|
|
2885
|
+
if (value) {
|
|
2886
|
+
affiliateParams[key] = value;
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
if (currentConfig.enableReferrerCapture && document.referrer) {
|
|
2890
|
+
affiliateParams.referrer = document.referrer;
|
|
2891
|
+
}
|
|
2892
|
+
if (Object.keys(affiliateParams).length === 0) {
|
|
2893
|
+
return null;
|
|
2894
|
+
}
|
|
2895
|
+
const existingData = getAffiliateParams();
|
|
2896
|
+
let shouldUpdate = true;
|
|
2897
|
+
if (existingData && currentConfig.attribution === "first-touch") {
|
|
2898
|
+
shouldUpdate = false;
|
|
2899
|
+
}
|
|
2900
|
+
if (shouldUpdate) {
|
|
2901
|
+
const affiliateData = {
|
|
2902
|
+
...affiliateParams,
|
|
2903
|
+
timestamp: Date.now(),
|
|
2904
|
+
sessionId: generateSessionId(),
|
|
2905
|
+
attribution: currentConfig.attribution,
|
|
2906
|
+
url: window.location.href,
|
|
2907
|
+
...currentConfig.enableUserAgentCapture && {
|
|
2908
|
+
userAgent: navigator.userAgent
|
|
2909
|
+
}
|
|
2910
|
+
};
|
|
2911
|
+
storage.setItem(currentConfig.storageKey, JSON.stringify(affiliateData));
|
|
2912
|
+
emitEvent({
|
|
2913
|
+
type: "capture",
|
|
2914
|
+
data: affiliateData,
|
|
2915
|
+
timestamp: Date.now()
|
|
2916
|
+
});
|
|
2917
|
+
currentConfig.onCapture(affiliateData);
|
|
2918
|
+
return affiliateData;
|
|
2919
|
+
}
|
|
2920
|
+
return existingData;
|
|
2921
|
+
} catch (error) {
|
|
2922
|
+
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
2923
|
+
currentConfig.onError(errorObj);
|
|
2924
|
+
return null;
|
|
2925
|
+
} finally {
|
|
2926
|
+
if (customConfig) {
|
|
2927
|
+
currentConfig = originalConfig;
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
function getAffiliateParams() {
|
|
2932
|
+
if (typeof window === "undefined") return null;
|
|
2933
|
+
try {
|
|
2934
|
+
const storage = getStorage();
|
|
2935
|
+
if (!storage) return null;
|
|
2936
|
+
const stored = storage.getItem(currentConfig.storageKey);
|
|
2937
|
+
if (!stored) return null;
|
|
2938
|
+
const data = JSON.parse(stored);
|
|
2939
|
+
if (isExpired(data.timestamp)) {
|
|
2940
|
+
clearAffiliateParams();
|
|
2941
|
+
emitEvent({
|
|
2942
|
+
type: "expire",
|
|
2943
|
+
data,
|
|
2944
|
+
timestamp: Date.now()
|
|
2945
|
+
});
|
|
2946
|
+
return null;
|
|
2947
|
+
}
|
|
2948
|
+
return data;
|
|
2949
|
+
} catch (error) {
|
|
2950
|
+
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
2951
|
+
currentConfig.onError(errorObj);
|
|
2952
|
+
return null;
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
function clearAffiliateParams() {
|
|
2956
|
+
if (typeof window === "undefined") return;
|
|
2957
|
+
try {
|
|
2958
|
+
const storage = getStorage();
|
|
2959
|
+
if (!storage) return;
|
|
2960
|
+
const existingData = getAffiliateParams();
|
|
2961
|
+
storage.removeItem(currentConfig.storageKey);
|
|
2962
|
+
emitEvent({
|
|
2963
|
+
type: "clear",
|
|
2964
|
+
data: existingData || void 0,
|
|
2965
|
+
timestamp: Date.now()
|
|
2966
|
+
});
|
|
2967
|
+
} catch (error) {
|
|
2968
|
+
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
2969
|
+
currentConfig.onError(errorObj);
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
function hasAffiliateData() {
|
|
2973
|
+
return getAffiliateParams() !== null;
|
|
2974
|
+
}
|
|
2975
|
+
function getAffiliateSource() {
|
|
2976
|
+
const data = getAffiliateParams();
|
|
2977
|
+
if (!data) return null;
|
|
2978
|
+
if (data.utm_source) return data.utm_source;
|
|
2979
|
+
if (data.referrer) {
|
|
2980
|
+
try {
|
|
2981
|
+
return new URL(data.referrer).hostname;
|
|
2982
|
+
} catch {
|
|
2983
|
+
return data.referrer;
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
return null;
|
|
2987
|
+
}
|
|
2988
|
+
|
|
2989
|
+
// src/affiliate/AffiliateTracker.tsx
|
|
2990
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
2991
|
+
var AffiliateTracker = ({
|
|
2992
|
+
config,
|
|
2993
|
+
autoCapture = true,
|
|
2994
|
+
children
|
|
2995
|
+
}) => {
|
|
2996
|
+
(0, import_react.useEffect)(() => {
|
|
2997
|
+
if (config) {
|
|
2998
|
+
configureAffiliateTracker(config);
|
|
2999
|
+
}
|
|
3000
|
+
if (autoCapture) {
|
|
3001
|
+
captureAffiliateParams();
|
|
3002
|
+
}
|
|
3003
|
+
}, [config, autoCapture]);
|
|
3004
|
+
return children ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children }) : null;
|
|
3005
|
+
};
|
|
3006
|
+
var AffiliateTracker_default = AffiliateTracker;
|
|
3007
|
+
|
|
3008
|
+
// src/affiliate/hooks.ts
|
|
3009
|
+
var import_react2 = require("react");
|
|
3010
|
+
function useAffiliateTracker(config) {
|
|
3011
|
+
const [affiliateParams, setAffiliateParams] = (0, import_react2.useState)(
|
|
3012
|
+
null
|
|
3013
|
+
);
|
|
3014
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
|
|
3015
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
3016
|
+
const configRef = (0, import_react2.useRef)(config);
|
|
3017
|
+
(0, import_react2.useEffect)(() => {
|
|
3018
|
+
configRef.current = config;
|
|
3019
|
+
}, [config]);
|
|
3020
|
+
(0, import_react2.useEffect)(() => {
|
|
3021
|
+
if (configRef.current) {
|
|
3022
|
+
configureAffiliateTracker({
|
|
3023
|
+
...configRef.current,
|
|
3024
|
+
onError: (err) => {
|
|
3025
|
+
setError(err);
|
|
3026
|
+
configRef.current?.onError?.(err);
|
|
3027
|
+
}
|
|
3028
|
+
});
|
|
3029
|
+
}
|
|
3030
|
+
}, []);
|
|
3031
|
+
const refreshParams = (0, import_react2.useCallback)(() => {
|
|
3032
|
+
setIsLoading(true);
|
|
3033
|
+
setError(null);
|
|
3034
|
+
try {
|
|
3035
|
+
const params = getAffiliateParams();
|
|
3036
|
+
setAffiliateParams(params);
|
|
3037
|
+
} catch (err) {
|
|
3038
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
3039
|
+
setError(error2);
|
|
3040
|
+
} finally {
|
|
3041
|
+
setIsLoading(false);
|
|
3042
|
+
}
|
|
3043
|
+
}, []);
|
|
3044
|
+
const captureParams = (0, import_react2.useCallback)(() => {
|
|
3045
|
+
setError(null);
|
|
3046
|
+
try {
|
|
3047
|
+
const params = captureAffiliateParams(configRef.current);
|
|
3048
|
+
setAffiliateParams(params);
|
|
3049
|
+
} catch (err) {
|
|
3050
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
3051
|
+
setError(error2);
|
|
3052
|
+
}
|
|
3053
|
+
}, []);
|
|
3054
|
+
const clearParams = (0, import_react2.useCallback)(() => {
|
|
3055
|
+
setError(null);
|
|
3056
|
+
try {
|
|
3057
|
+
clearAffiliateParams();
|
|
3058
|
+
setAffiliateParams(null);
|
|
3059
|
+
} catch (err) {
|
|
3060
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
3061
|
+
setError(error2);
|
|
3062
|
+
}
|
|
3063
|
+
}, []);
|
|
3064
|
+
(0, import_react2.useEffect)(() => {
|
|
3065
|
+
const unsubscribe = addEventListener((event) => {
|
|
3066
|
+
switch (event.type) {
|
|
3067
|
+
case "capture":
|
|
3068
|
+
setAffiliateParams(event.data || null);
|
|
3069
|
+
break;
|
|
3070
|
+
case "clear":
|
|
3071
|
+
case "expire":
|
|
3072
|
+
setAffiliateParams(null);
|
|
3073
|
+
break;
|
|
3074
|
+
}
|
|
3075
|
+
});
|
|
3076
|
+
return unsubscribe;
|
|
3077
|
+
}, []);
|
|
3078
|
+
(0, import_react2.useEffect)(() => {
|
|
3079
|
+
refreshParams();
|
|
3080
|
+
}, [refreshParams]);
|
|
3081
|
+
return {
|
|
3082
|
+
affiliateParams,
|
|
3083
|
+
isLoading,
|
|
3084
|
+
error,
|
|
3085
|
+
captureParams,
|
|
3086
|
+
clearParams,
|
|
3087
|
+
refreshParams
|
|
3088
|
+
};
|
|
3089
|
+
}
|
|
3090
|
+
function useHasAffiliateData() {
|
|
3091
|
+
const [hasData, setHasData] = (0, import_react2.useState)(false);
|
|
3092
|
+
(0, import_react2.useEffect)(() => {
|
|
3093
|
+
const checkData = () => {
|
|
3094
|
+
setHasData(hasAffiliateData());
|
|
3095
|
+
};
|
|
3096
|
+
checkData();
|
|
3097
|
+
const unsubscribe = addEventListener(() => {
|
|
3098
|
+
checkData();
|
|
3099
|
+
});
|
|
3100
|
+
return unsubscribe;
|
|
3101
|
+
}, []);
|
|
3102
|
+
return hasData;
|
|
3103
|
+
}
|
|
3104
|
+
function useAffiliateSource() {
|
|
3105
|
+
const [source, setSource] = (0, import_react2.useState)(null);
|
|
3106
|
+
(0, import_react2.useEffect)(() => {
|
|
3107
|
+
const updateSource = () => {
|
|
3108
|
+
setSource(getAffiliateSource());
|
|
3109
|
+
};
|
|
3110
|
+
updateSource();
|
|
3111
|
+
const unsubscribe = addEventListener(() => {
|
|
3112
|
+
updateSource();
|
|
3113
|
+
});
|
|
3114
|
+
return unsubscribe;
|
|
3115
|
+
}, []);
|
|
3116
|
+
return source;
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3119
|
+
// src/ShopkitAnalytics.tsx
|
|
3120
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
3121
|
+
var ShopkitAnalytics = ({
|
|
3122
|
+
config,
|
|
3123
|
+
children,
|
|
3124
|
+
onInitialized,
|
|
3125
|
+
onError
|
|
3126
|
+
}) => {
|
|
3127
|
+
(0, import_hydrogen_react2.useShopifyCookies)({
|
|
3128
|
+
hasUserConsent: true,
|
|
3129
|
+
domain: config.shopify?.domain || ""
|
|
3130
|
+
});
|
|
3131
|
+
(0, import_react3.useEffect)(() => {
|
|
3132
|
+
const initializeAnalytics = async () => {
|
|
3133
|
+
if (config.autoInitialize === false) return;
|
|
3134
|
+
const loggerConfig = {
|
|
3135
|
+
enabled: config.logger?.enabled ?? config.enableDebugLogs ?? true,
|
|
3136
|
+
level: config.logger?.level ?? "info",
|
|
3137
|
+
name: "@shopkit/analytics",
|
|
3138
|
+
prettyPrint: config.logger?.prettyPrint ?? false
|
|
3139
|
+
};
|
|
3140
|
+
const logger2 = createLogger(loggerConfig);
|
|
3141
|
+
try {
|
|
3142
|
+
logger2.info("Starting initialization...");
|
|
3143
|
+
const adapters = [];
|
|
3144
|
+
const addLoggerConfig = (adapterConfig) => ({
|
|
3145
|
+
...adapterConfig,
|
|
3146
|
+
enableDebugLogs: loggerConfig.enabled,
|
|
3147
|
+
logLevel: loggerConfig.level
|
|
3148
|
+
});
|
|
3149
|
+
if (config.googleAnalytics) {
|
|
3150
|
+
const gaAdapter = new GoogleAdapter(
|
|
3151
|
+
addLoggerConfig(config.googleAnalytics)
|
|
3152
|
+
);
|
|
3153
|
+
adapters.push(gaAdapter);
|
|
3154
|
+
logger2.info("Added Google Analytics adapter");
|
|
3155
|
+
}
|
|
3156
|
+
if (config.facebookPixel) {
|
|
3157
|
+
const pixelAdapter = new PixelAdapter(
|
|
3158
|
+
addLoggerConfig(config.facebookPixel)
|
|
3159
|
+
);
|
|
3160
|
+
adapters.push(pixelAdapter);
|
|
3161
|
+
logger2.info("Added Facebook Pixel adapter");
|
|
3162
|
+
}
|
|
3163
|
+
if (config.moengage) {
|
|
3164
|
+
const moengageAdapter = new MoengageAdapter(
|
|
3165
|
+
addLoggerConfig(config.moengage)
|
|
3166
|
+
);
|
|
3167
|
+
adapters.push(moengageAdapter);
|
|
3168
|
+
logger2.info("Added MoEngage adapter");
|
|
3169
|
+
}
|
|
3170
|
+
if (config.posthog) {
|
|
3171
|
+
const posthogAdapter = new PostHogAdapter(
|
|
3172
|
+
addLoggerConfig(config.posthog)
|
|
3173
|
+
);
|
|
3174
|
+
adapters.push(posthogAdapter);
|
|
3175
|
+
logger2.info("Added PostHog adapter");
|
|
3176
|
+
}
|
|
3177
|
+
if (config.shopify) {
|
|
3178
|
+
const shopifyAdapter = new ShopifyAdapter(
|
|
3179
|
+
addLoggerConfig(config.shopify)
|
|
3180
|
+
);
|
|
3181
|
+
adapters.push(shopifyAdapter);
|
|
3182
|
+
logger2.info("Added Shopify Analytics adapter");
|
|
3183
|
+
}
|
|
3184
|
+
if (config.kwikpass) {
|
|
3185
|
+
const kwikpassAdapter = new KwikPassAdapter(
|
|
3186
|
+
addLoggerConfig(config.kwikpass)
|
|
3187
|
+
);
|
|
3188
|
+
adapters.push(kwikpassAdapter);
|
|
3189
|
+
logger2.info("Added KwikPass Analytics adapter");
|
|
3190
|
+
}
|
|
3191
|
+
if (config.kwikcheckout) {
|
|
3192
|
+
const kwikcheckoutAdapter = new KwikCheckoutAdapter(
|
|
3193
|
+
addLoggerConfig(config.kwikcheckout)
|
|
3194
|
+
);
|
|
3195
|
+
adapters.push(kwikcheckoutAdapter);
|
|
3196
|
+
logger2.info("Added KwikCheckout Analytics adapter");
|
|
3197
|
+
}
|
|
3198
|
+
if (config.customAdapters) {
|
|
3199
|
+
adapters.push(...config.customAdapters);
|
|
3200
|
+
logger2.info(`Added ${config.customAdapters.length} custom adapters`);
|
|
3201
|
+
}
|
|
3202
|
+
if (adapters.length === 0) {
|
|
3203
|
+
logger2.warn("No analytics adapters configured");
|
|
3204
|
+
} else {
|
|
3205
|
+
await initializeEventTracking(adapters);
|
|
3206
|
+
logger2.info("Event tracking initialized with adapters", {
|
|
3207
|
+
adapters: adapters.map((a) => a.name)
|
|
3208
|
+
});
|
|
3209
|
+
}
|
|
3210
|
+
logger2.info("Initialization completed successfully");
|
|
3211
|
+
onInitialized?.();
|
|
3212
|
+
} catch (err) {
|
|
3213
|
+
const error = err instanceof Error ? err : new Error("Unknown initialization error");
|
|
3214
|
+
logger2.error("Initialization failed", error);
|
|
3215
|
+
onError?.(error);
|
|
3216
|
+
}
|
|
3217
|
+
};
|
|
3218
|
+
initializeAnalytics();
|
|
3219
|
+
}, [config, onInitialized, onError]);
|
|
3220
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
3221
|
+
config.affiliate?.enabled !== false && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3222
|
+
AffiliateTracker_default,
|
|
3223
|
+
{
|
|
3224
|
+
config: config.affiliate?.config,
|
|
3225
|
+
autoCapture: config.affiliate?.autoCapture
|
|
3226
|
+
}
|
|
3227
|
+
),
|
|
3228
|
+
children ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children }) : null
|
|
3229
|
+
] });
|
|
3230
|
+
};
|
|
3231
|
+
var ShopkitAnalytics_default = ShopkitAnalytics;
|
|
3232
|
+
|
|
3233
|
+
// src/events/index.ts
|
|
3234
|
+
init_publisher();
|
|
3235
|
+
init_subscriber();
|
|
3236
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3237
|
+
0 && (module.exports = {
|
|
3238
|
+
AffiliateTracker,
|
|
3239
|
+
BaseAdapter,
|
|
3240
|
+
DEFAULT_CURRENCY,
|
|
3241
|
+
EventNames,
|
|
3242
|
+
EventType,
|
|
3243
|
+
GoogleAdapter,
|
|
3244
|
+
HARDCODED_HANDLE,
|
|
3245
|
+
KwikCheckoutAdapter,
|
|
3246
|
+
KwikPassAdapter,
|
|
3247
|
+
MoengageAdapter,
|
|
3248
|
+
PixelAdapter,
|
|
3249
|
+
PostHogAdapter,
|
|
3250
|
+
ShopifyAdapter,
|
|
3251
|
+
ShopkitAnalytics,
|
|
3252
|
+
captureAffiliateParams,
|
|
3253
|
+
clearAffiliateParams,
|
|
3254
|
+
createAdapterLogger,
|
|
3255
|
+
createLogger,
|
|
3256
|
+
eventPublisher,
|
|
3257
|
+
eventSubscriber,
|
|
3258
|
+
getAffiliateParams,
|
|
3259
|
+
getAffiliateSource,
|
|
3260
|
+
hasAffiliateData,
|
|
3261
|
+
initTracking,
|
|
3262
|
+
initializeEventTracking,
|
|
3263
|
+
logger,
|
|
3264
|
+
publishEvent,
|
|
3265
|
+
useAffiliateSource,
|
|
3266
|
+
useAffiliateTracker,
|
|
3267
|
+
useHasAffiliateData
|
|
3268
|
+
});
|
|
3269
|
+
//# sourceMappingURL=index.js.map
|