From cbd43d6c07d6b1b669ce7c0999a4a2912974e8a0 Mon Sep 17 00:00:00 2001 From: Jer1605 Date: Thu, 6 Feb 2025 14:52:20 +0100 Subject: [PATCH 1/2] Add Flush Queue on JSSDK initialization --- src/index.tsx | 5 +++++ src/lib/data-collection/data-collection.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 9e89cd4..19efca1 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -4,6 +4,7 @@ import * as PropTypes from 'prop-types'; import * as React from 'react'; import { useEdgeeDataCollection } from './lib/data-collection/data-collection.hook'; import { Consent } from './lib/data-collection/data-collection.types'; +import { flushQueue } from './lib/data-collection/data-collection'; /** * Interface representing the Edgee analytics object. @@ -100,8 +101,12 @@ const EdgeeSdk = ({ src, dataInline }: EdgeeSdkProps): JSX.Element => { }; })((window as Window).history); + if (window.edgee) flushQueue(); + else window.addEventListener('edgee:loaded', flushQueue); + // Cleanup function to restore the original pushState and replaceState methods return (): void => { + window.removeEventListener('edgee:loaded', flushQueue); // No cleanup actions are defined here, but this is where you would restore the original methods if needed }; }, []); diff --git a/src/lib/data-collection/data-collection.ts b/src/lib/data-collection/data-collection.ts index abea96d..ed208a9 100644 --- a/src/lib/data-collection/data-collection.ts +++ b/src/lib/data-collection/data-collection.ts @@ -15,8 +15,8 @@ const eventQueue: (QueuedEvent | QueuedConsentEve /** * Flushes the event queue and sends all stored events to `window.edgee` if available. */ -const flushQueue = () => { - if (typeof window !== 'undefined' && window.edgee) { +export const flushQueue = () => { + if (typeof window !== 'undefined' && window.edgee && eventQueue.length > 0) { while (eventQueue.length > 0) { const event = eventQueue.shift(); if (!event) return; From 501c72365e028da2b7ae084e67208218ee384ba7 Mon Sep 17 00:00:00 2001 From: Jer1605 Date: Thu, 6 Feb 2025 15:07:09 +0100 Subject: [PATCH 2/2] Update Version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a6edbfc..8d2cbb6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-edgee", - "version": "1.2.0", + "version": "1.2.1", "description": "React component to use the Edgee SDK", "main": "dist/index.js", "types": "dist/index.d.ts",