$(document).ready(function() {
const url = document.location.href;
var link = document.querySelector('.tg-button > a');
var href = 'https://ya.ru?';
if(url.match(/utm_source=/)){
href += '&utm_source=' + window.location.search.split('utm_source=')[1].split('&')[0];
}
if(url.match(/utm_medium=/)){
href += '&utm_medium=' + window.location.search.split('utm_medium=')[1].split('&')[0];
}
if(url.match(/utm_campaign=/)){
href += '&utm_campaign=' + window.location.search.split('utm_campaign=')[1].split('&')[0];
}
link.setAttribute('href', href);
});
$(document).ready(function() {
const url = document.location.href;
var link = $('.tg-button > a');
var href = 'https://ya.ru?';
if(url.match(/utm_source=/)){
href += '&utm_source=' + window.location.search.split('utm_source=')[1].split('&')[0];
}
if(url.match(/utm_medium=/)){
href += '&utm_medium=' + window.location.search.split('utm_medium=')[1].split('&')[0];
}
if(url.match(/utm_campaign=/)){
href += '&utm_campaign=' + window.location.search.split('utm_campaign=')[1].split('&')[0];
}
link.attr('href', href);
});
const { searchParams } = new URL(document.location.href);
const url = new URL('https://ya.ru');
['utm_source', 'utm_medium', 'utm_campaign']
.filter(param => searchParams.has(param))
.forEach(param => url.searchParams.set(param, searchParams.get(param)));
const urlString = url.toString();
document.querySelectorAll('div.tg-button > a')
.forEach(el => el.setAttribute('href', urlString));
Получить объект параметр-значение из адреса текущей страницы;