Introduction
Live Assist for Dynamics 365 has introduced the ability to track Agent Activity to allow you to analyse the usage of the system by your agents. How to access the data and the description of the entity model is given in the article Agent Activity Reporting API.
Here, I will show how you can use this new capability to calculate various statistics by Querying Data using the Dynamics Web API.
Agent Presence Status
To determine the presence status of an agent at any point in time, you can use the Agent Chat Participation entity.
Perform a lookup filtering on the Agent ID and filter on the most recent presence state change before the defined timestamp. The result returned will be the presence state of the agent at that specified time.
Endpoint
- cxlvhlp_agentstatuschanges
Query Parameters
- Agent ID is equal to the Dynamics GUID for the agent in question
- Start Time is less than the provided timestamp
- Order results by timestamp in descending order
- Return the top result
Example
//Get Agent Status before window starts for an agent
cxlvhlp_agentstatuschanges?
$filter=_cxlvhlp_agentid_value eq AGENT_ID
and cxlvhlp_timestamp lt TIMESTAMP
&$orderby=cxlvhlp_timestamp desc
&$top=1
Agent Presence Status Changes
To determine the changes in presence status of an agent over a period of time and calculate how long the agent spent in each state, you can use the Agent Chat Participation entity.
Determine the state the agent was in before the time window using the Agent Presence Status described previously, then lookup all subsequent state changes within the time window. You can then calculate how long the agent spent in each presence state within your window of time.
Endpoint
- cxlvhlp_agentstatuschanges
Query Parameters
- Agent ID is equal to the Dynamics GUID for the agent in question
- Timestamp is between the window start and end time
- Order the results by the status change timestamp
Example
//Get all agent status change events during window for an agent
cxlvhlp_agentstatuschanges?
$filter=_cxlvhlp_agentid_value eq AGENT_ID
and Microsoft.Dynamics.CRM.Between(
PropertyName=”cxlvhlp_timestamp”,
PropertyValues=[WINDOW_START, WINDOW_END])
&$orderby=cxlvhlp_timestamp asc
Agent Chat Count
To determine the number of chats an agent is involved in at any point of time (including now), you can use the Agent Chat Participation entity.
Perform a lookup filtering on the Agent ID, where the start time of the chat was before the timestamp and the end time of the chat was after the timestamp. Don’t forget to also filter for chats that are still in progress and do not yet have the end time set. Using the $count endpoint will return just a count of the number of chats the agent was involved in.
Endpoint
- cxlvhlp_agentchatparticipations/$count
Query Parameters
- Agent ID is equal to the Dynamics GUID for the agent in question
- Start Time is less than the provided timestamp
- End Time is greater than the provided timestamp or not set at all
Example
//Count the number of chats an agent is in at an instant in time
cxlvhlp_agentchatparticipations/$count?
$filter=_cxlvhlp_agentid_value eq AGENT_ID
and cxlvhlp_starttime lt TIME_STAMP
and ((cxlvhlp_endtime gt TIME_STAMP )
or (cxlvhlp_endtime eq null))
Time Spent In Chat
To determine how long an agent spent in at least one chat for a period of time, you can use the Agent Chat Participation entity.
Perform a lookup filtering on the Agent ID, where the start time of the chat was before the end of the time window and the end time of the chat was after the start of the time window. Don’t forget to also filter for chats that are still in progress and do not yet have the end time set.
From the returned values, you can now calculate how long the agent spent chatting.
Endpoint
- cxlvhlp_agentchatparticipations
Query Parameters
- Agent ID is equal to the Dynamics GUID for the agent in question
- Start Time is less than the window end time
- End Time is greater than the window start time or not set at all
Example
//Get all agent participation events during window for an agent
cxlvhlp_agentchatparticipations?
$filter=_cxlvhlp_agentid_value eq AGENT_ID
and cxlvhlp_starttime lt END
and ((cxlvhlp_endtime gt START)
or (cxlvhlp_endtime eq null))
&$orderby=cxlvhlp_starttime asc
Operational Time
Now that we have calculated and retrieved some core data, we can use that data in other ways to calculate some further statistics. For example, we can now determine the Operational Time of an agent window where this is defined as the sum of the Time Spent in Online State and the Time Spent in chat whilst in Away or Back Soon
Data Input
To calculate this, we need the following data that we have retrieved above:
- Agent Status at start of window - see Agent Presence Status
- Agent Status Changes during Window - see Agent Presence Status Changes
- Chat Participations during Window - see Time Spent In Chat above
Calculation
From this data, it is possible to calculate how long an agent spent in the Online state. It is also possible to calculate how long the agent spent in chats whilst in the Away or Back Soon state. Sum the values together to get the final result.
Operational Quotient
Having calculated the Operational Time, we can now calculate the Operational Quotient. This is defined as the ratio of their Operational Time and their total login time.
Data Input
To calculate this, we need the following data that we have retrieved above:
- Operational Time
- Agent Status Changes during Window - see Agent Presence Status Changes
Calculation
From this data, it is possible to calculate how long an agent was logged in for, i.e. the sum of their time spent in Online, Back Soon and Available states. The Operational Quotient can then be calculated as Operational Time / Login Time.
Chat Operational Quotient
A similar statistic called the Chat Operational Quotient can also be determined from the above results. The Chat Operational Quotient is defined as the ratio of an agents Total Chat Duration and the time spent Logged In.
Data Input
To calculate this, we need the following data that we have retrieved or calculated above:
- Time Spent In Chat
- Login Time - see Operational Quotient
Calculation
The data required has already been calculated in the previous statistics so can be reused to calculate Chat Operational Quotient = Total Chat Duration / Logged In Time.