To create a UTM parameter in JavaScript, you can use the encodeURIComponent()
function to safely encode the parameter values.
Here is an example function that takes UTM parameter values as arguments and adds them to the current URL as a query string:
index.tsx585 chars18 lines
To use this function, simply call it with your desired UTM parameter values:
index.tsx53 chars2 lines
This will add the following query string to the current URL:
index.tsx66 chars2 lines
This UTM parameter can be used for marketing tracking and analytics purposes.
gistlibby LogSnag