Operating system attributes in the data layer
Google Tag Manager for WordPress can add the name and version of the operating system your visitor uses into the data layer. Turn on the OS data option in the Browser, OS & device data section of the plugin settings to make these variables available.
This page describes GTM4WP 2.0.0 and newer. Where the legacy 1.x versions of the plugin behaved differently, the older behavior is marked with a bold GTM4WP 1.x: lead-in.
The plugin identifies the operating system with User-Agent Client Hints, which the browser itself provides. Browsers that do not support Client Hints, currently Safari and Firefox, fall back to reading the user agent string, which gives less detail.
Three details are worth knowing before you build tags on these variables:
- The values arrive in a
gtm4wp.deviceDataevent shortly after the page has loaded, not in the initial data layer object. Tags that read these variables need a Custom Event trigger that listens forgtm4wp.deviceData. - A variable that the browser cannot determine is left out of the event instead of being set to an empty string. Check that the variable exists before you use it in a trigger condition.
- The detection happens in the browser, so the values stay correct on pages that are served from a page cache or a CDN.
GTM4WP 1.x: the operating system was identified on the server with the bundled WhichBrowser library, using the headers that the browser sent with the request, and the values were part of the data layer object written into the page. The library is no longer bundled with the plugin.
Please make sure that you do not use this data for unethical purposes. Ask for consent from your visitor if you access or process the data in a way that falls under data protection regulations.
Note: you do not need this feature to collect browser, operating system and device data in Google Analytics, which measures all of that on its own. The feature is useful if you want to pass such data to other 3rd party systems, or to limit certain tags in your Google Tag Manager container so that they fire only on specific operating systems.
The same detection also provides browser attributes and device attributes, each with its own checkbox in the plugin settings. If you turn on more than one of the three options, all of the values are delivered in the same gtm4wp.deviceData event.
With the OS data option turned on, you can access the following data layer variables:
osName
The name of the operating system that your visitor uses to run the browser. Example values are: Windows, macOS, Android, Linux, etc. Where the user agent string is used instead of Client Hints, the plugin recognizes Windows, Android, iOS, macOS and Linux.
osVersion
The version of the operating system that your visitor uses to run the browser. Client Hints treats the operating system version as detailed information that the browser may withhold, so this variable is not always present even when osName is. Check that it exists before you use it in a trigger condition.
On Windows the reported number is not the marketing version of the operating system. Windows 11 reports a major version of 13 or higher, while Windows 10 reports a lower one, so a condition that compares this variable to 10 or 11 does not identify the Windows version.
GTM4WP 1.x: WhichBrowser parsed the version from the request headers on the server, so the variable was always present and it reported the marketing version. Windows 11 read as 11 and Android 13 read as 13. Review any trigger that compares osVersion to a fixed number.
