core-outline 1.1.16 → 1.1.17

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.es.js CHANGED
@@ -6422,13 +6422,56 @@ var CoreOutline = function CoreOutline(_ref) {
6422
6422
  }));
6423
6423
  return _authorizeApp.apply(this, arguments);
6424
6424
  }
6425
+ var offLoadFunctionality = function offLoadFunctionality() {
6426
+ var data = JSON.stringify({
6427
+ data_source_id: data_source_id,
6428
+ sessionId: sessionId,
6429
+ formatted_events: JSON.stringify(events),
6430
+ raw_events: JSON.stringify(replayEvents)
6431
+ });
6432
+ socket.send({
6433
+ topic: "session-data",
6434
+ data_source_id: data_source_id,
6435
+ session_id: localStorage.getItem("coreOutlineSessionId"),
6436
+ start_date: new Date().toLocaleString(),
6437
+ latitude: location.latitude,
6438
+ longitude: location.longitude,
6439
+ browser: browser,
6440
+ event_id: "SESSION_END"
6441
+ });
6442
+ if (navigator.sendBeacon) {
6443
+ navigator.sendBeacon("http://localhost:5000/upload-events", data);
6444
+ } else {
6445
+ fetch("http://localhost:5000/upload-events", {
6446
+ method: 'POST',
6447
+ body: data,
6448
+ keepalive: true,
6449
+ headers: {
6450
+ 'Content-Type': 'application/json'
6451
+ }
6452
+ })["catch"](function (err) {
6453
+ return console.error('Upload failed:', err);
6454
+ });
6455
+ }
6456
+ };
6425
6457
  useEffect(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
6458
+ var handleBeforeUnload, handleVisibilityChange;
6426
6459
  return _regeneratorRuntime().wrap(function _callee$(_context) {
6427
6460
  while (1) switch (_context.prev = _context.next) {
6428
6461
  case 0:
6429
- _context.next = 2;
6462
+ handleBeforeUnload = function handleBeforeUnload() {
6463
+ offLoadFunctionality();
6464
+ };
6465
+ handleVisibilityChange = function handleVisibilityChange() {
6466
+ if (document.visibilityState === 'hidden') {
6467
+ offLoadFunctionality();
6468
+ }
6469
+ };
6470
+ window.addEventListener('beforeunload', handleBeforeUnload);
6471
+ document.addEventListener('visibilitychange', handleVisibilityChange);
6472
+ _context.next = 6;
6430
6473
  return authorizeApp(data_source_id, data_source_secret);
6431
- case 2:
6474
+ case 6:
6432
6475
  localStorage.setItem("coreOutlineSessionId", sessionId);
6433
6476
  localStorage.setItem("coreOutlineDataSourceIdId", data_source_id);
6434
6477
  console.log("Session", sessionId);
@@ -6443,6 +6486,9 @@ var CoreOutline = function CoreOutline(_ref) {
6443
6486
  event_id: "SESSION_START"
6444
6487
  });
6445
6488
  return _context.abrupt("return", function () {
6489
+ offLoadFunctionality();
6490
+ window.removeEventListener('beforeunload', handleBeforeUnload);
6491
+ document.removeEventListener('visibilitychange', handleVisibilityChange);
6446
6492
  socket.send({
6447
6493
  topic: "session-data",
6448
6494
  data_source_id: data_source_id,
@@ -6454,7 +6500,7 @@ var CoreOutline = function CoreOutline(_ref) {
6454
6500
  event_id: "SESSION_END"
6455
6501
  });
6456
6502
  });
6457
- case 7:
6503
+ case 11:
6458
6504
  case "end":
6459
6505
  return _context.stop();
6460
6506
  }
@@ -6501,7 +6547,6 @@ var CoreOutline = function CoreOutline(_ref) {
6501
6547
  page_name: window.location.href,
6502
6548
  event_id: "PAGE_NAVIGATION"
6503
6549
  });
6504
- saveEvents(events);
6505
6550
  };
6506
6551
  window.addEventListener("popstate", handleNavigation);
6507
6552
  var originalPushState = window.history.pushState;
@@ -6538,7 +6583,6 @@ var CoreOutline = function CoreOutline(_ref) {
6538
6583
  return function () {
6539
6584
  if (stopFn) {
6540
6585
  stopFn();
6541
- saveEvents(events);
6542
6586
  recorderActive.current = false;
6543
6587
  }
6544
6588
  };
@@ -6576,7 +6620,6 @@ var CoreOutline = function CoreOutline(_ref) {
6576
6620
  return function () {
6577
6621
  if (stopFn) {
6578
6622
  stopFn();
6579
- saveEvents(events);
6580
6623
  recorderActive.current = false;
6581
6624
  }
6582
6625
  };
@@ -6628,21 +6671,6 @@ var CoreOutline = function CoreOutline(_ref) {
6628
6671
  document.removeEventListener("click", handleClick);
6629
6672
  };
6630
6673
  }, []);
6631
- function saveEvents(events) {
6632
- var requestOptions = {
6633
- method: "PUT",
6634
- headers: {
6635
- "Content-Type": "application/json"
6636
- },
6637
- body: JSON.stringify(events)
6638
- };
6639
- fetch("http://localhost:5000/generate-s3-url/".concat(data_source_id, "/").concat(sessionId)).then(function (response) {
6640
- return response.json();
6641
- }).then(function (data) {
6642
- var uploadURL = data.signed_url;
6643
- return fetch(uploadURL, requestOptions);
6644
- });
6645
- }
6646
6674
  function saveEventsLocally() {
6647
6675
  var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "formatted" ;
6648
6676
  var blob = "";
package/dist/index.js CHANGED
@@ -6430,13 +6430,56 @@ var CoreOutline = function CoreOutline(_ref) {
6430
6430
  }));
6431
6431
  return _authorizeApp.apply(this, arguments);
6432
6432
  }
6433
+ var offLoadFunctionality = function offLoadFunctionality() {
6434
+ var data = JSON.stringify({
6435
+ data_source_id: data_source_id,
6436
+ sessionId: sessionId,
6437
+ formatted_events: JSON.stringify(events),
6438
+ raw_events: JSON.stringify(replayEvents)
6439
+ });
6440
+ socket.send({
6441
+ topic: "session-data",
6442
+ data_source_id: data_source_id,
6443
+ session_id: localStorage.getItem("coreOutlineSessionId"),
6444
+ start_date: new Date().toLocaleString(),
6445
+ latitude: location.latitude,
6446
+ longitude: location.longitude,
6447
+ browser: browser,
6448
+ event_id: "SESSION_END"
6449
+ });
6450
+ if (navigator.sendBeacon) {
6451
+ navigator.sendBeacon("http://localhost:5000/upload-events", data);
6452
+ } else {
6453
+ fetch("http://localhost:5000/upload-events", {
6454
+ method: 'POST',
6455
+ body: data,
6456
+ keepalive: true,
6457
+ headers: {
6458
+ 'Content-Type': 'application/json'
6459
+ }
6460
+ })["catch"](function (err) {
6461
+ return console.error('Upload failed:', err);
6462
+ });
6463
+ }
6464
+ };
6433
6465
  React.useEffect(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
6466
+ var handleBeforeUnload, handleVisibilityChange;
6434
6467
  return _regeneratorRuntime().wrap(function _callee$(_context) {
6435
6468
  while (1) switch (_context.prev = _context.next) {
6436
6469
  case 0:
6437
- _context.next = 2;
6470
+ handleBeforeUnload = function handleBeforeUnload() {
6471
+ offLoadFunctionality();
6472
+ };
6473
+ handleVisibilityChange = function handleVisibilityChange() {
6474
+ if (document.visibilityState === 'hidden') {
6475
+ offLoadFunctionality();
6476
+ }
6477
+ };
6478
+ window.addEventListener('beforeunload', handleBeforeUnload);
6479
+ document.addEventListener('visibilitychange', handleVisibilityChange);
6480
+ _context.next = 6;
6438
6481
  return authorizeApp(data_source_id, data_source_secret);
6439
- case 2:
6482
+ case 6:
6440
6483
  localStorage.setItem("coreOutlineSessionId", sessionId);
6441
6484
  localStorage.setItem("coreOutlineDataSourceIdId", data_source_id);
6442
6485
  console.log("Session", sessionId);
@@ -6451,6 +6494,9 @@ var CoreOutline = function CoreOutline(_ref) {
6451
6494
  event_id: "SESSION_START"
6452
6495
  });
6453
6496
  return _context.abrupt("return", function () {
6497
+ offLoadFunctionality();
6498
+ window.removeEventListener('beforeunload', handleBeforeUnload);
6499
+ document.removeEventListener('visibilitychange', handleVisibilityChange);
6454
6500
  socket.send({
6455
6501
  topic: "session-data",
6456
6502
  data_source_id: data_source_id,
@@ -6462,7 +6508,7 @@ var CoreOutline = function CoreOutline(_ref) {
6462
6508
  event_id: "SESSION_END"
6463
6509
  });
6464
6510
  });
6465
- case 7:
6511
+ case 11:
6466
6512
  case "end":
6467
6513
  return _context.stop();
6468
6514
  }
@@ -6509,7 +6555,6 @@ var CoreOutline = function CoreOutline(_ref) {
6509
6555
  page_name: window.location.href,
6510
6556
  event_id: "PAGE_NAVIGATION"
6511
6557
  });
6512
- saveEvents(events);
6513
6558
  };
6514
6559
  window.addEventListener("popstate", handleNavigation);
6515
6560
  var originalPushState = window.history.pushState;
@@ -6546,7 +6591,6 @@ var CoreOutline = function CoreOutline(_ref) {
6546
6591
  return function () {
6547
6592
  if (stopFn) {
6548
6593
  stopFn();
6549
- saveEvents(events);
6550
6594
  recorderActive.current = false;
6551
6595
  }
6552
6596
  };
@@ -6584,7 +6628,6 @@ var CoreOutline = function CoreOutline(_ref) {
6584
6628
  return function () {
6585
6629
  if (stopFn) {
6586
6630
  stopFn();
6587
- saveEvents(events);
6588
6631
  recorderActive.current = false;
6589
6632
  }
6590
6633
  };
@@ -6636,21 +6679,6 @@ var CoreOutline = function CoreOutline(_ref) {
6636
6679
  document.removeEventListener("click", handleClick);
6637
6680
  };
6638
6681
  }, []);
6639
- function saveEvents(events) {
6640
- var requestOptions = {
6641
- method: "PUT",
6642
- headers: {
6643
- "Content-Type": "application/json"
6644
- },
6645
- body: JSON.stringify(events)
6646
- };
6647
- fetch("http://localhost:5000/generate-s3-url/".concat(data_source_id, "/").concat(sessionId)).then(function (response) {
6648
- return response.json();
6649
- }).then(function (data) {
6650
- var uploadURL = data.signed_url;
6651
- return fetch(uploadURL, requestOptions);
6652
- });
6653
- }
6654
6682
  function saveEventsLocally() {
6655
6683
  var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "formatted" ;
6656
6684
  var blob = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-outline",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
4
4
  "description": "A React component for Core&Outline",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",