@weaverse/hydrogen 5.15.1 → 5.15.2
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.js +34 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -568,6 +568,32 @@ function syncReusedInstance(weaverse, params) {
|
|
|
568
568
|
weaverse.triggerUpdate();
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
|
+
|
|
572
|
+
// src/utils/pixel.ts
|
|
573
|
+
var currentNavigationKey = null;
|
|
574
|
+
var firedPageIds = /* @__PURE__ */ new Set();
|
|
575
|
+
var mountedInstances = 0;
|
|
576
|
+
function shouldFirePixel(navigationKey, pageId) {
|
|
577
|
+
if (navigationKey !== currentNavigationKey) {
|
|
578
|
+
currentNavigationKey = navigationKey;
|
|
579
|
+
firedPageIds.clear();
|
|
580
|
+
}
|
|
581
|
+
if (firedPageIds.has(pageId)) {
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
firedPageIds.add(pageId);
|
|
585
|
+
return true;
|
|
586
|
+
}
|
|
587
|
+
function registerPixelInstance() {
|
|
588
|
+
mountedInstances += 1;
|
|
589
|
+
return () => {
|
|
590
|
+
mountedInstances -= 1;
|
|
591
|
+
if (mountedInstances === 0) {
|
|
592
|
+
currentNavigationKey = null;
|
|
593
|
+
firedPageIds.clear();
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
}
|
|
571
597
|
var ThemeSettingsStore = class {
|
|
572
598
|
settings = {};
|
|
573
599
|
schema;
|
|
@@ -727,13 +753,18 @@ function useStudio(weaverse) {
|
|
|
727
753
|
}
|
|
728
754
|
function usePixel(context) {
|
|
729
755
|
let { projectId, pageId, isDesignMode, weaverseHost } = context;
|
|
756
|
+
let { key: navigationKey } = useLocation();
|
|
730
757
|
useEffect(() => {
|
|
731
758
|
if (!(projectId && pageId) || isDesignMode) {
|
|
732
759
|
return;
|
|
733
760
|
}
|
|
734
|
-
let
|
|
735
|
-
|
|
736
|
-
|
|
761
|
+
let unregister = registerPixelInstance();
|
|
762
|
+
if (shouldFirePixel(navigationKey, pageId)) {
|
|
763
|
+
let img = new Image();
|
|
764
|
+
img.onload = () => img.remove();
|
|
765
|
+
img.src = `${weaverseHost}/api/public/px?projectId=${projectId}&pageId=${pageId}`;
|
|
766
|
+
}
|
|
767
|
+
return unregister;
|
|
737
768
|
}, []);
|
|
738
769
|
}
|
|
739
770
|
var WeaverseHydrogenItem = class extends WeaverseItemStore {
|