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.
| Contextual.tagString("ProductOffer", "Liked");
|
| 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
}
}
|
| String key = "BidValue";
double numeric_value = 549.99;
Contextual.tagNumeric(key, numeric_value); // double numeric_value
|
| 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
}
}
|
| // Example code using custom tag
String key = "Birthday";
Contextual.tagDatetime(key, OffsetDate.now());
|
| 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
}
}
|
| // Example code using user's current OffsetDateTime
String key = "Birthday";
Contextual.tagDatetime(key);
|
| 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
| String key = "PageVisited";
Contextual.incrementTag(key);
|
| 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
| String key = "RemoveUser";
Contextual.removeTag(key);
|
Last update:
2024-02-15