Network Information Tracking

Learn about the network information tracking feature available in the new mobile SDKs.

This guide walks you through the network information tracking feature available in the Kotlin SDK.

Overview

The Kotlin SDK automatically tracks network-related information and attaches it to the event payload. It enriches every outgoing event with network-related metadata like Wi-Fi status, cellular connectivity, Bluetooth status, and carrier name.

Network parameters

RudderStack collects and attaches the following information in the network field of the event payload’s context object:

ParameterDescriptionRequired permissions
carrierName of the mobile network carrier (if available).-
cellularDetermines whether the device is connected to a cellular network.ACCESS_NETWORK_STATE
wifiDetermines whether Wi-fi is enabled.ACCESS_WIFI_STATE or ACCESS_NETWORK_STATE
bluetoothDetermines whether Bluetooth is enabled.BLUETOOTH

Add required permissions

The SDK requires some permissions in the app code to attach the above-mentioned parameters to the event payload.

For Kotlin (Android), the AndroidManifest.xml file is responsible for managing these permissions. You can add these permissions in the manifest file as follows:

<!-- Required -->
<!-- Allows access to the internet for network communication -->
<uses-permission android:name="android.permission.INTERNET"/>

<!-- Optional --> 
<!-- Allows access to track both WiFi and Cellular state -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Optional --> 
<!-- Grants access only to track WiFi state if the above permission is not used -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

<!-- Optional -->
<!-- Required for Bluetooth functionality - allows access to track Bluetooth state -->
<uses-permission android:name="android.permission.BLUETOOTH"/>

Note that:

  • The permissions marked as Optional in the above snippet are attached to the event payload only if the SDK is able to determine them based on the available permissions and the device running the app.
  • The SDK updates the cellular, wifi and bluetooth values dynamically for each event payload, that is, they represent the real-time status of these parameters at the time the event is triggered.

A sample JSON payload with the network field populated is shown below:

{
  //...
  "context": {
    "network": {
      "carrier": "CarrierName",
      "cellular": true,
      "wifi": false,
      "bluetooth": true
    }
  }
  //...
}

Questions? Contact us by email or on Slack