Check the User Agent of the user that triggers a Google Tag Manager event

佐手、 提交于 2020-01-25 08:16:29

问题


I have a datalayer event push in JS and was wondering if it is also possible to learn the User-Agent of the users triggering the event.


回答1:


You need to create variable which will return user agent

1) Go to Variables -> New

2) Name: User Agent

3) Type: Custom JavaScript

4) Code:

function () {return  navigator.userAgent;}

Then you can use this variable in your tags like that {{User Agent}}




回答2:


Even more simply, can't you use a "JavaScript Variable" (instead of a "Custom JavaScript" and then just set navigator.userAgent?




回答3:


Google analytics custom dimension field can be maximum 150 characters and user agent data (when encoded) usually exceed the limit. You need to find a way to shorten the user agent information within a custom js script before sending to GA. You may crop the first 150 character of the user agent information or remove the unnecessary sections or remove the blank characters.



来源:https://stackoverflow.com/questions/45844098/check-the-user-agent-of-the-user-that-triggers-a-google-tag-manager-event

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