Answer the question
In order to leave comments, you need to log in
Metric counter output from domain view?
How to write a js condition to display counters depending on the subdomain address? The site is implemented through multisite
Example:
if www=mysite.ru {
Yandex-counter
}
if www=site1.mysite{
Yandex-counter1
}
if www=site2.mysite{
Yandex-counter2
}
Answer the question
In order to leave comments, you need to log in
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});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question