问题
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