@d8a-tech/ga4-duplicator 0.1.0 → 0.22.4
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/gd.js +1 -1
- package/dist/gd.min.js +1 -1
- package/package.json +1 -1
package/dist/gd.js
CHANGED
package/dist/gd.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* ga4-duplicator - built 2026-01-21T13:
|
|
1
|
+
/* ga4-duplicator - built 2026-01-21T13:34:53.666Z */
|
|
2
2
|
"use strict";(()=>{window.createGA4Duplicator=function(g){class b{install(e){let r=window.fetch;window.fetch=function(n,i){let c=typeof n=="string"?n:n instanceof URL?n.toString():n.url,o=i&&i.method||n.method||"GET";if(e.isTargetUrl(c)){let s=(o||"GET").toUpperCase(),a=Promise.resolve(void 0);if(s==="POST"){if(i&&Object.prototype.hasOwnProperty.call(i,"body"))a=Promise.resolve(i.body);else if(typeof Request!="undefined"&&n instanceof Request)try{a=n.clone().blob().catch(()=>{})}catch(l){a=Promise.resolve(void 0)}}let u=r.apply(this,arguments),h=e.buildDuplicateUrl(c);return s==="GET"?r(h,{method:"GET",keepalive:!0}).catch(l=>{e.debug&&console.error("gtm interceptor: error duplicating GET fetch:",l)}):s==="POST"&&a.then(l=>{r(h,{method:"POST",body:l,keepalive:!0}).catch(f=>{e.debug&&console.error("gtm interceptor: error duplicating POST fetch:",f)})}),u}return r.apply(this,arguments)}}}class S{install(e){let r=XMLHttpRequest.prototype.open,n=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(i,c){return this._requestMethod=i,this._requestUrl=c,r.apply(this,arguments)},XMLHttpRequest.prototype.send=function(i){if(this._requestUrl&&e.isTargetUrl(this._requestUrl)){let c=n.apply(this,arguments);try{let o=(this._requestMethod||"GET").toUpperCase(),s=e.buildDuplicateUrl(this._requestUrl);o==="GET"?fetch(s,{method:"GET",keepalive:!0}).catch(a=>{e.debug&&console.error("gtm interceptor: error duplicating GET xhr:",a)}):o==="POST"&&fetch(s,{method:"POST",body:i,keepalive:!0}).catch(a=>{e.debug&&console.error("gtm interceptor: error duplicating POST xhr:",a)})}catch(o){e.debug&&console.error("gtm interceptor: xhr duplication failed:",o)}return c}return n.apply(this,arguments)}}}class U{install(e){if(!navigator.sendBeacon)return;let r=navigator.sendBeacon;navigator.sendBeacon=function(n,i){if(e.isTargetUrl(n)){let c=r.apply(this,arguments);try{r.call(navigator,e.buildDuplicateUrl(n),i)}catch(o){e.debug&&console.error("gtm interceptor: error duplicating sendBeacon:",o)}return c}return r.apply(this,arguments)}}}class L{install(e){try{let r=Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype,"src"),n=r&&r.set,i=r&&r.get,c=HTMLScriptElement.prototype.setAttribute,o=s=>{try{if(!e.isTargetUrl(s))return;fetch(e.buildDuplicateUrl(s),{method:"GET",keepalive:!0}).catch(a=>{e.debug&&console.error("gtm interceptor: error duplicating script GET:",a)})}catch(a){}};if(n&&i){let s=n,a=i;Object.defineProperty(HTMLScriptElement.prototype,"src",{configurable:!0,enumerable:!0,get:function(){return a.call(this)},set:function(u){try{let h=this.__ga4LastSrcDuplicated;u&&u!==h&&(o(String(u)),this.__ga4LastSrcDuplicated=String(u));let l=this,f=function(){try{let p=l.src;p&&p!==l.__ga4LastSrcDuplicated&&(o(p),l.__ga4LastSrcDuplicated=p)}catch(p){}l.removeEventListener("load",f)};this.addEventListener("load",f)}catch(h){}s.call(this,u)}})}HTMLScriptElement.prototype.setAttribute=function(s,a){try{if(String(s).toLowerCase()==="src"){let u=String(a),h=this.__ga4LastSrcDuplicated;u&&u!==h&&(o(u),this.__ga4LastSrcDuplicated=u);let l=this,f=function(){try{let p=l.src;p&&p!==l.__ga4LastSrcDuplicated&&(o(p),l.__ga4LastSrcDuplicated=p)}catch(p){}l.removeEventListener("load",f)};this.addEventListener("load",f)}}catch(u){}return c.apply(this,arguments)}}catch(r){}}}if(window.__ga4DuplicatorInitialized){g.debug&&console.warn("GA4 Duplicator: already initialized.");return}let d=[];if(g.destinations&&Array.isArray(g.destinations))for(let t=0;t<g.destinations.length;t++)d.push(g.destinations[t]);if(g.server_container_url&&d.push({measurement_id:"*",server_container_url:g.server_container_url}),d.length===0){console.error("GA4 Duplicator: either server_container_url or destinations array is required");return}function y(t){return t=String(t||""),t=t.replace(/\/+$/,""),t===""?"/":t}function D(t,e){if(!t||t==="*")return!0;try{let r=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp("^"+r+"$","i").test(e)}catch(r){return t.toLowerCase()===e.toLowerCase()}}function w(t){try{let e=new URL(t,location.href);return e.searchParams.get("tid")||e.searchParams.get("id")||""}catch(e){let r=t.match(/[?&](?:tid|id)=([^&?#]+)/);return r?decodeURIComponent(r[1]):""}}function T(t){for(let e=0;e<d.length;e++)if(D(d[e].measurement_id,t))return d[e];return null}function m(t){let e=String(t.server_container_url||"").trim(),r=new URL(e,location.href);return r.search="",r.hash="",r}function I(t){if(!t||typeof t!="string")return!1;try{let e=new URL(t,location.href);for(let s=0;s<d.length;s++){let a=m(d[s]);if(e.origin===a.origin&&y(e.pathname)===y(a.pathname))return!1}let r=e.searchParams,n=r.has("gtm"),i=r.has("tag_exp"),c=r.get("tid")||r.get("id")||"",o=/^G-[A-Z0-9]+$/i.test(c);return n&&i&&o}catch(e){if(typeof t=="string"){for(let c=0;c<d.length;c++)try{let o=m(d[c]),s=o.origin+o.pathname;if(t.indexOf(s)!==-1)return!1}catch(o){}let r=t.indexOf("gtm=")!==-1,n=t.indexOf("tag_exp=")!==-1,i=t.match(/[?&](?:tid|id)=G-[A-Za-z0-9]+/);return!!(r&&n&&i)}return!1}}function G(t){let e=w(t),r=T(e);if(!r)return"";let n=m(r);try{let i=new URL(t,location.href);n.search=i.search}catch(i){}return n.toString()}let R={debug:!!g.debug,isTargetUrl:I,buildDuplicateUrl:G},_=[new b,new S,new U,new L];for(let t=0;t<_.length;t++)try{_[t].install(R)}catch(e){g.debug&&console.error("GA4 Duplicator: failed to install interceptor",e)}window.__ga4DuplicatorInitialized=!0};})();
|
|
3
3
|
//# sourceMappingURL=gd.min.js.map
|
package/package.json
CHANGED