---
title: Track custom variables - Android (classic)
description: Track custom variables with the Contentsquare Android SDK
lastUpdated: 14 April 2026
source_url:
  html: https://docs.contentsquare.com/en/android/track-custom-variables/
  md: https://docs.contentsquare.com/en/android/track-custom-variables/index.md
---

> Documentation index: https://docs.contentsquare.com/llms.txt
> Use this file to discover all available pages before exploring further.

The latest CSQ SDK is here! Learn how to [upgrade your app](https://docs.contentsquare.com/en/csq-sdk-android/experience-analytics/upgrade-from-cs-sdk/).

Custom variables attach additional information about the screen, user, or session to screenview events.

For example, they can include information on the current layout of a screen, like dark or light mode.

## Defining custom variables

To define and send custom variables, follow this:

* Java

  ```java
  CustomVar customVar1 = new CustomVar(1, "CustomVarName1", "CustomVarValue1");
  CustomVar customVar2 = new CustomVar(2, "CustomVarName2", "CustomVarValue2");


  CustomVar[] customVars = new CustomVar[] {customVar1, customVar2};


  Contentsquare.send("ScreenName", customVars);
  ```

  Warning

  For consistent analytics, use the same index/name pair values across your application:

  **Screen A**

  ```java
  CustomVar customVar4 = new CustomVar(4, "hero_banner_type", "carousel");


  CustomVar[] customVars = new CustomVar[] {customVar4};


  Contentsquare.send("ScreenA", customVars);
  ```

  **Screen B**

  ```java
  CustomVar customVar4 = new CustomVar(4, "hero_banner_type", "slider");


  CustomVar[] customVars = new CustomVar[] {customVar4};


  Contentsquare.send("ScreenB", customVars);
  ```

* Kotlin

  ```kotlin
  val customVar1 = CustomVar(1, "CustomVarName1", "CustomVarValue1")
  val customVar2 = CustomVar(2, "CustomVarName2", "CustomVarValue2")


  Contentsquare.send("ScreenName", arrayOf(customVar1, customVar2))
  ```

  Warning

  For consistent analytics, use the same index/name pair values across your application:

  **Screen A**

  ```kotlin
  val customVar4 = CustomVar(4, "hero_banner_type", "carousel")


  Contentsquare.send("ScreenA", arrayOf(customVar4))
  ```

  **Screen A**

  ```kotlin
  val customVar4 = CustomVar(4, "hero_banner_type", "slider")


  Contentsquare.send("ScreenB", arrayOf(customVar4))
  ```

## Limits

### On the server side

* It is possible to save up to 20 distinct custom variables per screenview. If more are received, only the first 20 custom variables, based on their `index` value, will be kept.
* The `index` value of custom variable is used to determine which custom variable to be kept. Only `index` value between 1 and 20 will be taken into account.

### On the SDK side

* Every custom variable is composed of `index`, `name` and `value`.
* If you are using the same `index` twice in a single screen only the first (`name`, `value`) pair associated with the `index` will be kept.
* In case `name` (max. 512 characters) or `value` (max. 255 characters) maximum characters length is reached, the SDK will automatically trim the exceeding characters.
* If `name` or `value` are empty, the SDK will instead send the literal string `"cs-empty"`.
* Use a consistent `index` for a given variable within an application - for instance, if the "screen layout" is collected with an `index` of 3, use the slot 3 for this information on every screen of the application.
