PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.22
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.22
1.4.22 1.4.21 1.4.20 1.4.19 1.4.18 1.4.17 1.4.16 1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 All 185 releases
disco / backend / views / components / Docs / utils / withUtm.js

withUtm.js in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.22, at backend/views/components/Docs/utils/withUtm.js

30 lines 963 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Add the standard in-plugin UTM parameters to a discoplugin.com link.
3 *
4 * Used for links that come from the discoplugin.com REST API (docs, blog posts),
5 * so they can't carry UTMs in the source like the static links do.
6 *
7 * @param {string} url Link to tag.
8 * @param {string} campaign Placement inside the plugin (utm_campaign).
9 * @param {string} content Element that was clicked (utm_content).
10 * @return {string} Tagged link, or the original value if it isn't a discoplugin.com URL.
11 */
12 const withUtm = (url, campaign, content) => {
13 if (!url || !url.includes('discoplugin.com')) {
14 return url;
15 }
16
17 try {
18 const tagged = new URL(url);
19 tagged.searchParams.set('utm_source', 'disco-plugin');
20 tagged.searchParams.set('utm_medium', 'in-plugin');
21 tagged.searchParams.set('utm_campaign', campaign);
22 tagged.searchParams.set('utm_content', content);
23 return tagged.toString();
24 } catch (err) {
25 return url;
26 }
27 };
28
29 export default withUtm;
30