Search code examples
google-analyticsgoogle-tag-manageruser-agent

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.


Solution

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