Registry / analytics / global-queue

global-queue

JSON →
library1.0.1jsnpmunverified

A micro-package (~20 lines) that generates a push function for a global queue array (e.g., window._analytics). Version 1.0.1 is stable; no regular releases. Designed for 3rd-party analytics/tracking snippets where standard async patterns (like promises or event emitters) aren't available. Unlike bespoke queue implementations, it ensures the queue array exists and pushes raw arguments (or wrapped arrays) onto it. Intended for browser use only—no Node.js environment considered. Minimal footprint, no dependencies, and trivial API (one exported function).

npm install global-queue
INSTALL
IMPORT
SIG · GLOBAL-QUEUE
G
global-queue
analyticsjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import push from 'global-queue'
import { push } from 'global-queue'
The module exports a single factory function; default import is correct.
require
const push = require('global-queue')
const { push } = require('global-queue')
CommonJS usage: the factory function is the entire exports object.
factory call
const push = require('global-queue')('_analytics');
const push = require('global-queue')({ name: '_analytics' });
First argument is the queue name (string), not an options object.

Creates a push function for window._analytics and pushes two calls; shows resulting queue structure.

const push = require('global-queue')('_analytics'); push('identify', { userId: 'abc123' }); push('track', 'Page View', { page: '/' }); console.log(window._analytics); // [ ['identify', {userId:'abc123'}], ['track','Page View',{page:'/'}] ]
Debug
Known issues
gotchaglobal-queue writes to the global window object; not usable in Node.js or service workers where window is undefined.
fix
Use only in browser contexts; wrap in feature check: if (typeof window !== 'undefined') { ... }.
affects: all
gotchaBy default, arguments are wrapped in an array. Most analytics services expect this, but some (e.g., custom queues) may require raw arguments.
fix
Pass { wrap: false } as second argument to keep arguments unwrapped: const push = require('global-queue')('_analytics', { wrap: false });
affects: all
gotchaIf the queue array already exists, global-queue does not override it—it uses the existing array. That can cause unexpected ordering if other code already enqueued items.
fix
Ensure no other script creates the queue before calling global-queue, or manually clear it: window._analytics = [];
affects: all
Errors
Common errors & fixes
ReferenceError: window is not defined
Attempted to use global-queue in a non-browser environment (e.g., Node.js, Web Worker).
fix
Wrap in a browser check: if (typeof window !== 'undefined') { const push = require('global-queue')('_analytics'); }
TypeError: push is not a function
Imported incorrectly (e.g., named import instead of default), or forgot to call the factory with the queue name.
fix
Correct usage: const push = require('global-queue')('_myQueue');
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
36 hits · last 30 days
node
34
OpenAI (training)
1
Resources
global-queue — npm install global-queue · libregistry