| 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 |
|