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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@arraypress/referrer

v1.0.0

Published

Parse referrer URLs to detect traffic sources, search engines, social platforms, and UTM parameters.

Readme

@arraypress/referrer

Parse referrer URLs to detect traffic sources, search engines, social platforms, and UTM campaign parameters. Designed for analytics and traffic attribution in ecommerce and SaaS applications.

Zero dependencies. Works in Node.js, Cloudflare Workers, Deno, Bun, and browsers.

Installation

npm install @arraypress/referrer

Usage

import { getSource, getTrafficType, getSearchTerms, getUtmParams } from '@arraypress/referrer';

// Identify the traffic source
getSource('https://www.google.com/search?q=test');  // 'google'
getSource('https://t.co/abc123');                    // 'twitter'
getSource('https://some-blog.com/post');             // 'referral'
getSource('');                                        // 'direct'

// Categorize traffic type
getTrafficType('https://google.com/search?q=test');             // 'search'
getTrafficType('https://facebook.com/post/123');                // 'social'
getTrafficType('https://blog.com/?utm_source=newsletter');      // 'campaign'
getTrafficType('https://random-blog.com/article');              // 'referral'
getTrafficType('');                                              // 'direct'

// Extract search terms
getSearchTerms('https://google.com/search?q=best+sample+packs');  // 'best sample packs'
getSearchTerms('https://facebook.com/post');                       // null

// Extract UTM parameters
getUtmParams('https://store.com/?utm_source=newsletter&utm_medium=email&utm_campaign=launch');
// { source: 'newsletter', medium: 'email', campaign: 'launch', term: null, content: null }

API

getSource(url: string): string

Returns the specific traffic source. For recognized platforms, returns the platform name (e.g. 'google', 'facebook', 'reddit'). For unknown domains returns 'referral'. For empty/null input returns 'direct'.

getTrafficType(url: string): TrafficType

Returns the broad traffic category: 'search', 'social', 'campaign', 'referral', or 'direct'.

UTM parameters take precedence — if any UTM param is present, returns 'campaign' regardless of the domain. This means https://google.com/?utm_source=promo returns 'campaign', not 'search'.

getSearchTerms(url: string): string | null

Extracts the search query from a search engine referrer URL. Returns null if the URL is not from a recognized search engine or has no query parameter.

Checks these query parameters: q, query, p, wd, text.

Note: Many search engines (especially Google) no longer pass search terms in the referrer URL for privacy reasons.

getUtmParams(url: string): UtmParams

Extracts UTM campaign parameters. Always returns an object with all five fields; missing parameters are null.

interface UtmParams {
  source: string | null;    // utm_source
  medium: string | null;    // utm_medium
  campaign: string | null;  // utm_campaign
  term: string | null;      // utm_term
  content: string | null;   // utm_content
}

Supported Platforms

Search Engines (18): Google (30+ regional domains), Bing, Yahoo, DuckDuckGo, Baidu, Yandex, Ecosia, Startpage, Brave, Ask, AOL, Searx, Perplexity, You.com, Phind, Kagi, SearchGPT/ChatGPT, DeepSeek.

Social Platforms (15): Facebook, Twitter/X, Instagram, LinkedIn, Pinterest, Reddit, YouTube, TikTok, Snapchat, Discord, Telegram, WhatsApp, Mastodon, Threads, Bluesky.

All platforms include mobile variants, short link domains (t.co, fb.me, youtu.be, etc.), and regional subdomains.

Recommended Pattern

Store the raw referrer URL in your database and parse it on read. This preserves the original data and automatically benefits from future platform updates.

// At checkout — capture and store raw URL
const referrer = request.headers.get('referer') || '';
await db.prepare('UPDATE orders SET referrer = ? WHERE id = ?')
  .bind(referrer, orderId).run();

// In reports — parse on read
import { getSource, getTrafficType } from '@arraypress/referrer';

const source = getSource(order.referrer);  // 'google'
const type = getTrafficType(order.referrer);  // 'search'

TypeScript

Full type definitions are included.

import { getSource, getTrafficType, getUtmParams } from '@arraypress/referrer';
import type { TrafficType, UtmParams } from '@arraypress/referrer';

const source: string = getSource(url);
const type: TrafficType = getTrafficType(url);
const utm: UtmParams = getUtmParams(url);

License

MIT