问题描述
I'm following the steps in this resource 使用 GTM 中的自定义 JS 变量在我的 UA 媒体资源的引荐流量中排除/包括子域。
我的目标的简单示例:TLD mysite.com 视图应包括 blog.mysite.com 作为推荐来源,排除 mysite.com 作为推荐来源。 blog.mysite.com 视图应包括 mysite.com 作为引荐来源,并排除 blog.mysite.com 作为引荐来源。
根据上面的文章,我在推荐排除列表中只有“mysite.com”,并使用 JS 来欺骗 GA。以下是我目前为 GTM 中的自定义 JavaScript 变量编写的内容:
function () {
var theReferrer = document.referrer;
if (theReferrer) {
var myProtocol = theReferrer.match(/(https?:\/\/)/);
var myDomain = theReferrer.match(/\/\/mysite\.com(.+)/);
var mySubdomain = theReferrer.match(/\/\/(.+)\.mysite\.com(.+)/);
var myPath = "";
if (mySubdomain) {
if (mySubdomain[2]) myPath = mySubdomain[2];
// exclude referrals from the blog.mysite.com subdomain
if (mySubdomain[1]=="blog") {
return myProtocol[1]+"blog.mysite.com"+myPath;
}
// include referrals from all other subdomains
else {
return myProtocol[1]+mySubdomain[1]+".trickga.com"+myPath;
}
}
// include referrals from the main domain
else if (myDomain) {
if (myDomain[1]) myPath = myDomain[1];
return myProtocol[1]+"trickga.com"+myPath;
}
}
// if the referrer isn't our main domain or subdomain,leave it alone
return document.referrer;
问题: 以上代码仅适用于“blog.mysite.com”。我需要“mysite.com”的不同代码来排除/包含不同的 URL。我的 TLD 和子域在同一个属性中,只是视图不同。
有没有办法在 JavaScript 中区分视图?或者我可以为每个(子)域创建一个 GTM 容器,并使用它们自己的自定义 JS 变量?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)