UNPKG

2.13 kBJavaScriptView Raw
1this.workbox=this.workbox||{},this.workbox.googleAnalytics=function(e,n,t,o,r,c,s){"use strict";try{self.workbox.v["workbox:google-analytics:3.0.1"]=1}catch(e){}const l="www.google-analytics.com",i=/^\/(\w+\/)?collect/,a=(()=>{var e=babelHelpers.asyncToGenerator(function*(e){return yield new Promise(function(n,t){const o=new FileReader;o.onloadend=function(){return n(o.result)},o.onerror=function(){return t(o.error)},o.readAsText(e)})});return function(n){return e.apply(this,arguments)}})(),u=e=>(()=>{var n=babelHelpers.asyncToGenerator(function*(n){let{url:t,requestInit:o,timestamp:r}=n;t=new URL(t);let c;if(o.body){const e=o.body instanceof Blob?yield a(o.body):o.body;c=new URLSearchParams(e)}else c=t.searchParams;const s=r-(Number(c.get("qt"))||0),l=Date.now()-s;if(c.set("qt",l),e.parameterOverrides)for(const n of Object.keys(e.parameterOverrides)){const t=e.parameterOverrides[n];c.set(n,t)}"function"==typeof e.hitFilter&&e.hitFilter.call(null,c),o.body=c.toString(),o.method="POST",o.mode="cors",o.credentials="omit",o.headers={"Content-Type":"text/plain"},n.url=`${t.origin}${t.pathname}`});return function(e){return n.apply(this,arguments)}})();return e.initialize=((e={})=>{const a=t.cacheNames.getGoogleAnalyticsName(e.cacheName),w=new n.Plugin("workbox-google-analytics",{maxRetentionTime:2880,callbacks:{requestWillReplay:u(e)}}),f=[(e=>{const n=new c.NetworkFirst({cacheName:e});return new o.Route(({url:e})=>e.hostname===l&&"/analytics.js"===e.pathname,n,"GET")})(a),(e=>{const n=new c.NetworkFirst({cacheName:e});return new o.Route(({url:e})=>"www.googletagmanager.com"===e.hostname&&"/gtag/js"===e.pathname,n,"GET")})(a),...(e=>{const n=({url:e})=>e.hostname===l&&i.test(e.pathname),t=new s.NetworkOnly({plugins:[e]});return[new o.Route(n,t,"GET"),new o.Route(n,t,"POST")]})(w)],b=new r.Router;for(const e of f)b.registerRoute(e);self.addEventListener("fetch",e=>{const n=b.handleRequest(e);n&&e.respondWith(n)})}),e}({},workbox.backgroundSync,workbox.core._private,workbox.routing,workbox.routing,workbox.strategies,workbox.strategies);
2
3//# sourceMappingURL=workbox-google-analytics.prod.js.map