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.

Machine learning in action

On last MeasureCamp #8 in London I’ve led session about ML:

Machine Learning in action. Advanced users segmentation using Google Analytics, Google Tag Manager and R.


Summary of workflow

  1. Prepare data collection
    1. Google Tag Manager
      1. dataLayer
      2. browser fingerprinting
  2. Data processing and aggregation
    1. Google Analytics
      1. Custom Dimensions
      2. Content Grouping
  3. Advanced data analysis
    1. R + Google Analytics API
    2. Unsupervised Learning – k-Means algorithm

Result – clustered users:




Slides from my session are now available on SlideShare:

R Code

You can find complete example on my GitHub repository


It was pleasure to speak for full room. I hope that this session provide some inspiration to new way of web traffic analysis 🙂