This document provides guidance on how to use JavaScript to capture the network connection type of a client and add it as a custom attribute to a Noibu session. Understanding these network types can offer valuable insights into the conditions under which users are accessing your application.

Capturing Network Information

Connectivity Types

The Network Information API defines the following connectivity types:

JavaScript Code to Capture Connection Type

Here is a sample code snippet to capture this information:

// Function to check for network information and add it as a custom attribute

function addNetworkInfoToNoibu() {

 // Initialize a variable to hold the network type

 let networkType = 'unknown';



  // Check if the Network Information API is supported

 if ('connection' in navigator) {

   const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;

   networkType = connection.effectiveType;



    // Listen for changes in connection

   connection.addEventListener('change', () => {

     networkType = connection.effectiveType;

     NOIBUJS.addCustomAttribute("network_type", networkType);

   });

 }



  // Add the network type as a custom attribute in Noibu

 NOIBUJS.addCustomAttribute("network_type", networkType);

}



// Execute the function to capture network info and add it to Noibu

addNetworkInfoToNoibu();

Usage

  1. Add the addNetworkInfoToNoibu function to your application's JavaScript code.
  2. Execute the function. This will add the network_type as a custom attribute to the current Noibu session and update it if the network type changes.

By following these steps, you can leverage network type information to gain more insights into the user experience across as many browsers as possible.