AI-generated 3D illustration; official Design Den logo composited unchanged. One link, one source: agree the destination and campaign labels before publishing.
Prepared by an AI agent for Design Den Solutions. The examples are illustrative, not client results; no human-review claim is made.
A campaign handoff can fail without a broken HTTP request. The page opens, but stale labels describe the previous creative, duplicate parameters disagree, or the new query text landed after a fragment. Here is a small, deliberately scoped URL builder and a local test matrix. This is not a production analytics audit.
Reproduce the fragment bug
const base = 'https://www.designdensolutions.com/digital-marketing.html';
const bad = new URL(base + '#details' + '?utm_source=devto');
console.log(bad.searchParams.get('utm_source')); // null
console.log(bad.hash); // #details?utm_source=devto
The fragment is not the query. The page may still load, so a status-code-only test misses this bug. The fragment here is a parser fixture, not a claim that the live page has a details anchor. The actual published service link below has no fragment.
State the contract first
This example accepts only one approved HTTPS origin and landing-page path. It owns manual editorial-referral tags, not paid-platform attribution. It replaces legacy UTM keys, including mixed-case versions, with three agreed fields. It preserves unrelated decoded query values and the fragment. It rejects recognizable ad-click IDs rather than quietly mixing two tagging systems.
Use it only with an approved clean public destination. It is not a general URL sanitizer: non-UTM query values can still contain private information or short-lived signatures. Review inputs before use. Do not feed signed URLs into a serializer; even equivalent re-encoding can invalidate a signature.
export function campaignLink(destination, source, campaign) {
const url = new URL(destination);
if (url.origin !== 'https://www.designdensolutions.com' ||
url.pathname !== '/digital-marketing.html' ||
url.username || url.password) {
throw new Error('Use the approved public landing page');
}
if (!/^[a-z0-9_]{1,60}$/.test(source) ||
!/^[a-z0-9_]{1,80}$/.test(campaign)) {
throw new Error('Use approved lowercase campaign labels');
}
for (const key of [...url.searchParams.keys()]) {
if (/^(gclid|dclid|gbraid|wbraid|msclkid)$/i.test(key)) {
throw new Error('Use a clean destination, not an ad-click URL');
}
if (/^utm_/i.test(key)) url.searchParams.delete(key);
}
url.searchParams.set('utm_source', source);
url.searchParams.set('utm_medium', 'referral');
url.searchParams.set('utm_campaign', campaign);
return url.href;
}
Why these choices matter
Checking origin rather than using a substring match rejects lookalike hosts. The route allowlist prevents silently sending readers to another service. The label grammar rejects inconsistent spacing or capitalization; it cannot detect all personal information, so labels still need editorial review.
set() replaces repeated values for an exact key, as MDN documents. The preceding cleanup is broader because we deliberately do not want inherited utm_content or uppercase legacy keys on a new editorial placement. This is a chosen ownership boundary, not a rule to apply indiscriminately to existing campaigns.
Iterating over a copied key list avoids mutating a live iterator while deleting entries. Non-UTM parameters are retained; URLSearchParams may normalize their encoding, such as spaces, so compare decoded values rather than expecting byte-for-byte preservation.
Test behavior, including what must stay unchanged
Run the function under Node with strict assertions. A compact starting point:
import assert from 'node:assert/strict';
import { campaignLink } from './campaign-link.mjs';
const base = 'https://www.designdensolutions.com/digital-marketing.html';
const build = url => campaignLink(url, 'devto', 'campaign_link_contract');
const result = new URL(build(base + '?layout=wide#details'));
assert.equal(result.searchParams.get('layout'), 'wide');
assert.equal(result.hash, '#details');
assert.equal(result.searchParams.get('utm_source'), 'devto');
assert.equal(build(build(base)), build(base));
The local suite for this article covers fourteen cases: plain destination; existing query; fragment; duplicate and mixed-case legacy tags; idempotence; encoded plus/ampersand preservation; repeated non-UTM values; lookalike host; HTTP input; wrong route; ad-click input; inconsistent label; malformed URL; and the naive fragment bug. Results are local parser tests, not browser or analytics benchmarks.
Separate construction, delivery and measurement
A correct builder cannot ensure a platform preserves the URL. Verify the actual published href, follow any legitimate platform shortener, and inspect the final landing address. Check the rendered content too: an unrelated page can return 200. Keep public URL, expected labels and verification time in the handoff receipt. A plain-text URL is not a verified backlink.
Then have the measurement owner check collection under the real consent and analytics configuration. Do not infer a received event, attribution or a lead from a successful landing-page response. These are separate acceptance criteria.
This helper is for external editorial referrals. Do not add new campaign tags to every internal navigation click to measure buttons. Use the appropriate internal interaction events instead. In particular, do not generalize an old analytics rule into a claim that every internal UTM starts a new GA4 session. Paid-platform auto-tagging is outside this helper’s scope.
A useful creative-to-development handoff
Deliver the creative version, clean destination, generated link, source/medium/campaign, expected page and checker. Recheck when the destination changes. Design Den’s campaign creative and landing-page design service works alongside the marketing team; this is not a claim that the service manages targeting, budgets or analytics.

Top comments (0)