!function(){"use strict";var e=!1,t=null;function n(e){e=e||{},this.apiKey=e.apiKey||null,this.gtmEventKey=e.gtmEventKey||"ipmeta_loaded",this.measurementId=e.measurementId||null,this.isLocal=e.local||!1,this.isDebug=e.debug||!1,this.onReady=e.onReady||null,window.IpMeta=this}function o(e,t,n,o){var a=(e||"free")+"_ipmetaNetworkResponse";try{var i=sessionStorage.getItem(a);if(null!==i)return n&&console&&console.log&&console.log("IpMeta: Using cached response"),void o(JSON.parse(i),!1)}catch(e){}var r=new XMLHttpRequest,s="h="+encodeURIComponent(window.location.hostname);e&&(s+="&k="+encodeURIComponent(e));var d=t?window.location.origin+"/api/enrich":"https://ipmeta.io/api/enrich";r.open("POST",d,!0),r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),r.setRequestHeader("Accept","application/json"),r.onreadystatechange=function(){if(r.readyState===XMLHttpRequest.DONE)if(200!==r.status)if(429!==r.status)console.error("IpMeta: API request failed with status "+r.status);else try{var e=JSON.parse(r.responseText);console.error("IpMeta: Rate limit exceeded -",e.message||e[0])}catch(e){console.error("IpMeta: Rate limit exceeded")}else{var t;try{t=JSON.parse(r.responseText)}catch(e){return void console.error("IpMeta: Failed to parse response")}try{sessionStorage.setItem(a,r.responseText)}catch(e){}o(t,!0)}},r.send(s)}window.IpMetaGa4=function(t){if(e)return console.warn("IpMeta: Already initialized"),window.IpMeta;e=!0;var o=new n(t);return o.loadGa4(),o},window.IpMetaGtag=function(t){if(e)return console.warn("IpMeta: Already initialized"),window.IpMeta;e=!0;var o=0,a=t&&t.timeout||10,i=setInterval(function(){++o;var e=window.gtag;if(void 0!==e||o>=a)if(clearInterval(i),void 0!==e){var r=new n(t);r.tracker=e,r.loadGtagDirect()}else console.warn("IpMeta: gtag not found. Make sure gtag.js is loaded before IpMeta.")},300)},window.IpMetaInit=function(n){if(n=n||t||{},e&&window.ipmeta){if("function"==typeof window.gtag){var o={ipmeta_company:window.ipmeta.name,ipmeta_domain:window.ipmeta.domain,ipmeta_type:window.ipmeta.type};n.measurementId?window.gtag("config",n.measurementId,{user_properties:o,send_page_view:!1}):window.gtag("set","user_properties",o),console.log("IpMeta: Re-sent user properties after consent")}return window.IpMeta}return e=!1,"function"==typeof window.gtag?window.IpMetaGtag(n):window.dataLayer?window.IpMetaGa4(n):void console.warn("IpMeta: No GA4 detected. Call IpMetaGtag() or IpMetaGa4() directly.")},n.prototype.loadGa4=function(){var e=this;this.debugMessage("IpMeta: Loading GA4 network fields via dataLayer"),o(this.apiKey,this.isLocal,this.isDebug,function(t,n){var o={name:t.name||"(not set)",domain:t.domain||"(not set)",type:t.type||"(not set)"};window.ipmeta=o,window.dataLayer=window.dataLayer||[],window.dataLayer.push({ipmeta:o}),window.dataLayer.push({event:e.gtmEventKey}),e.debugMessage("IpMeta: Data pushed to dataLayer",o),"function"==typeof e.onReady&&e.onReady(o)})},n.prototype.loadGtagDirect=function(){var e=this;this.debugMessage("IpMeta: Loading GA4 network fields via gtag.js"),o(this.apiKey,this.isLocal,this.isDebug,function(t,n){var o={name:t.name||"(not set)",domain:t.domain||"(not set)",type:t.type||"(not set)"};if(window.ipmeta=o,"function"==typeof e.tracker){var a={ipmeta_company:o.name,ipmeta_domain:o.domain,ipmeta_type:o.type};e.measurementId?(e.tracker("config",e.measurementId,{user_properties:a,send_page_view:!1}),e.debugMessage("IpMeta: User properties set for "+e.measurementId,o)):(e.tracker("set","user_properties",a),e.debugMessage("IpMeta: User properties set globally",o))}"function"==typeof e.onReady&&e.onReady(o)})},n.prototype.getData=function(){return window.ipmeta||null},n.prototype.loadGtmGa4=function(){return this.loadGa4()},n.prototype.loadNetworkFields=function(){return this.debugMessage("IpMeta: loadNetworkFields() is deprecated (UA sunset). Use loadGa4() for GA4."),this.loadGa4()},n.prototype.loadGtagNetworkFields=function(){return this.loadGtagDirect()},n.prototype.loadGtmNetworkFields=function(){return this.loadGa4()},n.prototype.setDebug=function(e){this.isDebug=e},n.prototype.debugMessage=function(e,t){this.isDebug&&console&&console.log&&(void 0!==t?console.log(e,t):console.log(e))};var a={},i=["password","passwd","secret","token","auth","credit","card","cvv","ccn","ssn","pin"],r=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,s="ipmeta_fp_";function d(e){try{var t=sessionStorage.getItem(s+e);if(!t)return null;var n=JSON.parse(t);return Date.now()-n.ts>864e5?(sessionStorage.removeItem(s+e),null):n}catch(e){return null}}function c(e,t,n){try{sessionStorage.setItem(s+e,JSON.stringify({h:t,ts:Date.now(),ms:n}))}catch(e){}}function p(e,t){t=t||3e3,"undefined"!=typeof window&&window.requestIdleCallback?window.requestIdleCallback(e,{timeout:t}):"undefined"!=typeof window?setTimeout(e,Math.min(1e3,t)):e()}function u(e,t){if(window.crypto&&window.crypto.subtle){var n=(new TextEncoder).encode(e);window.crypto.subtle.digest("SHA-256",n).then(function(e){t(function(e){for(var t=new Uint8Array(e),n="",o=0;o=s&&(clearInterval(p),"function"==typeof window.gtag?(c&&console.log("IpMeta: Late detection - gtag.js"),window.IpMetaGtag(n)):window.dataLayer?(c&&console.log("IpMeta: Fallback to dataLayer"),window.IpMetaGa4(n)):c&&console.log("IpMeta: No GA4 detected after "+200*s/1e3+"s. Use IpMetaInit() after GA4 loads.")))},200)}}function M(e){var t=e&&e.debug;t&&console.log("IpMeta: Waiting for consent...");var n=window.dataLayer&&window.dataLayer.push;window.dataLayer&&n&&(window.dataLayer.push=function(){for(var o=n.apply(this,arguments),a=0;a