Answer the question
In order to leave comments, you need to log in
How to get utm tags from url?
You need to get all utm tags from url and pack them into variables.
The result should be:
medium = "x"
source = "y"
campaign = "z"
content = "k"
Url: https://pro-jector.site/?utm_medium=cpc&utm_source...
How can this be done?
Answer the question
In order to leave comments, you need to log in
Object.fromEntries((url.match(/(?<=utm_).+?=[^&]*/g) || []).map(n => n.split('=')))
[...url.matchAll(/utm_([^=]+)=([^&]*)/g)].reduce((acc, [ , k, v ]) => (acc[k] = v, acc), {})
Array
.from(new URL(url).searchParams)
.filter(n => n[0].startsWith('utm_'))
.reduce((acc, n) => ({ ...acc, [n[0].slice(4)]: n[1] }), {})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question