function extractHostname(url) {
var hostname;
//find & remove protocol (http, ftp, etc.) and get hostname
if (url.indexOf("//") > -1) {
hostname = url.split('/')[2];
}
else {
hostname = url.split('/')[0];
}
//find & remove port number
hostname = hostname.split(':')[0];
//find & remove "?"
hostname = hostname.split('?')[0];
return hostname;
}
switch(extractHostname(window.location.href)) {
case 'site1.domain.com':
///код для site1
break;
case 'site2.domain.com':
///код для site2
break;
default:
//код, если нет предыдущих совпадений
}
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
var domain_name = window.location.hostname;
let metrics = {};
metrics["domain1.ru"] = 11223344;
metrics["domain2.com"] = 33556677;
metrics["domain3.su"] = 88776655;
ym(metrics[domain_name], "init", {clickmap: true, webvisor: true});