如何使用 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...