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