Track custom variables

A newer version of this documentation is available. Switch to the latest version docs.

Custom variables are additional information on the page, the user or the session, sent along with screenviews.

For example, they can include information on the current layout of a screen, like day/night mode.

  • It is possible to save up to 20 distinct custom variable per screenview. If more are received, only the first 20 custom variables, based on their index value, will be kept.
  • The index value of the custom variable is used to determine which custom variables to be kept. Only index value from 1 to 20 (inclusive) will be taken into account.
  • Every custom variable is composed of index, name and value.
  • If you are using the same index twice in the same screen, only the first (name, value) pair associated with the index will be kept.
  • It is possible to save up to 20 custom vars on the same screenview.
  • In case name(max. 512 characters) or value(max. 255 characters) maximum character 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 custom var 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.

To define and send custom variables, follow this example:

import 'package:contentsquare/contentsquare.dart';
final customVar1 = CustomVar(
index: 1,
name: 'customName_1',
value: 'customValue_1',
);
final customVar2 = CustomVar(
index: 2,
name: 'customName_2',
value: 'customValue_2',
);
Contentsquare().send(
'myAwesomeScreenName',
customVars: [customVar1, customVar2],
);