Tracking WP Post Tags using Google Analytics and dataLayer (GTM)

雨燕双飞 提交于 2019-12-25 08:25:14

问题


I set the dataLayer variable with the post author, tags and categories data. All these were already created as custom dimensions on Analytics.

The problem is that Post Tags and Categories are arrays, Do I have to split the arrays on Google Tag Manager? (Or something like that, IDK). I did a test with Post Categories setting up pageCategory[0] as Data Layer Variable Name (Because I need only the first category) but It's not working good.

The dataLayer looks like this:

{
"pagePostType":"post",
"pagePostType2":"single-post",
"pageCategory":["ha-kidd-knitting-supplies"],
"pageAttributes":["big-time-yarn","charles-voth","classic-shades","easy-knits","km066","knitted-cowl","textured-cowl","universal-yarn"],
"pagePostAuthor":"Charles Voth"
}

What is the best way to collect all the wordpress post tags and categories as custom dimensions on Analytics?


回答1:


You need to use dot notation to access the array, so your page cateogry dataLayer variable could have a value like:

pageCategory.0

For your page attributes, they could be accessed individually:

pageAttributes.1
pageAttributes.2

etc.

Of course with multiple page attributes, this wouldn't be the best way. You should instead define your dataLayer variable to have a value of just pageAttributes, and then you can loop through this variable to populate your Custom Dimensions, and then concatenate the strings.



来源:https://stackoverflow.com/questions/39274378/tracking-wp-post-tags-using-google-analytics-and-datalayer-gtm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!