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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@uxf/analytics

v11.90.0

Published

[![npm](https://img.shields.io/npm/v/@uxf/analytics)](https://www.npmjs.com/package/@uxf/analytics) [![size](https://img.shields.io/bundlephobia/min/@uxf/analytics)](https://www.npmjs.com/package/@uxf/analytics) [![quality](https://img.shields.io/npms-io/

Readme

@uxf/analytics

npm size quality license

Installation

yarn add @uxf/analytics
npm install @uxf/analytics

Cookie consent

Store consent to cookie

import { storeConsentToCookie } from "@uxf/analytics/consent";

storeConsentToCookie(
    {
        ad_personalization: true,
        ad_storage: false,
        ad_user_data: false,
        analytics_storage: false,
    },
    1 // version - this allows us to simply re-request consents from users
);

Read consent from cookie

import { readConsentFromCookie } from "@uxf/analytics/consent";

const consent = readConsentFromCookie();

Check if cookie consent is set

This checks if the consent is already stored in cookies.

import { isConsentCookieSet } from "@uxf/analytics/consent";

const isSet = isCookieConsentSet(
    null,
    1 // version - this allows us to simply re-request consents from users
); // boolean

GTM

Initialize GTM

This reads the consent from cookie and initializes the GTM dataLayer.

import { GtmScript } from "@uxf/analytics/gtm";

// in your head component (not directly in _app)
<GtmScript gtmId="GTM-YOURID" />

or with hook

import { useGtmScript } from "@uxf/analytics/gtm";

const gtmScript = useGtmScript("GTM-YOURID");

// in your head component (not directly in _app)
<script dangerouslySetInnerHTML={{ __html: gtmScript }} />

Update GTM consent

This stores the consent to cookie and updates the GTM dataLayer.

import { updateGtmConsent } from "@uxf/analytics/gtm";

updateGtmConsent(
    {
        ad_personalization: true,
        ad_storage: false,
        ad_user_data: false,
        analytics_storage: false,
    },
    1
);

AB testing

A set of components and helpers prepared to implement AB testing to React & NextJS applications.

How to start

1. Define your experiments

import type { ExperimentConfig } from "@uxf/analytics/ab-testing";

const experiments = [
    {
        id: "1",
        traffic: 1,
        variants: [
            { name: "Control", traffic: 0.5 },
            { name: "B", traffic: 0.5 },
        ],
    },
    {
        id: "2",
        traffic: 0.5,
        variants: [
            { name: "Control", traffic: 0.25 },
            { name: "B", traffic: 0.75 },
        ],
    },
] as const satisfies ExperimentConfig[];

2. Use the ABTestingProvider component

import { ABTestingProvider, AB_TESTING_VARIANT_PROP_NAME } from "@uxf/analytics/ab-testing";

export default function App({ Component, pageProps }) {
    return (
        <ABTestingProvider experiments={props.pageProps[AB_TESTING_VARIANT_PROP_NAME]}>
            <Component {...pageProps} />
        </ABTestingProvider>
    );
}

3. Handle AB testing in middleware.ts

import { handleABTesting } from "@uxf/analytics/ab-testing";

export async function middleware(request: NextRequest) {
    const nextResponse = NextResponse.next();

    handleABTesting(request, nextResponse, experiments);

    return nextResponse;
}

4. Implement SSR support in page with AB testing

import { addExperimentsSSR } from "@uxf/analytics/ab-testing";

export const getServerSideProps: GetServerSideProps = async (ctx) => {
    return addExperimentsSSR(ctx, {
        props: {},
    });
};

5. Use the useABTestingVariant hook in your component

import { useABTestingVariant } from "@uxf/analytics/ab-testing";

const abTestingVariant = useABTestingVariant<typeof experiments>("1");

console.log(abTestingVariant); // "Control", "B", etc.