DEV Community

Cover image for UTM links for directory submissions: a 40-line Node.js script (and why utm_medium=directory lands in Unassigned)
Ed Grows
Ed Grows

Posted on

UTM links for directory submissions: a 40-line Node.js script (and why utm_medium=directory lands in Unassigned)

To track which startup directories send you visitors, give every submission its own UTM-tagged URL: utm_source set to the directory, utm_medium=referral, and one utm_campaign for the whole launch. Use referral, not something like directory, because GA4 only puts a medium it recognises into a channel. The script below builds the links, checks your description lengths and writes a CSV to track each listing.

TL;DR: lowercase values, utm_medium=referral, one campaign name, one row per directory. Keep the clean URL too, because some forms reject query strings.

Why tag directory links at all?

Short answer: without tags, directory visits blur into "referral from some domain" or "direct", and you cannot compare launch channels.

Some directories add rel="noreferrer" to outbound links, which hides where the visit came from. A UTM tag travels with the URL itself, so the visit is attributed to the source you named even when the referrer is missing.

Which utm_medium should you use for directories?

Short answer: referral.

GA4's default channel group decides the channel from source and medium. Its Referral channel matches when the medium is one of referral, app or link (GA4 default channel group). A made-up medium such as directory or listing matches no rule, so those sessions end up in Unassigned, the bucket GA4 uses when nothing else fits.

utm_medium GA4 default channel
referral Referral
link Referral
directory Unassigned
launch Unassigned

If you want a custom label, use a custom channel group in GA4 instead of inventing a medium.

What else does GA4 expect from UTM values?

Short answer: consistent, lowercase values.

Google's URL builder help page says parameter values are case sensitive, so utm_source=google and utm_source=Google are two different sources (Collect campaign data with custom URLs). It recommends a strict naming convention with lowercase as the standard. The script below lowercases the source for you.

The script

No dependencies. It reads a product.json, prints the tagged links, warns about copy that is too long or missing, and writes submissions.csv.

// kit.mjs: build a directory submission kit (UTM links + length-checked copy)
import fs from 'node:fs';

const product = JSON.parse(fs.readFileSync(process.argv[2] ?? 'product.json', 'utf8'));
const LIMITS = { tagline: 60, short: 160, medium: 300 };

function slug(host) {
  return host.replace(/^www\./, '').split('.')[0].toLowerCase().replace(/[^a-z0-9]+/g, '-');
}

function utmUrl(base, directoryUrl) {
  const host = new URL(directoryUrl).hostname;
  const url = new URL(base);
  url.searchParams.set('utm_source', slug(host));
  url.searchParams.set('utm_medium', 'referral');
  url.searchParams.set('utm_campaign', product.campaign);
  return url.toString();
}

const problems = [];
for (const [field, max] of Object.entries(LIMITS)) {
  const text = product.copy[field] ?? '';
  if (!text) problems.push(`${field}: missing`);
  else if (text.length > max) problems.push(`${field}: ${text.length} chars, limit ${max}`);
}

const rows = product.directories.map((dir) => ({
  directory: new URL(dir).hostname,
  url: utmUrl(product.url, dir),
  clean: product.url,
}));

console.log('Copy check:', problems.length ? problems.join('; ') : 'all lengths OK');
console.table(rows.map(({ directory, url }) => ({ directory, url })));

const csv = ['directory,url_with_utm,url_clean,submitted_on,listing_url,rel',
  ...rows.map((r) => `${r.directory},${r.url},${r.clean},,,`)].join('\n');
fs.writeFileSync('submissions.csv', csv + '\n');
console.log(`Wrote submissions.csv (${rows.length} rows)`);
Enter fullscreen mode Exit fullscreen mode

It uses the built-in URL and URLSearchParams APIs, so existing query parameters on your URL are kept and values are encoded correctly.

The input file

{
  "url": "https://yourproduct.com/",
  "campaign": "launch-2026-12",
  "copy": {
    "tagline": "Turn customer calls into clean CRM notes",
    "short": "Records sales calls, writes the summary and pushes action items to your CRM. Built for small sales teams that hate admin work.",
    "medium": ""
  },
  "directories": [
    "https://www.saashub.com/submit",
    "https://alternativeto.net/manage/new/",
    "https://www.futuretools.io/submit-a-tool"
  ]
}
Enter fullscreen mode Exit fullscreen mode

The limits (60, 160 and 300 characters) match the field sizes we ran into most often on directory forms. Change them if a site asks for something else.

What the output looks like

Running node kit.mjs product.json on the file above prints:

Copy check: medium: missing
directory            url
www.saashub.com      https://yourproduct.com/?utm_source=saashub&utm_medium=referral&utm_campaign=launch-2026-12
alternativeto.net    https://yourproduct.com/?utm_source=alternativeto&utm_medium=referral&utm_campaign=launch-2026-12
www.futuretools.io   https://yourproduct.com/?utm_source=futuretools&utm_medium=referral&utm_campaign=launch-2026-12
Wrote submissions.csv (3 rows)
Enter fullscreen mode Exit fullscreen mode

(console.table draws a box around this; trimmed here.) The missing medium text is caught before you open the first form, which is the point.

How to use the CSV during a launch

  1. Paste url_with_utm into each directory's website field.
  2. If the form rejects it, use url_clean. Some forms validate the URL strictly and refuse query strings.
  3. Fill submitted_on the day you send the form.
  4. When the listing goes live, add listing_url and the rel you see on the link.
  5. After a few weeks, filter GA4 by utm_campaign and compare sessions per source.

If you would rather not run a script, the free UTM builder on website.show makes the same kind of link in the browser.

Common mistakes

  • Inventing a medium. directory, listing or launch go to Unassigned. Use referral.
  • Mixed case. SaaSHub and saashub become two sources.
  • A new campaign name per directory. The directory belongs in utm_source; keep one campaign for the launch.
  • Tagging internal links. UTM tags on links inside your own site overwrite the real source of the visit.
  • Forgetting the clean URL. Keep it next to the tagged one so a strict form does not stop you.

FAQ

Do UTM parameters hurt SEO?
Search engines usually treat the tagged URL as a duplicate of the clean one. A canonical tag on your page that points to the clean URL keeps it tidy.

Should utm_source be the directory's full domain?
A short, lowercase name is easier to read in reports. The script uses the first part of the hostname, for example saashub.

Can I use utm_medium=link instead of referral?
Yes. GA4 maps both to the Referral channel. Pick one and use it everywhere.

What if a directory strips my query string?
Then the visit shows up as a normal referral from that domain, or as direct if the referrer is hidden. The CSV still tells you where you are listed.

Top comments (1)

Collapse
 
remycalder profile image
Remy Calder •

nice, the referral vs directory bit is the one people get wrong the most.

two small things worth watching with this setup.

the slug only keeps the first part of the hostname, so anything on a subdomain or a shared host collapses. app.someplace.com becomes "app", and if you submit to a few awesome-lists on github they all end up as utm_source=github. you could keep the short slug as the source and put the full host or path in utm_content, so you can still tell them apart later.

tagged URLs also travel. someone lands from saashub, copies the address bar into a slack chat or a reddit thread, and those visits get credited to saashub too. what a lot of people do is strip the utm params with history.replaceState after the analytics page_view has gone out, so a copied link is clean.

(disclosure: drafted with AI help. I'm building something for makers who launch in a lot of places, so this stuff is on my mind)