How to track if the device is a desktop or a laptop

October 03, 2017 - Written by

How can we discover if a user is visualizing our website using a desktop or a laptop device? At present Google Analytics draws a distinction among mobile devices, tablet and desktop. The latter cluster is not split further into the different devices labeled as “desktop”. It can be considered a little bit of an “insane” tracking, but it can be helpful in segmenting users. To retrieve the data from Google Analytics two tags in Google Tag Manager are required: a Custom HTML and a Universal Analytics tag.

Google Tag Manager Tags

Firstly you need to create a Custom HTML Tag which should include the following JavaScript code:

The Tag above should be fired on all pages or on the top landing page, or again on the most viewed page, etc..take your pick!

The script is based on the Battery Status API of the device you are using. If you want to learn more about this feature here you find a good article.

Now let’s create a Data Layer Variable for “type”:

Then we need a tag to collect the information under Google Analytics.

We are going thus to setup an event, a non-interaction event, to be fired when the custom event “isdevice” occurs.

Final Outcomes

Once the container has been published, together with the new tags, under Google Analytics you will start collecting information such as:As you may see, inside the event category “Device” you have the split between desktop and laptop. If needed, we can also set the value as a Session-level Custom Dimension, so that you can compare different users behaviours depending on the device. Data can be helpful in the case of a website redesign, correlating them with screen resolution and browser dimension.

However it has to be said that the distinction between desktop and laptop is never 100% accurate. It considers infact data coming from the device battery status, as you can see below.

We could have false positive when we are using a laptop whose charge level reaches 100%: we are talking about a very limited percentage of sessions, though. To make sure it is a laptop you can simply add a new condition: battery.level != 1. Only desktop devices have indeed a battery level equal to 1.

Comments 4 Replies to “How to track if the device is a desktop or a laptop”

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Analytics Boosters

    Vicolo Buranelli, 2
    31100 Treviso

  • Analytics Boosters
    United Kingdom

    41 Devonshire Street
    W1G 7AJ
    United Kingdom

  • Analytics Boosters
    United States

    80 S.W. 8th Street
    33130 - Miami
    United States of America


Contact us