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

@gebruederheitz/sticky-parameters

v2.3.3

Published

Forward certain URL parameters to allowlisted or non-denylisted links on the current site.

Downloads

3

Readme

Sticky Parameters

with Referrer Parameters

Forward certain URL parameters to allowlisted or non-denylisted links on the current site.


A utility script to make URL parameters "sticky" across pages / domains. Works by appending allowlisted parameters to anchor elements on the the current page linking to allowed domains.

Before

<a href="https://example.com/test?param=true">Link</a>
<a href="https://my-site.com/test?param=true">Link</a>
<a href="https://example.net/test?param=true">Link</a>

Request

https://my-site.com/with/sticky/parameters?id=123&color=blue&[email protected]

Config

allowedDomains: 
  - example.com
allowedParameters:
  - id
  - email
applyToExternalLinks:
  true

Result

<a href="https://example.com/test?param=true&id=123&[email protected]">Link</a>
<a href="https://my-site.com/test?param=true&id=123&[email protected]">Link</a>
<a href="https://example.net/test?param=true">Link</a>

Installation

> npm i @gebruederheitz/sticky-parameters

Usage

TL;DR: ES modules

import { StickyParameters } from '@gebruederheitz/sticky-parameters';

const sp = new StickyParameters(
    ['allowed', 'parameters'],
    ['allowed', 'domains.com'],
    false   // pass to external links
);

sp.run();

Configuration

The Sticky Parameters class expects three configuration parameters:

| Type | Description | Default | | --- | --- | --- | | String / String[] | A list of parameters that may be passed to qualifying links | [] | | String / String[] | A list of domains that may receive the allowed parameters | [] | | bool | Whether to allow modifying external links (true) or internal links only | false |

UMD builds

UMD builds can be found in /dist/sticky-parameters.umd.js.

<script src="/node_modules/@gebruederheitz/sticky-parameters/dist/sticky-parameters.umd.js"></script>

<script>
    const sp = new stickyParameters.StickyParameters(params, domains, false);
    window.addEventListener('load', () => {
        sp.run();
    });
</script>

Referrer Parameters

This special module allows to set further parameters depending on the document.referrer provided in order to measure SEO performance.

Usage

import { StickyParameters, ReferrerParameters } from '@gebruederheitz/sticky-parameters';

const sp = new StickyParameters(params, domains, true);
new ReferrerParameters(
    // RP will call .run() on the provided SP at the right time:
    sp,
    // If this parameter is set, processing will be skipped:
    'indexParameter',
    // Only these parameters will be parsed from the current URL:
    ['indexParameter', 'utm_id', 'source'],  
    // When a referrer is set, this callback will allow you to set your parameters
    // to the appropriate values based on the referrer string:
    (referrerString) => [
        {name: 'source', value: referrerString}
    ],
    // These parameters will be set when the indexParameter is not set and no
    // referrer string could be read from the browser:
    [
        {name: 'source', value: 'direct'},
    ]
); 

UMD / CommonJS

<head>
    <script src="/node_modules/@gebruederheitz/sticky-parameters/dist/sticky-parameters.umd.js"></script>
</head>
<body>

<!-- ... -->

    <script>
        const sp = new stickyParameters.StickyParameters(params, domains, false);
        new stickyParameters.ReferrerParameters(sp, indexP, parsedPs, getPsByRef, directPs);
    </script>
</body>

Development

Take a look at the Makefile for an overview of the most common tasks needed during development. To quickly get the project up and running use

# Install dependencies, run a watch task and host demo at localhost:5000:
$> make
# or, more explicitly:
$> make dev

To publish a new release you can use release-it with

$> make release
# or
$> npm run release