"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),t=require("react"),s=require("react-ga4"),p=require("react-router"),C=require("../conf/index.js"),g=require("@devgateway/wp-react-lib"),A=require("./internalTrafficUtils.js"),u=new Set,_=(f,T={})=>l=>{var o;const i=t.useContext(g.SettingsContext)??{},e=((o=i==null?void 0:i.data)==null?void 0:o.google_analytics_code)??C.Config.GA_CODE,r=p.useLocation(),n=t.useRef(!1);return t.useEffect(()=>{e&&e!=="#REACT_APP_GA_CODE#"&&!n.current&&(u.has(e)||(s.initialize(e),u.add(e),console.log("GA initialized with code:",e)),n.current=!0)},[e]),t.useEffect(()=>{if(e&&e!=="#REACT_APP_GA_CODE#"&&n.current){const c=r.pathname,a=A.isInternalTrafficEnabled()?"internal":"external";s.send({hitType:"pageview",page:c,traffic_type:a}),console.log("GA pageview sent:",{page:c,traffic_type:a})}},[r.pathname,e]),d.jsx(f,{...l})};exports.withTracker=_;
