npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sw-cache-expiration

v0.0.24

Published

This library automatically expires cached responses based on age or maximum number of entries.

Downloads

17

Readme

sw-offline-google-analytics

A service worker helper library to retry offline Google Analytics requests when a connection is available.

Installation

npm install --save-dev sw-offline-google-analytics

Demo

Browse sample source code in the demo directory, or try it out directly.

API

goog.offlineGoogleAnalytics.initialize

packages/sw-offline-google-analytics/src/index.js:82-132

In order to use the library, callgoog.offlineGoogleAnalytics.initialize(). It will take care of setting up service worker fetch handlers to ensure that the Google Analytics JavaScript is available offline, and that any Google Analytics requests made while offline are saved (using IndexedDB) and retried the next time the service worker starts up.

Parameters

  • config [Object] Optional configuration arguments.
    • config.parameterOverrides [Object] Optional Measurement Protocol parameters, expressed as key/value pairs, to be added to replayed Google Analytics requests. This can be used to, e.g., set a custom dimension indicating that the request was replayed.
    • config.hitFilter [Function] Optional A function that allows you to modify the hit parameters prior to replaying the hit. The function is invoked with the original hit's URLSearchParams object as its only argument. To abort the hit and prevent it from being replayed, throw an error.

Examples

// This code should live inside your service worker JavaScript, ideally
// before any other 'fetch' event handlers are defined:

// First, import the library into the service worker global scope:
importScripts('path/to/offline-google-analytics-import.js');

// Then, call goog.offlineGoogleAnalytics.initialize():
goog.offlineGoogleAnalytics.initialize();

// At this point, implement any other service worker caching strategies
// appropriate for your web app.
// If you need to specify parameters to be sent with each hit, you can use
// the `parameterOverrides` configuration option. This is useful in cases
// where you want to set a custom dimension on all hits sent by the service
// worker to differentiate them in your reports later.
goog.offlineGoogleAnalytics.initialize({
  parameterOverrides: {
    cd1: 'replay'
  }
});
// In situations where you need to programmatically modify a hit's
// parameters you can use the `hitFilter` option. One example of when this
// might be useful is if you wanted to track the amount of time that elapsed
// between when the hit was attempted and when it was successfully replayed.
goog.offlineGoogleAnalytics.initialize({
  hitFilter: searchParams =>
    // Sets the `qt` param as a custom metric.
    const qt = searchParams.get('qt');
    searchParams.set('cm1', qt);
  }
});

Returns undefined