@dev-2-dev/websdk-plugin-session-tracker 0.9.0 → 0.9.1
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/browser.js +15 -4893
- package/dist/browser.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +46 -23
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +45 -23
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -4437,7 +4437,7 @@ const pack = (event) => {
|
|
|
4437
4437
|
class D2DWebSessionTracker {
|
|
4438
4438
|
constructor(config) {
|
|
4439
4439
|
this.name = 'session-tracker';
|
|
4440
|
-
this.version = '"0.9.
|
|
4440
|
+
this.version = '"0.9.1"';
|
|
4441
4441
|
this.context = null;
|
|
4442
4442
|
this.config = {};
|
|
4443
4443
|
this.userConfig = null;
|
|
@@ -4624,19 +4624,40 @@ class D2DWebSessionTracker {
|
|
|
4624
4624
|
}
|
|
4625
4625
|
// MARK: On Focus
|
|
4626
4626
|
onFocus() {
|
|
4627
|
-
if (!this.
|
|
4627
|
+
if (!this.context)
|
|
4628
4628
|
return;
|
|
4629
|
-
|
|
4629
|
+
// Check if recording was active before blur
|
|
4630
|
+
const isRecordingActive = this.context.getPluginField('isRecordingActive');
|
|
4631
|
+
// If session tracker was paused (e.g., by onBlur), resume it
|
|
4632
|
+
if (!this.isActive) {
|
|
4633
|
+
this.isActive = true;
|
|
4634
|
+
// Resume recording if it was active before blur
|
|
4635
|
+
if (this.config.enableSessionRecording &&
|
|
4636
|
+
isRecordingActive &&
|
|
4637
|
+
!this.stopRecording) {
|
|
4638
|
+
this.startSessionRecording();
|
|
4639
|
+
}
|
|
4640
|
+
return;
|
|
4641
|
+
}
|
|
4642
|
+
// If already active but recording was stopped, restart it
|
|
4643
|
+
if (this.config.enableSessionRecording &&
|
|
4644
|
+
isRecordingActive &&
|
|
4645
|
+
!this.stopRecording) {
|
|
4646
|
+
this.startSessionRecording();
|
|
4647
|
+
}
|
|
4630
4648
|
}
|
|
4631
4649
|
// MARK: On Blur
|
|
4632
4650
|
onBlur() {
|
|
4633
4651
|
if (!this.isActive)
|
|
4634
4652
|
return;
|
|
4635
4653
|
console.log('onBlur');
|
|
4636
|
-
this.
|
|
4637
|
-
|
|
4654
|
+
if (this.config.enableSessionRecording && this.stopRecording) {
|
|
4655
|
+
this.stopRecording();
|
|
4656
|
+
this.stopRecording = null;
|
|
4657
|
+
}
|
|
4658
|
+
this.isActive = false;
|
|
4638
4659
|
this.sendFinalBatch().catch(err => {
|
|
4639
|
-
this.context?.logger.error(
|
|
4660
|
+
this.context?.logger.error(err);
|
|
4640
4661
|
});
|
|
4641
4662
|
}
|
|
4642
4663
|
// MARK: On Before Unload
|
|
@@ -4645,9 +4666,8 @@ class D2DWebSessionTracker {
|
|
|
4645
4666
|
return;
|
|
4646
4667
|
console.log('onBeforeUnload');
|
|
4647
4668
|
this.stop();
|
|
4648
|
-
// Send final batch via addWithFile
|
|
4649
4669
|
this.sendFinalBatch().catch(err => {
|
|
4650
|
-
this.context?.logger.error(
|
|
4670
|
+
this.context?.logger.error(err);
|
|
4651
4671
|
});
|
|
4652
4672
|
}
|
|
4653
4673
|
// MARK: On Tracking Change
|
|
@@ -4837,23 +4857,27 @@ class D2DWebSessionTracker {
|
|
|
4837
4857
|
// Events are already compressed by packFn if compressionEnabled is true
|
|
4838
4858
|
const fileContent = JSON.stringify(eventsToSend);
|
|
4839
4859
|
const blob = new Blob([fileContent], { type: 'application/json' });
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
credentials: 'omit', // Prevents CORS issues with wildcard Access-Control-Allow-Origin
|
|
4848
|
-
});
|
|
4860
|
+
fetch(this.delayedS3Url, {
|
|
4861
|
+
method: 'PUT',
|
|
4862
|
+
body: blob,
|
|
4863
|
+
keepalive: true, // Ensures request continues even if page unloads
|
|
4864
|
+
credentials: 'omit', // Prevents CORS issues with wildcard Access-Control-Allow-Origin
|
|
4865
|
+
})
|
|
4866
|
+
.then(response => {
|
|
4849
4867
|
if (!response.ok) {
|
|
4850
4868
|
throw new Error(`S3 upload failed: ${response.statusText}`);
|
|
4851
4869
|
}
|
|
4852
4870
|
this.lastBatchTime = Date.now();
|
|
4853
|
-
}
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4871
|
+
})
|
|
4872
|
+
.catch(error => {
|
|
4873
|
+
// Silently handle errors during page unload/navigation
|
|
4874
|
+
// These are expected when the page is navigating away
|
|
4875
|
+
if (error.name !== 'TypeError' ||
|
|
4876
|
+
!error.message.includes('Failed to fetch')) {
|
|
4877
|
+
// Only log non-navigation errors
|
|
4878
|
+
this.context?.logger.error(`Failed to send final batch: ${error}`);
|
|
4879
|
+
}
|
|
4880
|
+
});
|
|
4857
4881
|
}
|
|
4858
4882
|
// MARK: Upload To S3
|
|
4859
4883
|
async uploadToS3(url, data) {
|
|
@@ -4886,6 +4910,4 @@ class D2DWebSessionTracker {
|
|
|
4886
4910
|
}
|
|
4887
4911
|
}
|
|
4888
4912
|
|
|
4889
|
-
exports.D2DWebSessionTracker = D2DWebSessionTracker;
|
|
4890
4913
|
exports.default = D2DWebSessionTracker;
|
|
4891
|
-
//# sourceMappingURL=index.js.map
|