Skip to Content

batteryData()

Detect and store the user’s battery data.

JavaScript July 2, 2019

Usage

JavaScript
nebula.batteryData(battery)

Parameters

battery
(Required) (Object) The getBattery() object
Default: None

Parameter Notes

This function is called automatically, so it is not needed to call manually. See below for the object that it updates and the trigger it provides.

Request or provide clarification »

Additional Notes

On battery state changes, this function updates the nebula.user.client.device.battery object and then triggers batteryChange.

Source File

Located in /assets/js/nebula.js on line 572.

JavaScript
nebula.batteryData = function(battery){
    if ( battery ){
        nebula.user.client.device.battery = {
            mode: ( battery.charging )? 'Adapter' : 'Battery',
            charging: ( battery.charging )? true : false,
            chargingTime: battery.chargingTime,
            dischargingTime: battery.dischargingTime,
            level: battery.level,
            percentage: parseFloat((battery.level*100).toFixed(0)) + '%',
        };

        //These definitions will be transported with the Performance Metric event payload
        ga('set', nebula.analytics.dimensions.batteryMode, nebula.user.client.device.battery.mode);
        ga('set', nebula.analytics.dimensions.batteryPercent, nebula.user.client.device.battery.percentage);
        ga('set', nebula.analytics.metrics.batteryLevel, nebula.user.client.device.battery.level);

        nebula.dom.document.trigger('batteryChange');
    }
};

Override

To override or disable this JavaScript function, simply redeclare it with the exact same function name.

JavaScript
nebula.batteryData = function(battery){
    //Write your own code here, leave it blank, or return false.
}