Skip to content
Open Source

Branded Short Links, Custom Domain Redirects with Analytics Built In.

Published on

Featured image for "Branded Short Links, Custom Domain Redirects with Analytics Built In."

A random string of characters tells nobody where a link goes. A link like yourdomain.com/github does — and today we are releasing Branded Short Links, our open source project for running custom domain short links on Cloudflare Workers at the edge, with no origin server needed.

Every redirect is a real HTTP 3xx response — no http-equiv meta refresh tricks — so search engines see your links exactly the way they should.

Your links, your domain, your analytics.

Analytics with zero client-side JavaScript

A 3xx redirect never loads a page, so how do you track it? We lean on an under-documented Google Tag Manager feature: the worker executes your GTM tags server-side through GTM’s noscript mode. Point the gtm_container_id setting at your container and tracking just works, without a single line of client-side JavaScript.

Google Analytics 4 is supported through a GTM Custom Image tag hitting the GA4 Measurement Protocol, and ntfy push notifications work the same way as an alternative custom tag. Each request also gathers rich visitor data from Cloudflare — city, region, country, ASN, coordinates, timezone, data center, user-agent, and more — and exposes it to your tags as data-layer variables like cf_*, headers_*, bsl_shortcode, and bsl_redirectUrl.

Each short link is a few lines of configuration: a shortcode, a redirect URL, and your choice of HTTP response code per link (301, 302, 303, 307, or 308). Unmatched shortcodes fall back to a configurable fallback URL while retaining the original request.

Two extra settings round things out: debug_mode runs your custom image tags and shows their responses instead of redirecting, and force_https keeps every visit on a secure connection.

Free, open, and ready to deploy

Branded Short Links is open source on GitHub under the Apache License 2.0. Deploying takes minutes: clone the repo, npm install, wrangler login, and wrangler deploy — the Cloudflare network handles the rest with minimal maintenance.

Your domain is already sitting there — grab Branded Short Links and put it to work!