如何解决如何使用 Google Tag Manager 的自定义 Javascript 变量对具有多个 pageAttributes 的帖子进行分类?
我正在尝试使用 Google Tag Manager 的自定义 Javascript 变量以及查找表变量和两个数据层变量(attributesArray 和 categoryArray)在 Google Analytics 中创建一个内容组,该内容组将我们的 wordpress 网站的新闻类别帖子(pageCategory in dataLayer)通过标记(dataLayer 中的 pageAttributes),以便我们可以轻松地在一个地方查看我们的新闻帖子的分析,并确定哪些主题表现最好。每个新闻帖子都有多个主题标签。
当前编写的 Javascript 仅拉入它迭代的第一个 pageCategory,然后停止该函数。这是一个问题,因为大多数新闻帖子都有多个 pageAttributes。我知道这是由于结束 for 循环的 return 语句,但我不知道我可以使用哪些其他语句来继续该函数并将数据发送到查找表变量/内容组。
这是我的功能:
function() {
var categoryArr = {{categoryArray}};
var attributesArr = {{attributesArray}};
var attributeType;
for (i = 0; i < categoryArr.length; i++) {
if (categoryArr[i] == "news") {
for (i = 0; i < attributesArr.length; i++) {
if (attributesArr[i] == "student-story") {
attributeType = "student-story";
return attributeType;
}
if (attributesArr[i] == "civic-engagement") {
attributeType = "civic-engagement";
return attributeType;
}
if (attributesArr[i] == "demographics") {
attributeType = "demographics";
return attributeType;
}
if (attributesArr[i] == "economic-development") {
attributeType = "economic-development";
return attributeType;
}
if (attributesArr[i] == "global-engagement") {
attributeType = "global-engagement";
return attributeType;
}
if (attributesArr[i] == "governance") {
attributeType = "governance";
return attributeType;
}
if (attributesArr[i] == "health-care") {
attributeType = "health-care";
return attributeType;
}
if (attributesArr[i] == "healthy-communities") {
attributeType = "healthy-communities";
return attributeType;
}
if (attributesArr[i] == "housing") {
attributeType = "housing";
return attributeType;
}
if (attributesArr[i] == "nonprofits-philanthropy") {
attributeType = "nonprofits-philanthropy";
return attributeType;
}
if (attributesArr[i] == "public-administration") {
attributeType = "public-administration";
return attributeType;
}
if (attributesArr[i] == "public-policy") {
attributeType = "public-policy";
return attributeType;
}
if (attributesArr[i] == "real-estate") {
attributeType = "real-estate";
return attributeType;
}
if (attributesArr[i] == "security") {
attributeType = "security";
return attributeType;
}
if (attributesArr[i] == "social-innovation") {
attributeType = "social-innovation";
return attributeType;
}
if (attributesArr[i] == "sustainability") {
attributeType = "sustainability";
return attributeType;
}
if (attributesArr[i] == "transportation") {
attributeType = "transportation";
return attributeType;
}
if (attributesArr[i] == "planning-development") {
attributeType = "planning-development";
return attributeType;
}
if (attributesArr[i] == "covid-19") {
attributeType = "covid-19";
return attributeType;
}
if (attributesArr[i] == "price-editorial") {
attributeType = "price-editorial";
return attributeType;
}
if (attributesArr[i] == "op-ed") {
attributeType = "op-ed";
return attributeType;
}
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。