@d8a-tech/gd 0.38.0 → 0.39.0
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 +2 -2
- package/dist/gd.min.js +2 -2
- package/package.json +1 -1
package/dist/gd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/* ga4-duplicator - built 2026-02-
|
|
1
|
+
/* ga4-duplicator - built 2026-02-27T14:15:53.972Z */
|
|
2
2
|
"use strict";
|
|
3
3
|
(() => {
|
|
4
4
|
// src/version.ts
|
|
5
|
-
var version = "v0.
|
|
5
|
+
var version = "v0.39.0" ? "v0.39.0" : devVersionUtc();
|
|
6
6
|
|
|
7
7
|
// src/ga4-duplicator.ts
|
|
8
8
|
window.createGA4Duplicator = function(options) {
|
package/dist/gd.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* ga4-duplicator - built 2026-02-
|
|
2
|
-
"use strict";(()=>{var w="v0.
|
|
1
|
+
/* ga4-duplicator - built 2026-02-27T14:15:53.972Z */
|
|
2
|
+
"use strict";(()=>{var w="v0.39.0";window.createGA4Duplicator=function(h){class L{install(t){let e=window.fetch;window.fetch=function(i,n){let o=typeof i=="string"?i:i instanceof URL?i.toString():i.url,g=n&&n.method||i.method||"GET";if(t.isTargetUrl(o)){let l=(g||"GET").toUpperCase(),d=Promise.resolve(void 0);if(l==="POST"){if(n&&Object.prototype.hasOwnProperty.call(n,"body"))d=Promise.resolve(n.body);else if(typeof Request!="undefined"&&i instanceof Request)try{d=i.clone().blob().catch(()=>{})}catch(c){d=Promise.resolve(void 0)}}let s=e.apply(this,arguments),p=t.buildDuplicateUrl(o),u=t.getConvertToGet(o);return l==="GET"?e(p,{method:"GET",keepalive:!0,credentials:"include"}).catch(c=>{t.debug&&console.error("gtm interceptor: error duplicating GET fetch:",c)}):l==="POST"&&d.then(c=>{if(u){let a="";if(typeof c=="string")a=c;else if(c instanceof Blob){e(p,{method:"POST",body:c,keepalive:!0,credentials:"include"}).catch(_=>{t.debug&&console.error("gtm interceptor: error duplicating POST fetch (convert_to_get with Blob):",_)});return}let m=a.split(`
|
|
3
3
|
`),y=!1;for(let _=0;_<m.length;_++){let E=m[_].trim();if(E){let M=t.buildDuplicateUrl(o),H=b(M,E);e(H,{method:"GET",keepalive:!0,credentials:"include"}).catch(N=>{t.debug&&console.error("gtm interceptor: error duplicating GET fetch (from convert_to_get):",N)}),y=!0}}y||e(p,{method:"GET",keepalive:!0,credentials:"include"}).catch(_=>{t.debug&&console.error("gtm interceptor: error duplicating GET fetch (empty body convert_to_get):",_)})}else e(p,{method:"POST",body:c,keepalive:!0,credentials:"include"}).catch(a=>{t.debug&&console.error("gtm interceptor: error duplicating POST fetch:",a)})}),s}return e.apply(this,arguments)}}}class I{install(t){let e=XMLHttpRequest.prototype.open,i=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(n,o){return this._requestMethod=n,this._requestUrl=o,e.apply(this,arguments)},XMLHttpRequest.prototype.send=function(n){if(this._requestUrl&&t.isTargetUrl(this._requestUrl)){let o=i.apply(this,arguments);try{let g=(this._requestMethod||"GET").toUpperCase(),l=t.buildDuplicateUrl(this._requestUrl),d=t.getConvertToGet(this._requestUrl);if(g==="GET")fetch(l,{method:"GET",keepalive:!0,credentials:"include"}).catch(s=>{t.debug&&console.error("gtm interceptor: error duplicating GET xhr:",s)});else if(g==="POST")if(d){let s="";if(typeof n=="string")s=n;else if(n&&typeof n=="object")try{s=String(n)}catch(c){s=""}let p=s.split(`
|
|
4
4
|
`),u=!1;for(let c=0;c<p.length;c++){let a=p[c].trim();if(a){let m=t.buildDuplicateUrl(this._requestUrl),y=b(m,a);fetch(y,{method:"GET",keepalive:!0,credentials:"include"}).catch(_=>{t.debug&&console.error("gtm interceptor: error duplicating GET xhr (from convert_to_get):",_)}),u=!0}}u||fetch(l,{method:"GET",keepalive:!0,credentials:"include"}).catch(c=>{t.debug&&console.error("gtm interceptor: error duplicating GET xhr (empty body convert_to_get):",c)})}else fetch(l,{method:"POST",body:n,keepalive:!0,credentials:"include"}).catch(s=>{t.debug&&console.error("gtm interceptor: error duplicating POST xhr:",s)})}catch(g){t.debug&&console.error("gtm interceptor: xhr duplication failed:",g)}return o}return i.apply(this,arguments)}}}class R{install(t){if(!navigator.sendBeacon)return;let e=navigator.sendBeacon;navigator.sendBeacon=function(i,n){if(t.isTargetUrl(i)){let o=e.apply(this,arguments);try{let g=t.buildDuplicateUrl(i);if(t.getConvertToGet(i)){let d="";if(typeof n=="string")d=n;else if(n&&typeof n=="object")try{d=String(n)}catch(u){d=""}let s=d.split(`
|
|
5
5
|
`),p=!1;for(let u=0;u<s.length;u++){let c=s[u].trim();if(c){let a=t.buildDuplicateUrl(i),m=b(a,c);fetch(m,{method:"GET",keepalive:!0,credentials:"include"}).catch(y=>{t.debug&&console.error("gtm interceptor: error duplicating GET beacon (from convert_to_get):",y)}),p=!0}}p||fetch(g,{method:"GET",keepalive:!0,credentials:"include"}).catch(u=>{t.debug&&console.error("gtm interceptor: error duplicating GET beacon (empty body convert_to_get):",u)})}else e.call(navigator,g,n)}catch(g){t.debug&&console.error("gtm interceptor: error duplicating sendBeacon:",g)}return o}return e.apply(this,arguments)}}}class A{install(t){try{let e=Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype,"src"),i=e&&e.set,n=e&&e.get,o=HTMLScriptElement.prototype.setAttribute,g=l=>{try{if(!t.isTargetUrl(l))return;fetch(t.buildDuplicateUrl(l),{method:"GET",keepalive:!0,credentials:"include"}).catch(d=>{t.debug&&console.error("gtm interceptor: error duplicating script GET:",d)})}catch(d){}};if(i&&n){let l=i,d=n;Object.defineProperty(HTMLScriptElement.prototype,"src",{configurable:!0,enumerable:!0,get:function(){return d.call(this)},set:function(s){try{let p=this.__ga4LastSrcDuplicated;s&&s!==p&&(g(String(s)),this.__ga4LastSrcDuplicated=String(s));let u=this,c=function(){try{let a=u.src;a&&a!==u.__ga4LastSrcDuplicated&&(g(a),u.__ga4LastSrcDuplicated=a)}catch(a){}u.removeEventListener("load",c)};this.addEventListener("load",c)}catch(p){}l.call(this,s)}})}HTMLScriptElement.prototype.setAttribute=function(l,d){try{if(String(l).toLowerCase()==="src"){let s=String(d),p=this.__ga4LastSrcDuplicated;s&&s!==p&&(g(s),this.__ga4LastSrcDuplicated=s);let u=this,c=function(){try{let a=u.src;a&&a!==u.__ga4LastSrcDuplicated&&(g(a),u.__ga4LastSrcDuplicated=a)}catch(a){}u.removeEventListener("load",c)};this.addEventListener("load",c)}}catch(s){}return o.apply(this,arguments)}}catch(e){}}}if(window.__ga4DuplicatorInitialized){h.debug&&console.warn("GA4 Duplicator: already initialized.");return}let f=[];if(h.destinations&&Array.isArray(h.destinations))for(let r=0;r<h.destinations.length;r++){let t=h.destinations[r];f.push({measurement_id:t.measurement_id,server_container_url:t.server_container_url,convert_to_get:t.convert_to_get!==void 0?t.convert_to_get:h.convert_to_get})}if(h.server_container_url&&f.push({measurement_id:"*",server_container_url:h.server_container_url,convert_to_get:h.convert_to_get}),f.length===0){console.error("GA4 Duplicator: either server_container_url or destinations array is required");return}function T(r){return r=String(r||""),r=r.replace(/\/+$/,""),r===""?"/":r}function P(r,t){if(!r||r==="*")return!0;try{let e=r.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp("^"+e+"$","i").test(t)}catch(e){return r.toLowerCase()===t.toLowerCase()}}function v(r,t){let e=String(r||""),i=String(t||"").trim();if(!e||!i)return e;let n=e.indexOf("#"),o=n>=0?e.slice(0,n):e,g=n>=0?e.slice(n):"",l=o.indexOf("?"),d=l>=0?o.slice(0,l):o,s=l>=0?o.slice(l+1):"",p=s?s.split("&").map(a=>a.trim()).filter(Boolean):[],u=[];for(let a=0;a<p.length;a++){let m=p[a];m!==i&&(m.startsWith(i+"=")||u.push(m))}let c=u.length>0?u.join("&")+"&"+i:i;return d+"?"+c+g}function G(r){try{let t=new URL(r,location.href);return t.searchParams.get("tid")||t.searchParams.get("id")||""}catch(t){let e=r.match(/[?&](?:tid|id)=([^&?#]+)/);return e?decodeURIComponent(e[1]):""}}function U(r){for(let t=0;t<f.length;t++)if(P(f[t].measurement_id,r))return f[t];return null}function b(r,t){try{let e=new URL(r,location.href),i=new URLSearchParams(t);for(let[n]of i.entries())e.searchParams.delete(n);for(let[n,o]of i.entries())e.searchParams.append(n,o);return v(e.toString(),"richsstsse")}catch(e){let i=r.split("?")[0],n=r.match(/\?(.*)/)?r.match(/\?(.*)/)[1]:"",o=n+(n&&t?"&":"")+t;return v(i+(o?"?"+o:""),"richsstsse")}}function S(r){let t=String(r.server_container_url||"").trim(),e=new URL(t,location.href);return e.search="",e.hash="",e}function O(r){if(!r||typeof r!="string")return!1;try{let t=new URL(r,location.href);for(let l=0;l<f.length;l++){let d=S(f[l]);if(t.origin===d.origin&&T(t.pathname)===T(d.pathname))return!1}let e=t.searchParams,i=e.has("gtm"),n=e.has("tag_exp"),o=e.get("tid")||e.get("id")||"",g=/^G-[A-Z0-9]+$/i.test(o);return i&&n&&g}catch(t){if(typeof r=="string"){for(let o=0;o<f.length;o++)try{let g=S(f[o]),l=g.origin+g.pathname;if(r.indexOf(l)!==-1)return!1}catch(g){}let e=r.indexOf("gtm=")!==-1,i=r.indexOf("tag_exp=")!==-1,n=r.match(/[?&](?:tid|id)=G-[A-Za-z0-9]+/);return!!(e&&i&&n)}return!1}}function k(r){let t=G(r),e=U(t);if(!e)return"";let i=S(e);try{let n=new URL(r,location.href);i.search=n.search,i.searchParams.set("_dtv",w),i.searchParams.set("_dtn","gd")}catch(n){}return v(i.toString(),"richsstsse")}function q(r){let t=G(r),e=U(t);return e?!!e.convert_to_get:!1}let C={debug:!!h.debug,isTargetUrl:O,buildDuplicateUrl:k,getConvertToGet:q},D=[new L,new I,new R,new A];for(let r=0;r<D.length;r++)try{D[r].install(C)}catch(t){h.debug&&console.error("GA4 Duplicator: failed to install interceptor",t)}window.__ga4DuplicatorInitialized=!0};})();
|