如何访问Google标签管理器中WordPress中创建的自定义分类学?
我在WordPress中为文章长度创建了自定义分类学。它称为“长度”,这些是其中的项目: image
我还创建了一个自定义维度在Google Analytics(索引5)中,并在Google标签管理器中为其创建了一个自定义数据层变量。但是我认为我正在错误地引用数据层变量名称,当我在GTM中预览时,它是“未定义”的。
当我检查页面时,我可以在类末尾看到分类的“长度”,并且是分类的“标准”,但是我无法弄清楚数据层变量名称是什么(我知道我需要使用点表示法) 。
这是我检查时显示的代码。
<article id="post-2784" class="post post-2784 type-post status-publish format-standard has-post-thumbnail hentry category-deforestacion category-gran-chaco length-standard">
...
</article>
如何正确访问GTM的分类法?我敢肯定,仅仅是不正确的,并且花了几个小时进行调试和研究,但无法弄清楚。
I created a custom taxonomy in WordPress for article lengths. It's called 'Length' and these are the items within it: image
I also created a custom dimension in Google Analytics (it's index 5), and created a custom Data Layer variable in Google Tag Manager for it. But I think I am referencing the Data Layer Variable Name incorrectly and it is 'undefined' when I preview it in gtm.
I can see the taxonomy 'length' and it's classification 'standard' at the end of the class when I inspect the page, but I can't figure out what the Data Layer Variable Name is (I know I need to use dot notation).
Here's the code that shows when I inspect.
<article id="post-2784" class="post post-2784 type-post status-publish format-standard has-post-thumbnail hentry category-deforestacion category-gran-chaco length-standard">
...
</article>
How do I access the taxonomy correctly for gtm? I'm pretty sure it's just this that is incorrect and spent hours debugging and researching but can't figure it out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Datalayer是您页面上的全局变量。尝试在文章页面上打开Dev Console,并在其中输入Datalayer。我非常怀疑它的居民,除非您的分类扩展超过90%的扩展名。
您不需要DL。如果要在页面视图上填充自定义维度,只需拥有一个自定义JS代码变量,该变量看起来像这样:
然后只使用它而不是DL变量。它首先使用
.status-publish.post
在页面上的任何内容,并返回具有长度 - 其中的第一类。逻辑假设某些事情。您应该尝试将其调整为页面设计,尤其是在页面上有多个.status-publish.post.post
项目时。dataLayer is a global variable on your pages. Try opening dev console on the article page and type dataLayer in it. I heavily doubt it's populated though unless your the taxonomy extension is better than 90% of extensions out there.
You don't need a DL though. If you want to populate your custom dimension on the page view, just have a custom JS code variable that would look something like this:
And then just use it instead of the DL variable. It takes whatever first has
.status-publish.post
on the page and returns the first class that has length- in it. The logic assumes certain things. You should try and adjust it to your page design, especially if there are multiple.status-publish.post
items on the pages.我没有完全尝试建议的内容,但是对于那些想知道这对我有用的人:
我遇到了一个问题,它也会跟踪主页上的尺寸(由于WordPress主题),所以我将其包裹在一个IF中:
它与我在Google Analytics(分析)和WordPress中的自定义分类法中的自定义维度完美搭配!
I didn't try exactly what was suggested but for those wondering this is what worked for me:
I had an issue where it would track the dimensions on the homepage too (due to the wordpress theme), so I wrapped it in an if:
It works perfectly with my custom dimensions in Google Analytics and my custom taxonomies in Wordpress!