@metodokorexmk/tracking 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +42 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +208 -210
- package/dist/index.d.ts +208 -210
- package/dist/index.js +42 -38
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +27 -27
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +54 -54
- package/dist/react/index.d.ts +54 -54
- package/dist/react/index.js +27 -27
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -259,7 +259,7 @@ var VideoTracker = class {
|
|
|
259
259
|
this.watchTimeIntervals = /* @__PURE__ */ new Map();
|
|
260
260
|
}
|
|
261
261
|
/**
|
|
262
|
-
*
|
|
262
|
+
* Initializes tracking for a video.
|
|
263
263
|
*/
|
|
264
264
|
initVideo(videoId) {
|
|
265
265
|
if (this.videos.has(videoId)) return;
|
|
@@ -287,7 +287,7 @@ var VideoTracker = class {
|
|
|
287
287
|
});
|
|
288
288
|
}
|
|
289
289
|
/**
|
|
290
|
-
*
|
|
290
|
+
* Tracks a play event.
|
|
291
291
|
*/
|
|
292
292
|
trackPlay(videoId, currentTime = 0) {
|
|
293
293
|
const state = this.getOrCreateState(videoId);
|
|
@@ -303,7 +303,7 @@ var VideoTracker = class {
|
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
305
|
/**
|
|
306
|
-
*
|
|
306
|
+
* Tracks a pause event.
|
|
307
307
|
*/
|
|
308
308
|
trackPause(videoId, currentTime, duration) {
|
|
309
309
|
const state = this.getOrCreateState(videoId);
|
|
@@ -325,7 +325,7 @@ var VideoTracker = class {
|
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
327
|
/**
|
|
328
|
-
*
|
|
328
|
+
* Tracks a seek event (timeline jump).
|
|
329
329
|
*/
|
|
330
330
|
trackSeek(videoId, fromTime, toTime) {
|
|
331
331
|
const state = this.getOrCreateState(videoId);
|
|
@@ -340,7 +340,7 @@ var VideoTracker = class {
|
|
|
340
340
|
});
|
|
341
341
|
}
|
|
342
342
|
/**
|
|
343
|
-
*
|
|
343
|
+
* Tracks progress milestones (25%, 50%, 75%).
|
|
344
344
|
*/
|
|
345
345
|
trackProgress(videoId, percentage, currentTime) {
|
|
346
346
|
const state = this.getOrCreateState(videoId);
|
|
@@ -356,7 +356,7 @@ var VideoTracker = class {
|
|
|
356
356
|
}
|
|
357
357
|
}
|
|
358
358
|
/**
|
|
359
|
-
*
|
|
359
|
+
* Tracks video completion (>=95%).
|
|
360
360
|
*/
|
|
361
361
|
trackComplete(videoId, totalDuration) {
|
|
362
362
|
const state = this.getOrCreateState(videoId);
|
|
@@ -373,7 +373,7 @@ var VideoTracker = class {
|
|
|
373
373
|
});
|
|
374
374
|
}
|
|
375
375
|
/**
|
|
376
|
-
*
|
|
376
|
+
* Tracks video end (native ended event).
|
|
377
377
|
*/
|
|
378
378
|
trackEnd(videoId) {
|
|
379
379
|
const state = this.getOrCreateState(videoId);
|
|
@@ -386,7 +386,7 @@ var VideoTracker = class {
|
|
|
386
386
|
});
|
|
387
387
|
}
|
|
388
388
|
/**
|
|
389
|
-
*
|
|
389
|
+
* Tracks playback speed change.
|
|
390
390
|
*/
|
|
391
391
|
trackSpeedChange(videoId, speed) {
|
|
392
392
|
const state = this.getOrCreateState(videoId);
|
|
@@ -397,7 +397,7 @@ var VideoTracker = class {
|
|
|
397
397
|
});
|
|
398
398
|
}
|
|
399
399
|
/**
|
|
400
|
-
*
|
|
400
|
+
* Tracks fullscreen toggle.
|
|
401
401
|
*/
|
|
402
402
|
trackFullscreen(videoId, isFullscreen) {
|
|
403
403
|
trackEvent("Video", isFullscreen ? "fullscreen_enter" : "fullscreen_exit", videoId, void 0, {
|
|
@@ -406,7 +406,7 @@ var VideoTracker = class {
|
|
|
406
406
|
});
|
|
407
407
|
}
|
|
408
408
|
/**
|
|
409
|
-
*
|
|
409
|
+
* Tracks no interaction (user is on the page but not interacting with the video).
|
|
410
410
|
*/
|
|
411
411
|
trackNoInteraction(videoId, timeOnPage) {
|
|
412
412
|
trackEvent("Video", "no_interaction", videoId, void 0, {
|
|
@@ -415,20 +415,20 @@ var VideoTracker = class {
|
|
|
415
415
|
});
|
|
416
416
|
}
|
|
417
417
|
/**
|
|
418
|
-
*
|
|
418
|
+
* Returns the current state of a video.
|
|
419
419
|
*/
|
|
420
420
|
getState(videoId) {
|
|
421
421
|
return this.videos.get(videoId);
|
|
422
422
|
}
|
|
423
423
|
/**
|
|
424
|
-
*
|
|
424
|
+
* Cleans up tracking for a specific video.
|
|
425
425
|
*/
|
|
426
426
|
cleanup(videoId) {
|
|
427
427
|
this.stopWatchTimeTracking(videoId);
|
|
428
428
|
this.videos.delete(videoId);
|
|
429
429
|
}
|
|
430
430
|
/**
|
|
431
|
-
*
|
|
431
|
+
* Cleans up all video tracking.
|
|
432
432
|
*/
|
|
433
433
|
cleanupAll() {
|
|
434
434
|
for (const videoId of this.videos.keys()) {
|
|
@@ -436,7 +436,7 @@ var VideoTracker = class {
|
|
|
436
436
|
}
|
|
437
437
|
this.videos.clear();
|
|
438
438
|
}
|
|
439
|
-
// ---
|
|
439
|
+
// --- Private methods ---
|
|
440
440
|
getOrCreateState(videoId) {
|
|
441
441
|
if (!this.videos.has(videoId)) {
|
|
442
442
|
this.initVideo(videoId);
|
|
@@ -884,7 +884,7 @@ var LandingTracker = class {
|
|
|
884
884
|
this.listeners = [];
|
|
885
885
|
}
|
|
886
886
|
/**
|
|
887
|
-
*
|
|
887
|
+
* Initializes landing page tracking with the given configuration.
|
|
888
888
|
*/
|
|
889
889
|
init(config) {
|
|
890
890
|
if (typeof window === "undefined") return;
|
|
@@ -920,7 +920,7 @@ var LandingTracker = class {
|
|
|
920
920
|
this.trackSessionStart();
|
|
921
921
|
}
|
|
922
922
|
/**
|
|
923
|
-
*
|
|
923
|
+
* Destroys the tracker and cleans up all observers and listeners.
|
|
924
924
|
*/
|
|
925
925
|
destroy() {
|
|
926
926
|
this.observers.forEach((obs) => obs.disconnect());
|
|
@@ -936,43 +936,43 @@ var LandingTracker = class {
|
|
|
936
936
|
this.sectionTimers.clear();
|
|
937
937
|
}
|
|
938
938
|
// ====================================
|
|
939
|
-
//
|
|
939
|
+
// PUBLIC TRACKING METHODS
|
|
940
940
|
// ====================================
|
|
941
|
-
/**
|
|
941
|
+
/** Track a CTA click */
|
|
942
942
|
trackCTAClick(buttonName, section, additionalData) {
|
|
943
943
|
trackCTAClick(buttonName, section, additionalData);
|
|
944
944
|
this.pushGTMEvent("cta_click", { button_text: buttonName, section });
|
|
945
945
|
}
|
|
946
|
-
/**
|
|
946
|
+
/** Track a conversion */
|
|
947
947
|
trackConversion(type, value, additionalData) {
|
|
948
948
|
trackEvent("Conversion", type, void 0, value, additionalData);
|
|
949
949
|
this.pushGTMEvent("conversion", { conversion_type: type, value });
|
|
950
950
|
}
|
|
951
|
-
/**
|
|
951
|
+
/** Track FAQ expansion */
|
|
952
952
|
trackFAQExpand(question, index) {
|
|
953
953
|
trackEvent("FAQ", "expand", question, index);
|
|
954
954
|
}
|
|
955
|
-
/**
|
|
955
|
+
/** Track social link click */
|
|
956
956
|
trackSocialClick(platform, action) {
|
|
957
957
|
trackEvent("Social", "click", platform, void 0, { social_action: action });
|
|
958
958
|
}
|
|
959
|
-
/**
|
|
959
|
+
/** Track image click */
|
|
960
960
|
trackImageClick(imageName, section) {
|
|
961
961
|
trackEvent("Engagement", "image_click", imageName, void 0, { section });
|
|
962
962
|
}
|
|
963
|
-
/**
|
|
963
|
+
/** Track scroll to a section */
|
|
964
964
|
trackScrollTo(section) {
|
|
965
965
|
trackEvent("Navigation", "scroll_to", section);
|
|
966
966
|
}
|
|
967
|
-
/**
|
|
967
|
+
/** Track content share */
|
|
968
968
|
trackShare(platform, content) {
|
|
969
969
|
trackEvent("Share", "click", platform, void 0, { share_content: content });
|
|
970
970
|
}
|
|
971
|
-
/**
|
|
971
|
+
/** Track file download */
|
|
972
972
|
trackDownload(fileName, fileType) {
|
|
973
973
|
trackEvent("Download", "click", fileName, void 0, { file_type: fileType });
|
|
974
974
|
}
|
|
975
|
-
/**
|
|
975
|
+
/** Get current session data */
|
|
976
976
|
getSessionData() {
|
|
977
977
|
return {
|
|
978
978
|
duration: Math.round((Date.now() - this.sessionStartTime) / 1e3),
|
|
@@ -981,7 +981,7 @@ var LandingTracker = class {
|
|
|
981
981
|
};
|
|
982
982
|
}
|
|
983
983
|
// ====================================
|
|
984
|
-
//
|
|
984
|
+
// PRIVATE METHODS
|
|
985
985
|
// ====================================
|
|
986
986
|
captureInitialData() {
|
|
987
987
|
const utmParams = captureUTMParams();
|
|
@@ -1169,7 +1169,7 @@ var initTrackingAPI = (config) => {
|
|
|
1169
1169
|
};
|
|
1170
1170
|
var getAPIConfig = () => {
|
|
1171
1171
|
if (!apiConfig) {
|
|
1172
|
-
throw new Error("[@metodokorexmk/tracking] initTrackingAPI()
|
|
1172
|
+
throw new Error("[@metodokorexmk/tracking] initTrackingAPI() must be called before using persistence functions.");
|
|
1173
1173
|
}
|
|
1174
1174
|
return apiConfig;
|
|
1175
1175
|
};
|
|
@@ -1316,14 +1316,18 @@ var buildTrackingRequestBody = (params, formData, origin, options) => {
|
|
|
1316
1316
|
if (origin.hasCampaign) {
|
|
1317
1317
|
if (collaboratorId) body.userId = collaboratorId;
|
|
1318
1318
|
if (params.idCampana) body.idCampana = params.idCampana;
|
|
1319
|
-
if (params.adsetId) body.adsetId = params.adsetId;
|
|
1320
|
-
if (params.adId) body.adId = params.adId;
|
|
1321
1319
|
if (params.utmContent) body.utmContent = params.utmContent;
|
|
1322
1320
|
if (params.fbclid) body.fbclid = params.fbclid;
|
|
1323
1321
|
} else if (collaboratorId) {
|
|
1324
1322
|
body.referringUserId = collaboratorId;
|
|
1325
1323
|
body.referring_user_id = collaboratorId;
|
|
1326
1324
|
}
|
|
1325
|
+
if (params.adsetId) body.adsetId = params.adsetId;
|
|
1326
|
+
if (params.adId) body.adId = params.adId;
|
|
1327
|
+
if (params.utmSource) body.utmSource = params.utmSource;
|
|
1328
|
+
if (params.utmMedium) body.utmMedium = params.utmMedium;
|
|
1329
|
+
if (params.utmCampaign) body.utmCampaign = params.utmCampaign;
|
|
1330
|
+
if (params.leadCampaign) body.leadCampaign = params.leadCampaign;
|
|
1327
1331
|
if (params.pipelineId) {
|
|
1328
1332
|
const parsed = parseInt(params.pipelineId, 10);
|
|
1329
1333
|
if (!isNaN(parsed)) body.pipeline_id = parsed;
|
|
@@ -1422,7 +1426,7 @@ var DwellTimeTracker = class {
|
|
|
1422
1426
|
this.boundVisibilityChange = this.handleVisibilityChange.bind(this);
|
|
1423
1427
|
}
|
|
1424
1428
|
/**
|
|
1425
|
-
*
|
|
1429
|
+
* Starts dwell time tracking.
|
|
1426
1430
|
*/
|
|
1427
1431
|
start(config) {
|
|
1428
1432
|
if (typeof window === "undefined") return;
|
|
@@ -1459,7 +1463,7 @@ var DwellTimeTracker = class {
|
|
|
1459
1463
|
this.retryPendingUpdates();
|
|
1460
1464
|
}
|
|
1461
1465
|
/**
|
|
1462
|
-
*
|
|
1466
|
+
* Stops tracking and sends accumulated time.
|
|
1463
1467
|
*/
|
|
1464
1468
|
stop() {
|
|
1465
1469
|
if (this.startTime) {
|
|
@@ -1474,7 +1478,7 @@ var DwellTimeTracker = class {
|
|
|
1474
1478
|
this.cleanup();
|
|
1475
1479
|
}
|
|
1476
1480
|
/**
|
|
1477
|
-
*
|
|
1481
|
+
* Returns elapsed time in seconds (excluding paused time).
|
|
1478
1482
|
*/
|
|
1479
1483
|
getElapsedTime() {
|
|
1480
1484
|
if (!this.startTime) return 0;
|
|
@@ -1486,8 +1490,8 @@ var DwellTimeTracker = class {
|
|
|
1486
1490
|
return Math.max(0, totalTime - currentPauseTime);
|
|
1487
1491
|
}
|
|
1488
1492
|
/**
|
|
1489
|
-
*
|
|
1490
|
-
*
|
|
1493
|
+
* Manually updates video time.
|
|
1494
|
+
* Called from VideoTracker or other adapters.
|
|
1491
1495
|
*/
|
|
1492
1496
|
updateVideoTime(videoTimeWatched, videoCompleted = false) {
|
|
1493
1497
|
const hasNewTime = videoTimeWatched > this.videoTimeWatched;
|
|
@@ -1501,7 +1505,7 @@ var DwellTimeTracker = class {
|
|
|
1501
1505
|
}
|
|
1502
1506
|
}
|
|
1503
1507
|
/**
|
|
1504
|
-
*
|
|
1508
|
+
* Updates the trackingDataId (useful when obtained after registration).
|
|
1505
1509
|
*/
|
|
1506
1510
|
updateTrackingId(trackingDataId) {
|
|
1507
1511
|
if (!trackingDataId || typeof trackingDataId === "string" && trackingDataId.trim() === "") return;
|
|
@@ -1524,7 +1528,7 @@ var DwellTimeTracker = class {
|
|
|
1524
1528
|
}
|
|
1525
1529
|
}
|
|
1526
1530
|
/**
|
|
1527
|
-
*
|
|
1531
|
+
* Cleans up all listeners and timers.
|
|
1528
1532
|
*/
|
|
1529
1533
|
destroy() {
|
|
1530
1534
|
this.stop();
|
|
@@ -1584,7 +1588,7 @@ var DwellTimeTracker = class {
|
|
|
1584
1588
|
const isNetworkError = err.name === "AbortError" || err.name === "TimeoutError" || err.name === "TypeError" && err.message?.includes("Failed to fetch");
|
|
1585
1589
|
if (token) this.savePendingUpdate(elapsedTime);
|
|
1586
1590
|
if (this.onError && !isNetworkError) {
|
|
1587
|
-
this.onError(error instanceof Error ? error : new Error("
|
|
1591
|
+
this.onError(error instanceof Error ? error : new Error("Unknown error"));
|
|
1588
1592
|
}
|
|
1589
1593
|
} finally {
|
|
1590
1594
|
this.isSending = false;
|