@serwist/google-analytics
Advanced tools
Comparing version 9.0.0-preview.0 to 9.0.0-preview.1
@@ -6,10 +6,4 @@ import { BackgroundSyncPlugin } from '@serwist/background-sync'; | ||
/* | ||
Copyright 2018 Google LLC | ||
Use of this source code is governed by an MIT-style | ||
license that can be found in the LICENSE file or at | ||
https://opensource.org/licenses/MIT. | ||
*/ const QUEUE_NAME = "serwist-google-analytics"; | ||
const MAX_RETENTION_TIME = 60 * 48; // Two days in minutes | ||
const QUEUE_NAME = "serwist-google-analytics"; | ||
const MAX_RETENTION_TIME = 60 * 48; | ||
const GOOGLE_ANALYTICS_HOST = "www.google-analytics.com"; | ||
@@ -20,18 +14,5 @@ const GTM_HOST = "www.googletagmanager.com"; | ||
const GTM_JS_PATH = "/gtm.js"; | ||
// This RegExp matches all known Measurement Protocol single-hit collect | ||
// endpoints. Most of the time the default path (/collect) is used, but | ||
// occasionally an experimental endpoint is used when testing new features, | ||
// (e.g. /r/collect or /j/collect) | ||
const COLLECT_PATHS_REGEX = /^\/(\w+\/)?collect/; | ||
/** | ||
* Creates the requestWillDequeue callback to be used with the background | ||
* sync plugin. The callback takes the failed request and adds the | ||
* `qt` param based on the current time, as well as applies any other | ||
* user-defined hit modifications. | ||
* | ||
* @param config | ||
* @returns The requestWillDequeue callback function. | ||
* @private | ||
*/ const createOnSyncCallback = (config)=>{ | ||
const createOnSyncCallback = (config)=>{ | ||
return async ({ queue })=>{ | ||
@@ -43,12 +24,6 @@ let entry = undefined; | ||
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.clone().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. | ||
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", String(queueTime)); | ||
// Apply `parameterOverrides`, if set. | ||
if (config.parameterOverrides) { | ||
@@ -60,8 +35,5 @@ for (const param of Object.keys(config.parameterOverrides)){ | ||
} | ||
// Apply `hitFilter`, if set. | ||
if (typeof config.hitFilter === "function") { | ||
config.hitFilter.call(null, params); | ||
} | ||
// Retry the fetch. Ignore URL search params from the URL as they're | ||
// now in the post body. | ||
await fetch(new Request(url.origin + url.pathname, { | ||
@@ -92,9 +64,3 @@ body: params.toString(), | ||
}; | ||
/** | ||
* Creates GET and POST routes to catch failed Measurement Protocol hits. | ||
* | ||
* @param bgSyncPlugin | ||
* @returns The created routes. | ||
* @private | ||
*/ const createCollectRoutes = (bgSyncPlugin)=>{ | ||
const createCollectRoutes = (bgSyncPlugin)=>{ | ||
const match = ({ url })=>url.hostname === GOOGLE_ANALYTICS_HOST && COLLECT_PATHS_REGEX.test(url.pathname); | ||
@@ -111,9 +77,3 @@ const handler = new NetworkOnly({ | ||
}; | ||
/** | ||
* Creates a route with a network first strategy for the analytics.js script. | ||
* | ||
* @param cacheName | ||
* @returns The created route. | ||
* @private | ||
*/ const createAnalyticsJsRoute = (cacheName)=>{ | ||
const createAnalyticsJsRoute = (cacheName)=>{ | ||
const match = ({ url })=>url.hostname === GOOGLE_ANALYTICS_HOST && url.pathname === ANALYTICS_JS_PATH; | ||
@@ -125,9 +85,3 @@ const handler = new NetworkFirst({ | ||
}; | ||
/** | ||
* Creates a route with a network first strategy for the gtag.js script. | ||
* | ||
* @param cacheName | ||
* @returns The created route. | ||
* @private | ||
*/ const createGtagJsRoute = (cacheName)=>{ | ||
const createGtagJsRoute = (cacheName)=>{ | ||
const match = ({ url })=>url.hostname === GTM_HOST && url.pathname === GTAG_JS_PATH; | ||
@@ -139,9 +93,3 @@ const handler = new NetworkFirst({ | ||
}; | ||
/** | ||
* Creates a route with a network first strategy for the gtm.js script. | ||
* | ||
* @param cacheName | ||
* @returns The created route. | ||
* @private | ||
*/ const createGtmJsRoute = (cacheName)=>{ | ||
const createGtmJsRoute = (cacheName)=>{ | ||
const match = ({ url })=>url.hostname === GTM_HOST && url.pathname === GTM_JS_PATH; | ||
@@ -153,5 +101,3 @@ const handler = new NetworkFirst({ | ||
}; | ||
/** | ||
* @param options | ||
*/ const initialize = (options = {})=>{ | ||
const initialize = (options = {})=>{ | ||
const cacheName = privateCacheNames.getGoogleAnalyticsName(options.cacheName); | ||
@@ -158,0 +104,0 @@ const bgSyncPlugin = new BackgroundSyncPlugin(QUEUE_NAME, { |
{ | ||
"name": "@serwist/google-analytics", | ||
"version": "9.0.0-preview.0", | ||
"version": "9.0.0-preview.1", | ||
"type": "module", | ||
@@ -45,6 +45,6 @@ "description": "Queues failed requests and uses the Background Sync API to replay them when the network is available", | ||
"dependencies": { | ||
"@serwist/background-sync": "9.0.0-preview.0", | ||
"@serwist/core": "9.0.0-preview.0", | ||
"@serwist/routing": "9.0.0-preview.0", | ||
"@serwist/strategies": "9.0.0-preview.0" | ||
"@serwist/background-sync": "9.0.0-preview.1", | ||
"@serwist/core": "9.0.0-preview.1", | ||
"@serwist/routing": "9.0.0-preview.1", | ||
"@serwist/strategies": "9.0.0-preview.1" | ||
}, | ||
@@ -54,3 +54,3 @@ "devDependencies": { | ||
"typescript": "5.4.0-dev.20240203", | ||
"@serwist/constants": "9.0.0-preview.0" | ||
"@serwist/constants": "9.0.0-preview.1" | ||
}, | ||
@@ -57,0 +57,0 @@ "peerDependencies": { |
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
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
1
18592
354
+ Added@serwist/background-sync@9.0.0-preview.1(transitive)
+ Added@serwist/core@9.0.0-preview.1(transitive)
+ Added@serwist/routing@9.0.0-preview.1(transitive)
+ Added@serwist/strategies@9.0.0-preview.1(transitive)
- Removed@serwist/background-sync@9.0.0-preview.0(transitive)
- Removed@serwist/core@9.0.0-preview.0(transitive)
- Removed@serwist/routing@9.0.0-preview.0(transitive)
- Removed@serwist/strategies@9.0.0-preview.0(transitive)