BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/vinkas-ui/utm-link

UTM Link

vinkas-ui/utm-link
FreeComponent

A link component that automatically adds UTM parameters to the href on click

Live preview

live · rendered by the registry
Rendered by vinkas-ui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://ui.vinkas.com/r/utm-link.json

Source

registry/components/ui/utm-link.tsxui.vinkas.com/r/utm-link.json
1"use client"
2
3import Link from "next/link"
4
5type UTMLinkProps = {
6 href: string
7 children: React.ReactNode
8 source?: string
9 medium?: string
10 campaign?: string
11} & React.ComponentProps<typeof Link>
12
13export default function UTMLink({
14 href,
15 children,
16 source,
17 medium,
18 campaign,
19 onMouseDown,
20 onClick,
21 ...props
22}: UTMLinkProps) {
23 const applySearchParams = (e: React.MouseEvent<HTMLAnchorElement>) => {
24 if (e.defaultPrevented) return
25 if (e.button !== 0 && e.type !== "click") return
26 if (!source && !medium && !campaign) return
27
28 const hrefAttr = e.currentTarget.getAttribute("href")
29 if (!hrefAttr || hrefAttr.startsWith("#")) {
30 return
31 }
32
33 const url = new URL(e.currentTarget.href)
34
35 if (url.protocol !== "http:" && url.protocol !== "https:") return
36
37 if (
38 (!source || url.searchParams.has("utm_source")) &&
39 (!medium || url.searchParams.has("utm_medium")) &&
40 (!campaign || url.searchParams.has("utm_campaign"))
41 ) {
42 return
43 }
44
45 if (source && !url.searchParams.has("utm_source")) {
46 url.searchParams.set("utm_source", source)
47 }
48 if (medium && !url.searchParams.has("utm_medium")) {
49 url.searchParams.set("utm_medium", medium)
50 }
51 if (campaign && !url.searchParams.has("utm_campaign")) {
52 url.searchParams.set("utm_campaign", campaign)
53 }
54
55 e.currentTarget.href = url.toString()
56 }
57
58 return (
59 <Link
60 href={href}
61 onMouseDown={(e) => {
62 onMouseDown?.(e)
63 applySearchParams(e)
64 }}
65 onClick={(e) => {
66 onClick?.(e)
67 if (e.detail === 0) applySearchParams(e)
68 }}
69 {...props}>
70 {children}
71 </Link>
72 )
73}

Files it writes

  • registry/components/ui/utm-link.tsx

Facts

Registry
vinkas-ui
Type
registry:ui
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-03
Last confirmed
yesterday

Go to the source

Docs on vinkas-ui ui.vinkas.com vinkashq/ui on GitHub Raw registry item This item as JSON

More from vinkas-ui

All 7 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Copyright Textcopyright-textvinkas-uiComponentsFreeno deps
Input Copyableinput-copyablevinkas-uiComponentsFree1 dep
Markdown Textmarkdown-textvinkas-uiComponentsFree1 dep
Relative Timerelative-timevinkas-uiComponentsFreeno deps · 2 files
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex