PageSourceSearch

https://guidasphere.com/assets/module.ad-tracker.js

js guidasphere.com collected 2026-09-24 14:44:51 UTC 2,083 bytes, 66 lines download raw bytes

1import { n as reactFactory, o as toModule } from "/assets/module.jsx-runtime-alias.js";
2var React = toModule(reactFactory(), 1);
3var useEffect = React.useEffect;
4var useRef = React.useRef;
5
6const TRACKED_CAMPAIGNS = new Set();
7let pendingImpressions = new Set();
8let flushInterval = null;
9
10function flushImpressions() {
11  if (pendingImpressions.size === 0) return;
12  const campaignIds = Array.from(pendingImpressions);
13  pendingImpressions.clear();
14  
15  if (window.GUIDASPHERE_CATALOG_API?.trackAdImpressions) {
16    window.GUIDASPHERE_CATALOG_API.trackAdImpressions(campaignIds).catch(() => {});
17  }
18}
19
20export function useAdTracker(products) {
21  const observerRef = useRef(null);
22
23  useEffect(() => {
24    observerRef.current = new IntersectionObserver((entries) => {
25      let hasNew = false;
26      entries.forEach((entry) => {
27        if (entry.isIntersecting) {
28          const campaignId = entry.target.getAttribute('data-campaign-id');
29          if (campaignId && !TRACKED_CAMPAIGNS.has(campaignId)) {
30            TRACKED_CAMPAIGNS.add(campaignId);
31            pendingImpressions.add(Number(campaignId));
32            hasNew = true;
33          }
34        }
35      });
36      
37      if (hasNew && !flushInterval) {
38        flushInterval = setInterval(flushImpressions, 3000);
39      }
40    }, { threshold: 0.5 });
41    
42    return () => {
43      if (observerRef.current) observerRef.current.disconnect();
44      if (flushInterval) {
45        clearInterval(flushInterval);
46        flushInterval = null;
47      }
48      flushImpressions(); // Flush on unmount
49    };
50  }, []);
51
52  const registerAdRef = (campaignId) => (node) => {
53    if (node && campaignId && observerRef.current && !TRACKED_CAMPAIGNS.has(String(campaignId))) {
54      node.setAttribute('data-campaign-id', String(campaignId));
55      observerRef.current.observe(node);
56    }
57  };
58
59  const handleAdClick = (campaignId) => {
60    if (campaignId && window.GUIDASPHERE_CATALOG_API?.trackAdClick) {
61      window.GUIDASPHERE_CATALOG_API.trackAdClick(campaignId).catch(() => {});
62    }
63  };
64
65  return { registerAdRef, handleAdClick };
66}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.