You can add
your own contextual data when you report a tagged event to Aternity, for use in the activity signature's internal logic. The
setContextValue
API adds a key
value pair to the AternityContext
object which you created earlier when you tagged an event.
For example, if you tagged the
start of a file download, you can use
setContextValue
to add contextual data of
the file size to be downloaded, so that the signature only
starts the activity if the downloaded file is less than 1GB.
Alternatively, if you are reporting an error tag, you can use
the contextuals to send the error message or error code.
Send contextual data when you report a tagged event
This fits into the wider picture of monitoring a custom activity as follows:
-
Tag a custom event to create an
AternityContext
object.
-
(Optional) Add a key and value as contextual data to the
AternityContext
object using
setContextValue
. You can assign any
number of key-value pairs, where the key and its value are
defined as strings.
-
Report the AternityContext
object
containing the tagged event and its contextual data
using reportTag
.
You can also use
getContextValue
to retrieve a key's
value, and removeContextForKey
to delete a
key and its value.
Before You Begin
Before you begin, ensure you have already done the following:
Method Definition
The
setContextValue
API adds a key
value pair to the AternityContext
object which you created earlier when you tagged an event.
You can assign any
number of key-value pairs, where the key and its value are
defined as strings.
You can also use
getContextValue
to retrieve a key's
value, and removeContextForKey
to delete a
key and its value.
public void setContextValue(java.lang.String key,
java.lang.String value)
public void removeContextForKey(java.lang.String key)
public java.lang.String getContextValue(java.lang.String key)
Example
//Create an AternityContext object called "dl_start" which tags the start of "Download" activity
AternityContext download_start =
Aternity.getInstance().tagApplication("Download", Aternity.Phase.Start);
//You can also set some values in the context object before reporting it to the server
download_start.setContextValue("Filename", "photo.jpg");
download_start.setContextValue("server", "192.168.111.30");
//Report the start of the activity with reportTag, referring to the AternityContext object with its tag and contextuals
download_start.reportTag();