Skip to content

Instantly share code, notes, and snippets.

@dcvogi
Last active December 6, 2017 07:46
Show Gist options
  • Save dcvogi/377875db7c69a7545755871338b19103 to your computer and use it in GitHub Desktop.
Save dcvogi/377875db7c69a7545755871338b19103 to your computer and use it in GitHub Desktop.
Track the Network Information
(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