如何在Google跟踪代码管理器中将两个dataLayer变量合并为一个 [英] How to you combine two dataLayer variables into one in Google Tag Manager
问题描述
页面上有两个dataLayer变量.您如何将它们都组合为一个变量,以便可以将其推入分析?
There are two dataLayer variables on the page. How do you combine both of them into one single variable so that it can be pushed into analytics ?
dataLayer当前格式 网页名称:AIR_SEARCH_PAGE 流:预订
dataLayer current format PageName: AIR_SEARCH_PAGE Flow:BOOKING
我想创建另一个变量XYZ,并将结果显示为BOOKING:AIR_SEARCH_PAGE.如何实现呢? XYZ:BOOKING:AIR_SEARCH_PAGE
I want to create another variable which is XYZ and the result to be displayed as BOOKING:AIR_SEARCH_PAGE. How to achieve this ? XYZ:BOOKING:AIR_SEARCH_PAGE
推荐答案
此处有几个选项:
-
通过GTM组合字符串.例如,看起来您具有以下dataLayer:
Combine the strings through GTM. For example, looks like you have the following dataLayer:
dataLayer = [{
'PageName': 'AIR_SEARCH_PAGE',
'Flow': 'BOOKING'
}]
在GTM中,您可以为'PageName'创建一个DL变量,为'Flow'创建一个DL变量,然后当您需要组合它们或在其周围添加其他文本时,可以说:
In GTM, you could create a DL variable for 'PageName', and another one for 'Flow', and then when you need to combine them, or add other text around it, you can say:
XYZ: {{Flow}}: {{PageName}}
因此它将显示为"XYZ:预订:AIR_SEARCH_PAGE"
so this would render as "XYZ: BOOKING: AIR_SEARCH_PAGE"
使用JS字符串操作并将字符串连接在一起,然后再次推送到dataLayer.
Use the JS string manipulation and join the strings together and then push to the dataLayer again.
将一个新参数推入dataLayer中,该参数将为您组合字符串.
Push a new parameter into the dataLayer that combines the strings for you.
dataLayer.push({
'xyz': 'BOOKING:AIR_SEARCH_PAGE'
})
,然后通过GTM使用该新变量.
and then use that new variable through GTM.
我认为第一种方法可能是最好的.
I think the first method may be best.
这篇关于如何在Google跟踪代码管理器中将两个dataLayer变量合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!