V
V
Vladimir Kalaganov2019-09-17 18:06:43
JavaScript
Vladimir Kalaganov, 2019-09-17 18:06:43

How to forward UTM-tag from the referrer and put it in the address bar?

Good afternoon, maybe someone has a solution that will help take the utm tag from the referrer and put it in the address bar?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey c0re, 2019-09-17
@Kalaganov5

see:
-> document.referrer
-> document.location
-> javascript working with strings
-> javascript working with arrays
-> javascript parsing url
well, for example, you can do this:

document.location.href += "&" + document.referrer
                                .split("?")[1]
                                .split("#")[0]
                                .split("&")
                                .filter(str => str.indexOf("utm_") > -1)
                                .join("&");

in case the referrer has no parameters, do a check
document.location.href += document.referrer.indexOf("?") > -1 ?
            "&" + document.referrer
            .split("?")[1]
            .split("#")[0]
            .split("&")
            .filter(str => str.indexOf("utm_") > -1)
            .join("&") : "";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question