Skip to content

Setting a unique user identifier

We typically use CLAID for data collection from multiple devices, owned by multiple people (e.g., study participants). In later parts of this tutorial series, you will learn how can upload data from one or multiple devices to a server. To distinguish data from multiple participants, we have to assign an unique user identifier (simply a name or hash) when installing a CLAID App on different participant's devices. This is in particular a requirement for Tutorial 2.4.

Understanding hostnames and user identifiers

In CLAID, we distinguish hosts and users. Both are specified when starting CLAID.

  • hosts: Hosts are devices which run a specific CLAID configuration. Multiple devices can run the same host. A host name (e.g., "Smartphone", "Something", "Watch", ...) determines which modules CLAID loads from the configuration file. The configuration file might contain multiple hosts. During startup, CLAID only loads the relevant section for the configured hostname.
  • users: Are unique identifiers to distinguish users of devices. User identifiers are typically used to distinguish multiple participants in a study. A user can have multiple devices, each running a separate host or the same host.

Check out the picture below for reference:

Image

In a nutshell, a CLAID config is a collection of hosts. When starting CLAID on a certain device, you need to specify a hostname, which tells CLAID which part of the config to load. Check out the config exmaple below:

A basic CLAID configuration file

Individual hostnames corresponds to separate sections in the CLAID configuration file. Each host has his own configuration of Modules. In the example below, we have three hosts called "FirstHost", "SomeOtherHost" and "SmartphoneHost".

{
    "hosts": [
        {
            "hostname": "FirstHost",
            "modules": [...],
        },
        {
            "hostname": "SomeOtherHost",
            "modules": [...],
        },
        {
            "hostname": "SmartphoneHost",
            "modules": [...]
        },
        ...
    ]
}
When starting CLAID, you would then specify the path to the config file and the hostname. CLAID then loads the part of the config relevant to the specified host:
claid.start("path/to/config.json", hostname: "SomeOtherHost", ...);

Specifying the host and user identifier

Host and user identifier are both specified when starting CLAID. Check out the explanations for your target platform below.

Instructions to set the user identifier

Choose the instructions below depending on which platform you target. Mind the tabs.

On Android/WearOS, you typically start CLAID from the MainActivity or the main Application. If you cloned one of our template Apps, typically CLAID is started in the main Application. Find the file from Android Studio:

Image

When starting CLAID, you specifiy multiple options such as the config file, hostname or user id. Here, you can set hostname and user id:

CLAID.startInForeground(this,   
        "assets://CLAIDConfig.json",    // Path to config
/*-->*/ "SomeHost",     // Specify the host name here!
/*-->*/ "user01",       // Specify the user identifier here!
        "some_device",  // Device name (can be anything)
        CLAIDSpecialPermissionsConfig.regularConfig()
);
Note: Setting the hostname or user name works the same way whether you start CLAID in the foreground or background (cf. next Tutorial).

In Flutter Apps, you typically start CLAID during the initialization of the state of your main widget. If you cloned one of our template Apps, typically CLAID is started in the MyHomePage. Find the file from Android Studio:

Image

When starting CLAID, you specifiy multiple options such as the config file, hostname or user id. Here, you can set hostname and user id:

CLAID.startInForeground(
    configFilePath: "assets://flutter_assets/assets/claid_test.json",
    hostId: "SomeHost",     // Host name
    userId: "user01",       // Unique user id
    deviceId: "my_device",  // Device name
    specialPermissionsConfig: CLAIDSpecialPermissionsConfig.regularConfig(),
    claidPackages: []
).then((value) => setState(() {
claidStarted = true;
}));
Note: Setting the hostname or user name works the same way whether you start CLAID in the foreground or background (cf. next Tutorial).

.. coming soon ..