Last active
December 6, 2017 07:46
-
-
Save dcvogi/377875db7c69a7545755871338b19103 to your computer and use it in GitHub Desktop.
Track the Network Information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function trackNetworkInformation(){ | |
// Check if network information is supported | |
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection; | |
if (!connection){ | |
ga('send', 'event', 'browser support features', 'network information', 'network information api is not supported'); | |
return; | |
} | |
var connectionType = connection.hasOwnProperty('type') ? 'type' : 'effectiveType'; | |
ga('send', 'event', 'network information', 'state', connection[connectionType] + ' - ' + connection['downlink']); | |
connection.addEventListener('typechange', function(){ | |
ga('send', 'event', 'network information', 'new state', connection[connectionType] + ' - ' + connection['downlink']); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment