---
title: Track dynamic variables - iOS (classic)
description: Track dynamic variables with the Contentsquare iOS SDK
lastUpdated: 14 April 2026
source_url:
  html: https://docs.contentsquare.com/en/ios/track-dynamic-variables/
  md: https://docs.contentsquare.com/en/ios/track-dynamic-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-ios/experience-analytics/upgrade-from-cs-sdk/).

Dynamic variables are additional information on the session that can be used to segment sessions.

For example, they can include information on the A/B Test variations displayed to the current user.

Warning

**Note about Privacy Manifest:** If you decide to use Dynamic Variables to collect new data or use already collected data but for a different purpose, it is up to you to update the privacy practices described in your app manifest accordingly. Here are some common examples of data collected via dynamic variables: Contact info, Financial info, Location (country...), etc. See [Purpose of processing and categories of personal data collected](https://docs.contentsquare.com/en/ios/privacy/#purpose-of-processing-and-categories-of-personal-data-collected) already described in the Contentsquare iOS SDK Privacy Manifest.

## Defining dynamic variables

To define and send a dynamic variable, you just need to use the following API:

* Swift

  ```swift
  // string value
  Contentsquare.send(dynamicVar: DynamicVar(key: String, value: String))


  // int value
  Contentsquare.send(dynamicVar: DynamicVar(key: String, value: UInt32))
  ```

* Objective-C

  ```objective-c
  // string value
  DynamicVar *dynamicVarString = [[DynamicVar alloc] initWithKey:(NSString * _Nonnull)
                                                    stringValue:(NSString * _Nonnull)
                                                    error:(NSError * _Nullable __autoreleasing * _Nullable)];
  [Contentsquare sendWithDynamicVar:dynamicVarString];


  // int value
  DynamicVar *dynamicVarInt = [[DynamicVar alloc] initWithKey:(NSString * _Nonnull)
                                                  intValue:(uint32_t)
                                                  error:(NSError * _Nullable __autoreleasing * _Nullable)];
  [Contentsquare sendWithDynamicVar: dynamicVarInt];
  ```

To define and send a dynamic variable, directly use the key and String/UInt32 value:

**Type of the value** — The value can be either a **whole number** or a **string**. For each case, available features won't be the same in the Contentsquare app:

* For **whole numbers**, you will be able to do some algebra. Example: *sessions with dynamic variable key = "numberOfFriends" and value >= 10*
* For **strings**, auto-completion and Regular Expression will be available. Example: *sessions with dynamic variable key = "accountType" and value = "Premium"*

## Sending a dynamic variable for each session

You may want to send a dynamic variable for each session (like the user's country or store). While **triggering the dynamic variable at app launch will cover most cases, it will not be enough**. A session can start when the app is put in foreground, after staying in background for more than 30 minutes. See [Session definition](https://docs.contentsquare.com/en/ios/how-the-sdk-works/#session-definition) section for more information.

That is why we also recommend **sending such dynamic variable every time the app enters foreground**.

You can use [`didBecomeActiveNotification` notification ↗](https://developer.apple.com/documentation/uikit/uiapplication/1622953-didbecomeactivenotification) and [`sceneDidBecomeActive(_:)` callback ↗](https://developer.apple.com/documentation/uikit/uiscenedelegate/3197915-scenedidbecomeactive) to detect foreground and trigger a dynamic variable.

## Limits

### On the server side

* It is possible to save up to 40 distinct dynamic variable keys per screenview. If more are received, only the first 40 keys will be kept.
* If you are using the same key twice on the same screenview, the last value associated with the key will be collected.

### On the SDK side

* Every dynamic variable is composed of a pair of key (max. 512 characters) and value (max. 255 characters string or number of type `UInt32` between 0 and 232 - 1). In case these maximums length are reached, the SDK will automatically trim the exceeding characters.
* If key or value are empty, the SDK will instead send the literal string "cs-empty".
