I have an URL like https://www.some.com/something-else/?utm_source=Google-PageM&utm_medium=Paid&utm_campaign=SEM-Something
. The request was to extract the values of the UTMs (Google-Page, Paid, SEM-Somethig) to send them in a post request. Actually I'm using this Javascript code:
const utmSource = location.href.replaceAll('?', '$').
replaceAll('&', '$').
split('$').filter(utm => utm.includes('utm_source')).
map(utm => utm.split('=')).flat()[1];
For every UTM (utm_source, utm_campaign & utm_medium) but I think that maybe are a better way to do this.
Is there a better way to do it?
Thanks everyone!