sokomir
sokomir

Reputation: 13

How to get the User Agent of a user triggering a GTM event?

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

Upvotes: 1

Views: 7380

Answers (3)

Cagatay Kiyici
Cagatay Kiyici

Reputation: 11

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.

Upvotes: 1

nocabt
nocabt

Reputation: 1131

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

Upvotes: 5

Victor Leontyev
Victor Leontyev

Reputation: 8736

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

Upvotes: 6

Related Questions