# disco/1.4.22/backend/views/components/Docs/utils/withUtm.js

Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO, version 1.4.22. 30 lines.

- Page: https://pluginprobe.com/plugins/disco/1.4.22/code/backend/views/components/Docs/utils/withUtm.js
- Raw: https://pluginprobe.com/plugins/disco/1.4.22/raw/backend/views/components/Docs/utils/withUtm.js
- Modified: 2026-10-05T06:26:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/disco/1.4.22/code/backend/views/components/Docs/utils/withUtm.js#L10-L20`.

```javascript
/**
 * Add the standard in-plugin UTM parameters to a discoplugin.com link.
 *
 * Used for links that come from the discoplugin.com REST API (docs, blog posts),
 * so they can't carry UTMs in the source like the static links do.
 *
 * @param {string} url      Link to tag.
 * @param {string} campaign Placement inside the plugin (utm_campaign).
 * @param {string} content  Element that was clicked (utm_content).
 * @return {string} Tagged link, or the original value if it isn't a discoplugin.com URL.
 */
const withUtm = (url, campaign, content) => {
	if (!url || !url.includes('discoplugin.com')) {
		return url;
	}

	try {
		const tagged = new URL(url);
		tagged.searchParams.set('utm_source', 'disco-plugin');
		tagged.searchParams.set('utm_medium', 'in-plugin');
		tagged.searchParams.set('utm_campaign', campaign);
		tagged.searchParams.set('utm_content', content);
		return tagged.toString();
	} catch (err) {
		return url;
	}
};

export default withUtm;

```
