workbox-google-analytics
Advanced tools
Comparing version 4.0.0-alpha.0 to 4.0.0-beta.0
this.workbox = this.workbox || {}; | ||
this.workbox.googleAnalytics = (function (exports,Plugin_mjs,cacheNames_mjs,Route_mjs,Router_mjs,NetworkFirst_mjs,NetworkOnly_mjs) { | ||
this.workbox.googleAnalytics = (function (exports,Plugin_mjs,cacheNames_mjs,getFriendlyURL_mjs,logger_mjs,Route_mjs,Router_mjs,NetworkFirst_mjs,NetworkOnly_mjs) { | ||
'use strict'; | ||
try { | ||
self.workbox.v['workbox:google-analytics:4.0.0-alpha.0'] = 1; | ||
self.workbox.v['workbox:google-analytics:4.0.0-beta.0'] = 1; | ||
} catch (e) {} // eslint-disable-line | ||
@@ -37,25 +37,2 @@ | ||
/** | ||
* Promisifies the FileReader API to await a text response from a Blob. | ||
* | ||
* @param {Blob} blob | ||
* @return {Promise<string>} | ||
* | ||
* @private | ||
*/ | ||
const getTextFromBlob = async blob => { | ||
// This usage of `return await new Promise...` is intentional to work around | ||
// a bug in the transpiled/minified output. | ||
// See https://github.com/GoogleChrome/workbox/issues/1186 | ||
return await new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.onloadend = () => resolve(reader.result); | ||
reader.onerror = () => reject(reader.error); | ||
reader.readAsText(blob); | ||
}); | ||
}; | ||
/** | ||
* Creates the requestWillDequeue callback to be used with the background | ||
@@ -72,49 +49,67 @@ * sync queue plugin. The callback takes the failed request and adds the | ||
const createOnSyncCallback = config => { | ||
return async ({ | ||
queue | ||
}) => { | ||
let entry; | ||
const createRequestWillReplayCallback = config => { | ||
return async storableRequest => { | ||
let { | ||
url, | ||
requestInit, | ||
timestamp | ||
} = storableRequest; | ||
url = new URL(url); // Measurement protocol requests can set their payload parameters in either | ||
// the URL query string (for GET requests) or the POST body. | ||
while (entry = await queue.shiftRequest()) { | ||
const { | ||
request, | ||
timestamp | ||
} = entry; | ||
const url = new URL(request.url); | ||
let params; | ||
try { | ||
// Measurement protocol requests can set their payload parameters in | ||
// either the URL query string (for GET requests) or the POST body. | ||
const params = request.method === 'POST' ? new URLSearchParams((await request.text())) : url.searchParams; // Calculate the qt param, accounting for the fact that an existing | ||
// qt param may be present and should be updated rather than replaced. | ||
if (requestInit.body) { | ||
const payload = requestInit.body instanceof Blob ? await getTextFromBlob(requestInit.body) : requestInit.body; | ||
params = new URLSearchParams(payload); | ||
} else { | ||
params = url.searchParams; | ||
} // Calculate the qt param, accounting for the fact that an existing | ||
// qt param may be present and should be updated rather than replaced. | ||
const originalHitTime = timestamp - (Number(params.get('qt')) || 0); | ||
const queueTime = Date.now() - originalHitTime; // Set the qt param prior to applying hitFilter or parameterOverrides. | ||
params.set('qt', queueTime); // Apply `paramterOverrideds`, if set. | ||
const originalHitTime = timestamp - (Number(params.get('qt')) || 0); | ||
const queueTime = Date.now() - originalHitTime; // Set the qt param prior to applying the hitFilter or parameterOverrides. | ||
if (config.parameterOverrides) { | ||
for (const param of Object.keys(config.parameterOverrides)) { | ||
const value = config.parameterOverrides[param]; | ||
params.set(param, value); | ||
} | ||
} // Apply `hitFilter`, if set. | ||
params.set('qt', queueTime); | ||
if (config.parameterOverrides) { | ||
for (const param of Object.keys(config.parameterOverrides)) { | ||
const value = config.parameterOverrides[param]; | ||
params.set(param, value); | ||
if (typeof config.hitFilter === 'function') { | ||
config.hitFilter.call(null, params); | ||
} // Retry the fetch. Ignore URL search params form the URL as they're | ||
// now in the post body. | ||
await fetch(new Request(url.origin + url.pathname, { | ||
body: params.toString(), | ||
method: 'POST', | ||
mode: 'cors', | ||
credentials: 'omit', | ||
headers: { | ||
'Content-Type': 'text/plain' | ||
} | ||
})); | ||
{ | ||
logger_mjs.logger.log(`Request for '${getFriendlyURL_mjs.getFriendlyURL(url.href)}'` + `has been replayed`); | ||
} | ||
} catch (err) { | ||
await queue.unshiftRequest(entry); | ||
{ | ||
logger_mjs.logger.log(`Request for '${getFriendlyURL_mjs.getFriendlyURL(url.href)}'` + `failed to replay, putting it back in the queue.`); | ||
} | ||
return; | ||
} | ||
} | ||
if (typeof config.hitFilter === 'function') { | ||
config.hitFilter.call(null, params); | ||
{ | ||
logger_mjs.logger.log(`All Google Analytics request successfully replayed; ` + `the queue is now empty!`); | ||
} | ||
requestInit.body = params.toString(); | ||
requestInit.method = 'POST'; | ||
requestInit.mode = 'cors'; | ||
requestInit.credentials = 'omit'; | ||
requestInit.headers = { | ||
'Content-Type': 'text/plain' | ||
}; // Ignore URL search params as they're now in the post body. | ||
storableRequest.url = `${url.origin}${url.pathname}`; | ||
}; | ||
@@ -204,5 +199,3 @@ }; | ||
maxRetentionTime: MAX_RETENTION_TIME, | ||
callbacks: { | ||
requestWillReplay: createRequestWillReplayCallback(options) | ||
} | ||
onSync: createOnSyncCallback(options) | ||
}); | ||
@@ -239,4 +232,4 @@ const routes = [createAnalyticsJsRoute(cacheName), createGtagJsRoute(cacheName), ...createCollectRoutes(queuePlugin)]; | ||
}({},workbox.backgroundSync,workbox.core._private,workbox.routing,workbox.routing,workbox.strategies,workbox.strategies)); | ||
}({},workbox.backgroundSync,workbox.core._private,workbox.core._private,workbox.core._private,workbox.routing,workbox.routing,workbox.strategies,workbox.strategies)); | ||
//# sourceMappingURL=workbox-offline-ga.dev.js.map |
@@ -1,3 +0,3 @@ | ||
this.workbox=this.workbox||{},this.workbox.googleAnalytics=function(e,t,o,n,c,a,s){"use strict";try{self.workbox.v["workbox:google-analytics:4.0.0-alpha.0"]=1}catch(e){}const r=/^\/(\w+\/)?collect/,w=e=>async t=>{let o,{url:n,requestInit:c,timestamp:a}=t;if(n=new URL(n),c.body){const e=c.body instanceof Blob?await(async e=>await new Promise((t,o)=>{const n=new FileReader;n.onloadend=(()=>t(n.result)),n.onerror=(()=>o(n.error)),n.readAsText(e)}))(c.body):c.body;o=new URLSearchParams(e)}else o=n.searchParams;const s=a-(Number(o.get("qt"))||0),r=Date.now()-s;if(o.set("qt",r),e.parameterOverrides)for(const t of Object.keys(e.parameterOverrides)){const n=e.parameterOverrides[t];o.set(t,n)}"function"==typeof e.hitFilter&&e.hitFilter.call(null,o),c.body=o.toString(),c.method="POST",c.mode="cors",c.credentials="omit",c.headers={"Content-Type":"text/plain"},t.url=`${n.origin}${n.pathname}`};return e.initialize=((e={})=>{const l=o.cacheNames.getGoogleAnalyticsName(e.cacheName),i=new t.Plugin("workbox-google-analytics",{maxRetentionTime:2880,callbacks:{requestWillReplay:w(e)}}),u=[(e=>{const t=new a.NetworkFirst({cacheName:e});return new n.Route(({url:e})=>"www.google-analytics.com"===e.hostname&&"/analytics.js"===e.pathname,t,"GET")})(l),(e=>{const t=new a.NetworkFirst({cacheName:e});return new n.Route(({url:e})=>"www.googletagmanager.com"===e.hostname&&"/gtag/js"===e.pathname,t,"GET")})(l),...(e=>{const t=({url:e})=>"www.google-analytics.com"===e.hostname&&r.test(e.pathname),o=new s.NetworkOnly({plugins:[e]});return[new n.Route(t,o,"GET"),new n.Route(t,o,"POST")]})(i)],m=new c.Router;for(const e of u)m.registerRoute(e);m.addFetchListener()}),e}({},workbox.backgroundSync,workbox.core._private,workbox.routing,workbox.routing,workbox.strategies,workbox.strategies); | ||
this.workbox=this.workbox||{},this.workbox.googleAnalytics=function(t,e,o,n,c,a,r){"use strict";try{self.workbox.v["workbox:google-analytics:4.0.0-beta.0"]=1}catch(t){}const w=/^\/(\w+\/)?collect/;return t.initialize=((t={})=>{const s=o.cacheNames.getGoogleAnalyticsName(t.cacheName),i=new e.Plugin("workbox-google-analytics",{maxRetentionTime:2880,onSync:(t=>async({queue:e})=>{let o;for(;o=await e.shiftRequest();){const{request:n,timestamp:c}=o,a=new URL(n.url);try{const r="POST"===n.method?new URLSearchParams(await n.text()):a.searchParams,w=c-(Number(r.get("qt"))||0),s=Date.now()-w;if(r.set("qt",s),t.parameterOverrides)for(const e of Object.keys(t.parameterOverrides)){const o=t.parameterOverrides[e];r.set(e,o)}"function"==typeof t.hitFilter&&t.hitFilter.call(null,r),await fetch(new Request(a.origin+a.pathname,{body:r.toString(),method:"POST",mode:"cors",credentials:"omit",headers:{"Content-Type":"text/plain"}}))}catch(t){return void await e.unshiftRequest(o)}}})(t)}),l=[(t=>{const e=new a.NetworkFirst({cacheName:t});return new n.Route(({url:t})=>"www.google-analytics.com"===t.hostname&&"/analytics.js"===t.pathname,e,"GET")})(s),(t=>{const e=new a.NetworkFirst({cacheName:t});return new n.Route(({url:t})=>"www.googletagmanager.com"===t.hostname&&"/gtag/js"===t.pathname,e,"GET")})(s),...(t=>{const e=({url:t})=>"www.google-analytics.com"===t.hostname&&w.test(t.pathname),o=new r.NetworkOnly({plugins:[t]});return[new n.Route(e,o,"GET"),new n.Route(e,o,"POST")]})(i)],u=new c.Router;for(const t of l)u.registerRoute(t);u.addFetchListener()}),t}({},workbox.backgroundSync,workbox.core._private,workbox.routing,workbox.routing,workbox.strategies,workbox.strategies); | ||
//# sourceMappingURL=workbox-offline-ga.prod.js.map |
{ | ||
"name": "workbox-google-analytics", | ||
"version": "4.0.0-alpha.0", | ||
"version": "4.0.0-beta.0", | ||
"license": "MIT", | ||
@@ -32,8 +32,8 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"workbox-background-sync": "^4.0.0-alpha.0", | ||
"workbox-core": "^4.0.0-alpha.0", | ||
"workbox-routing": "^4.0.0-alpha.0", | ||
"workbox-strategies": "^4.0.0-alpha.0" | ||
"workbox-background-sync": "^4.0.0-beta.0", | ||
"workbox-core": "^4.0.0-beta.0", | ||
"workbox-routing": "^4.0.0-beta.0", | ||
"workbox-strategies": "^4.0.0-beta.0" | ||
}, | ||
"gitHead": "db1fb73fd32fbd5cbf42e246e6144011a5c6edc2" | ||
"gitHead": "bc90cc4bdb1f8ad435564aa84b0c90acfac611e2" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
40068
3
420
4
3