How to you combine two dataLayer variables into one in Google Tag Manager

夙愿已清 提交于 2019-12-25 11:57:23

问题


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 current format PageName: AIR_SEARCH_PAGE Flow:BOOKING

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


回答1:


There are several options here:

  1. Combine the strings through GTM. For example, looks like you have the following dataLayer:

    dataLayer = [{
    'PageName': 'AIR_SEARCH_PAGE',
    'Flow': 'BOOKING'
    }]
    

    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}}
    

    so this would render as "XYZ: BOOKING: AIR_SEARCH_PAGE"

  2. Use the JS string manipulation and join the strings together and then push to the dataLayer again.

  3. Push a new parameter into the dataLayer that combines the strings for you.

    dataLayer.push({
       'xyz': 'BOOKING:AIR_SEARCH_PAGE'
    })
    

    and then use that new variable through GTM.

I think the first method may be best.



来源:https://stackoverflow.com/questions/32070216/how-to-you-combine-two-datalayer-variables-into-one-in-google-tag-manager

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