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