BeBranded-xyz

payload plugin utm

by BeBranded-xyz
Analytics
v3
v4
^3.92.0
^3.92.0 || >=4.0.0-beta.9 <5 · prerelease
MIT

Overview

Summary generated from the README

Adds a UTM links collection to Payload where editors generate campaign URLs live, copy them, and keep a searchable inventory. The plugin registers via the plugins array and needs Payload 3.92 or newer. It supports source and medium presets, an optional origin allowlist, value normalization, and authenticated CSV export. It does not track clicks or retrieve analytics data.

Features

  • Live UTM URL generation with one-click copy that preserves existing query parameters and fragments
  • Reusable source and medium presets as quick-fill buttons
  • Server-side recalculation of the saved URL so clients cannot forge it
  • Permission-aware CSV export with a configurable row cap and spreadsheet formula protection
  • Optional origin allowlist and value normalization modes: preserve, lowercase or slug
  • Standalone utilities entry point for building UTM URLs and variants outside Payload

Use cases

  • Create consistent campaign links for newsletters and social posts directly next to your content
  • Export saved campaign links to CSV for marketing reporting, scoped by campaign or tenant
  • Manage UTM links per tenant in a multi-tenant Payload site

From the author

Campaign links, live UTM generation, presets and access-controlled CSV exports for Payload CMS 3.

Installation

npm i payload-plugin-utm

1

Stars

0

Forks

2

Open Issues

2 weeks ago

Last Updated

68

Weekly Downloads

v0.1.1

npm Version

307.3 KB

Unpacked Size

0

Dependencies

GitHub stars

1+1 since Nov 1

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20261
Dec 5, 20261
Dec 4, 20261
Dec 3, 20261
Dec 2, 20261
Dec 1, 20261
Nov 30, 20261
Nov 29, 20261
Nov 28, 20261
Nov 27, 20261
Nov 26, 20261
Nov 25, 20261
Nov 24, 20261
Nov 23, 20261
Nov 22, 20261
Nov 21, 20261
Nov 20, 20261
Nov 19, 20261
Nov 18, 20261
Nov 17, 20261
Nov 16, 20261
Nov 15, 20261
Nov 14, 20261
Nov 13, 20261
Nov 12, 20261
Nov 11, 20261
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
Nov 7, 20260
Nov 6, 20260
Nov 5, 20260
Nov 4, 20260
Nov 3, 20260
Nov 2, 20260
Nov 1, 20260
npm weekly downloads

69+69 since Nov 16

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202669
Dec 5, 202652
Dec 4, 202647
Dec 3, 202655
Dec 2, 202675
Dec 1, 202676
Nov 30, 202695
Nov 29, 202690
Nov 28, 2026105
Nov 27, 2026200
Nov 26, 2026249
Nov 25, 2026394
Nov 24, 2026733
Nov 23, 20261,705
Nov 22, 20261,687
Nov 21, 20261,671
Nov 20, 20261,574
Nov 19, 20261,510
Nov 18, 20261,343
Nov 17, 2026991
Nov 16, 20260

Each point is npm's rolling 7-day download count.

Health Score

60/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1443199925-root.svg)](https://payloaddirectory.dev/plugins/1443199925-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1443199925-root"><img src="https://payloaddirectory.dev/badge/1443199925-root.svg" alt="Payload Directory"></a>
Updated Nov 16, 2026Created Nov 2, 2026Published Nov 14, 2026

README

Payload UTM

Create campaign links where your content already lives: in Payload CMS.

Live URL generation, one-click copy, reusable source/medium presets, a searchable campaign inventory and permission-aware CSV exports. No analytics account, redirect service or external API required.

Community plugin · MIT · Payload 3.92+ · React 19 · Node 22+

Install

pnpm add payload-plugin-utm

Also works with npm install or yarn add. A 0.2 beta that adds opt-in page personalization by campaign audience and statistics is available with pnpm add payload-plugin-utm@beta; the default install stays on this stable line.

Add the plugin to your existing Payload configuration:

import { buildConfig } from 'payload'
import { utmPlugin } from 'payload-plugin-utm'

export default buildConfig({
  // Keep your database, auth collection, editor and other app settings.
  plugins: [
    utmPlugin({
      presets: [
        { label: 'Newsletter', source: 'newsletter', medium: 'email' },
        { label: 'Instagram story', source: 'instagram', medium: 'social', content: 'story' },
      ],
    }),
  ],
})

Then run your normal payload generate:importmap, payload generate:types and database migration workflow. Generate migrations in your application: this plugin does not ship database-specific migrations.

Use it

  1. Open Marketing → UTM links.
  2. Enter a name and a complete destination URL.
  3. Fill in source, medium and campaign, or use a preset to fill source/medium.
  4. Copy the URL immediately, then save it in your campaign inventory.
  5. Search by campaign/source/medium, filter by status, or export saved links as CSV.

The three required parameters are utm_source, utm_medium and utm_campaign. Optional fields support utm_id, utm_content and utm_term. Existing non-UTM query parameters and fragments are preserved. Old UTM parameters, including duplicates and mixed-case keys, are replaced.

The server always recalculates the saved URL. API clients cannot substitute a forged generatedUrl; partial updates preserve existing campaign parameters.

Options

OptionDefaultWhat it does
enabledtrueDisable the plugin without changing the app config.
collectionSlug'utm-links'Rename the collection. A conflicting slug throws a startup error.
relatedCollectionsnoneAdd an optional relationship to your content collections. It does not replace the destination URL.
presets[]Quick-fill buttons: { label, source, medium, content? }.
locale'en'English or French text for custom controls. Field labels support both through Payload's admin language.
allowedOriginsunrestrictedOptional exact origin allowlist, e.g. ['https://example.com']. An empty list denies all destinations. No paths, wildcards or trailing slashes.
normalization'preserve'Preserve case, lowercase values, or produce ASCII slugs with 'slug'. Trims outer whitespace in every mode.
csvExportenabled, 1000 rowsfalse disables it. { maxRows: 5000 } sets a cap between 1 and 10000. Oversized exports return HTTP 413 rather than silently truncating.
overridesnoneA function receiving and returning the generated CollectionConfig. Customize access, labels, fields, hooks and endpoints. Change the slug through collectionSlug.

UTM values are case-sensitive in downstream tools. No lowercasing happens by default. Slug normalization removes non-ASCII characters; do not use it for campaigns whose names must retain non-Latin text. Required values that normalize to an empty string fail validation. Parameter values are limited to 512 characters; destination URLs to 8192.

Multi-tenant apps

Install the UTM plugin before Payload's multi-tenant plugin so the latter can add its tenant field, access rules and filters:

import { multiTenantPlugin } from '@payloadcms/plugin-multi-tenant'

plugins: [
  utmPlugin({ relatedCollections: ['pages', 'posts'] }),
  multiTenantPlugin({
    collections: { 'utm-links': {} },
    // Keep your normal tenant configuration.
  }),
]

The plugin itself is tenant-agnostic. There are no hardcoded collection names, tenants, domains or user roles. Include your normal tenant field when creating links through the API. Changing a collection slug or an existing app's normalization policy needs an application migration/data review.

Custom access

All CRUD operations require req.user by default. Supply your own role checks through overrides:

utmPlugin({
  overrides: (collection) => ({
    ...collection,
    access: {
      ...collection.access,
      delete: ({ req }) => Boolean(req.user?.roles?.includes('admin')),
    },
  }),
})

Adapt the example to your generated user type. The CSV endpoint always requires authentication and runs with overrideAccess: false, forwarding the original request. Collection, field and multi-tenant access rules still apply. Application hooks run before the final URL calculation. If you replace core fields or add a beforeChange hook, you are responsible for maintaining the plugin's invariants.

CSV export

Download from the link editor, or request:

GET /api/utm-links/export-csv
GET /api/utm-links/export-csv?where[campaign][equals]=summer-launch
GET /api/utm-links/export-csv?where[tenant][equals]=123

Use your normal authenticated Payload session/API credentials and your app's API prefix. The editor download includes all saved records the current user can read, not just the current document or an implicit list-view selection. Add where filters to scope a campaign or tenant. Exported fields are fixed campaign metadata; internal notes and related document contents are not exported. Fields denied by field-level access appear empty.

CSV uses UTF-8 with a BOM, CRLF line endings and quoted cells. Values that could be interpreted as spreadsheet formulas are prefixed with an apostrophe. Responses are private and not cached. Archiving organizes the inventory: it does not deactivate links that have already been shared.

Utilities without React or Payload

The utilities entry point has no runtime dependencies and can be used in scripts or other frameworks:

import { buildUtmUrl, buildUtmVariants } from 'payload-plugin-utm/utilities'

const base = {
  destination: 'https://example.com/article/?ref=menu#details',
  source: 'instagram',
  medium: 'social',
  campaign: 'summer-launch',
}

buildUtmUrl(base)
// https://example.com/article/?ref=menu&utm_source=instagram&utm_medium=social&utm_campaign=summer-launch#details

buildUtmVariants(base, [
  { content: 'bio' },
  { source: 'newsletter', medium: 'email', content: 'button' },
])

buildUtmUrl returns null for invalid/incomplete input. buildUtmVariants throws with the 1-based index of an invalid variant; it never writes to your database. validateDestination, normalizeUtmValue, utmLinksToCsv and utmParameters are also exported.

Scope and compatibility

This is a link-management plugin, not an attribution platform. It does not record clicks, inject tracking scripts, proxy/shorten URLs, collect visitors, or retrieve GA4 statistics. Direct campaign links work independently of Payload after you copy them. Whether a destination records UTM traffic depends on that site's analytics setup.

Tested with Payload/UI 3.92.0 and React 19.2.6. CI tests the package on Node 22 and 24. A Postgres/Next.js consumer build is also verified during initial release validation; broader database/browser compatibility should be verified in your app before rollout. Use Payload and @payloadcms/ui versions that match each other.

Development

corepack enable
pnpm install --frozen-lockfile
pnpm check
pnpm pack

See CONTRIBUTING.md, SECURITY.md, CHANGELOG.md and ROADMAP.md. PRs improving accessibility, translations, adapters and test coverage are welcome.

Built by BeBranded. Licensed under MIT.

Similar plugins