in Google Analytics, Google Tag Manager

Track battery level in Google Tag Manager

For analysing data context is very important. How about check how battery level influence for web user behaviour?

To solve this case I’ve prepared modification of  code. This code put battery level in dataLayer and you can track it in every web analytics solution using Google Tag Manager.

Create Custom HTML tag with this code:


Publish your container and that’s it!

Now create new dataLayer variables in GTM to get this values and send i.e. in Google Analytics tracking as custom dimension (session scope):

  • battery_level
  • battery_is_charging
  • battery_time_to_charge
  • battery_time_to_discharge

Check also source code on my Github.