Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@serwist/google-analytics

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serwist/google-analytics - npm Package Compare versions

Comparing version 9.0.0-preview.0 to 9.0.0-preview.1

70

dist/initialize.js

@@ -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, {

12

package.json
{
"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": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc