Skip to content

Android User Tagging

You can tag users/devices from your SDK in one line of code.

The SDK looks after the details for the device, you just supply the tag key and value:

  • The tag name (key) is what you want to call it. In the example below "ProductOffer" is how you will see this in the Contextual Dashboard.
  • Contextual supports tags of: string, numeric and datetime. In the example below, the key "ProductOffer" is assigned the value of "Liked" and is stored in the Contextual cloud.

Utilising Kotlin Coroutine Flow, you can observe the value of tags

Prerequisite: - Contextual#init is successful(Tagging should only be used after onInstallRegistered callback)

NB: You can only get tags inside GuideBlocks.

String Tags

1
Contextual.tagString("ProductOffer", "Liked");
1
2
3
4
5
6
7
8
  CoroutineScope(Dispatchers.IO).launch {
            Contextual.tagString("ProductOffer", "Liked").collectLatest {
                val taggedValue = tags?.tagStringValue // Get the tag value
                val createdDate = tags?.createdDate // Get the tag created date time
                val installId = tags?.installId // Get the install ID associated with this tag

            }
        }

Numeric Tags

1
2
3
String key  = "BidValue";
double numeric_value = 549.99;
Contextual.tagNumeric(key, numeric_value);   // double numeric_value
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  val key = "BidValue"
  val numeric_value = 549.99
  CoroutineScope(Dispatchers.IO).launch {
            Contextual.tagString(key, numeric_value).collectLatest {
                val taggedValue = tags?.tagIntegerValue // Get the tag value
                val createdDate = tags?.createdDate // Get the tag created date time
                val installId = tags?.installId // Get the install ID associated with this tag

            }
        }

Datetime Tags

1
2
3
// Example code using custom tag
String key = "Birthday";
Contextual.tagDatetime(key, OffsetDate.now());
1
2
3
4
5
6
7
8
9
  val key = "Birthday"
  CoroutineScope(Dispatchers.IO).launch {
            Contextual.tagDatetime(key, OffsetDate.now()).collectLatest {
                val taggedValue = tags?.tagDateTime // Get the tag value
                val createdDate = tags?.createdDate // Get the tag created date time
                val installId = tags?.installId // Get the install ID associated with this tag

            }
        }
1
2
3
4
// Example code using user's current OffsetDateTime

String key = "Birthday";
Contextual.tagDatetime(key);
1
2
3
4
5
6
7
8
9
  val key = "Birthday"
  CoroutineScope(Dispatchers.IO).launch {
            Contextual.tagDatetime(key).collectLatest {
                val taggedValue = tags?.tagDateTime // Get the tag value
                val createdDate = tags?.createdDate // Get the tag created date time
                val installId = tags?.installId // Get the install ID associated with this tag

            }
        }

Other Tag Operations

Increment Tag Value

1
2
String key = "PageVisited";
Contextual.incrementTag(key);
1
2
3
4
5
6
7
8
9
  val key = "PageVisited"
  CoroutineScope(Dispatchers.IO).launch {
            Contextual.incrementTag(key).collectLatest {
                val taggedValue = tags?.tagIntegerValue // Get the tag value
                val createdDate = tags?.createdDate // Get the tag created date time
                val installId = tags?.installId // Get the install ID associated with this tag

            }
        }

Remove Tag

1
2
String key = "RemoveUser";
Contextual.removeTag(key);

Last update: 2024-02-15