-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEW] Livechat Analytics and Reports #11238
[NEW] Livechat Analytics and Reports #11238
Conversation
@@ -56,49 +56,49 @@ const chartConfiguration = { | |||
responsiveAnimationDuration: 0 // animation duration after a resize | |||
}; | |||
|
|||
// analytics all options and their associated chart/overview options | |||
const analyticsAllOptions = [{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you create a library(Object) to handle Livechat Analytics
stuff and moving the specific code to there.
Then, you will have all the logic inside the library and not inside the template. Using this approach you just need to call the methods within the Library and to keep the Livechat stuff organized, you could add your Library into RocketChat.Livechat
, such as RocketChat.Livechat.Analytics
.
@@ -561,9 +561,9 @@ class ModelRooms extends RocketChat.models._Base { | |||
return this.update(query, update); | |||
} | |||
|
|||
incMsgCountAndSetLastMessageById(_id, inc, lastMessageTimestamp, lastMessage) { | |||
incMsgCountAndSetLastMessageById(room, token, inc, lastMessageTimestamp, lastMessage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not wrong, your implementation here is not related to msgCount
and LastMessage
stuff, but is related to room.metrics
informations. Because of this, please create a new method in the model to store these data, reverting the changes inside incMsgCountAndSetLastMessageById
.
In addition: You can use the Rocket.Chat/packages/rocketchat-livechat/server/models/Rooms.js
to add your implementation.
// This method take so long to execute on gient rooms cuz it will trugger the cache rebuild for the releations of that room | ||
RocketChat.models.Rooms.incMsgCountAndSetLastMessageById(message.rid, 1, message.ts, RocketChat.settings.get('Store_Last_Message') && message); | ||
RocketChat.models.Rooms.incMsgCountAndSetLastMessageById(room, message.token, 1, message.ts, RocketChat.settings.get('Store_Last_Message') && message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said below, you don't need to change the method incMsgCountAndSetLastMessageById
to implement your code.
You have created a new file listening afterSaveMessage
callback, why didn't you implement the code there?
https://github.com/RocketChat/Rocket.Chat/pull/11238/files#diff-9943cbbd0d16d3c0c7306a507793042dR1
@@ -0,0 +1,56 @@ | |||
<template name="livechatAnalytics"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of creating a new folder to store the analytics client files?
We already do this to store triggers
client files in Rocket.Chat/packages/rocketchat-livechat/client/views/app/triggers
.
@@ -19,6 +19,22 @@ AccountBox.addRoute({ | |||
pageTemplate: 'livechatCurrentChats' | |||
}, livechatManagerRoutes); | |||
|
|||
AccountBox.addRoute({ | |||
name: 'livechat-analytics', | |||
path: '/livechat-analytics', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the prefix livechat
in path
prop, like this -> path: '/analytics'
.
|
||
AccountBox.addRoute({ | ||
name: 'livechat-real-time-monitoring', | ||
path: '/livechat-real-time-monitoring', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the prefix livechat
in path
prop, like this -> path: '/real-time-monitoring'
.
}; | ||
|
||
// livechat analytics : update last message timestamps | ||
if (room.t === 'l') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems strange checking room.t === 'l'
within Livechat Room model.
You have to check this outside the model, before calling the method.
} | ||
|
||
// check if room is livechat & yet awaiting for response | ||
if (!(typeof room.t !== 'undefined' && room.t === 'l')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, change this to if (room.t !== 'l') {
.
// | ||
data.dataPoints.push(RocketChat.models.Rooms.getTotalConversationsBetweenDate('l', date)); | ||
break; | ||
case 'First_response_time': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, think about moving the switch statement to methods(props) inside RocketChat.Livechat.Analytics
, like
RocketChat.Livechat.Analytics[options.chartOptions.name](options)
..
Centralizing analytics stuff it the Analytics
lib, it will help in tracking issues in the future.
|
||
const data = options.analyticsOptions.analyticsOverviewOptions; // getting data format | ||
|
||
switch (options.analyticsOptions.name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same I wrote here:
https://github.com/RocketChat/Rocket.Chat/pull/11238/files#r201514190
…ion date from client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pkgodara, I left comments in your PR, but there are other cases that I want to share with you.
I have tested the Real-Time Monitoring
dashboard and I suggest you to review how you're processing the data related to Livechat Visitors because I had only one visitor in the collection, but every time I refreshed the page, the TOTAL VISITORS
value was incremented.
Other important thing: You're using moments.js
on the backend side in server methods and server publications, but you don't need to load the moments.js
just to create filters, you can rely on Date
Object, like new Date()
.
added(/* id, fields */) { | ||
updateAgentStatusChart(); | ||
}, | ||
removed(/* id */) {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you declare the event if you did not use it?
}); | ||
|
||
LivechatVisitors.find().observeChanges({ | ||
changed() {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you declare the event if you did not use it?
displayDepartmentChart(true); | ||
updateDepartmentsChart(id); | ||
}, | ||
removed(/* id */) {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you declare the event if you did not use it?
|
||
LivechatVisitors.find().observeChanges({ | ||
changed() {}, | ||
added(/* id, fields */) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, remove the unused comments.
added(/* id, fields */) { | ||
updateVisitorsCount(1); | ||
}, | ||
removed(/* id */) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, remove the unused comments.
api.addFiles('client/collections/LivechatPageVisited.js', 'client'); | ||
api.addFiles('client/collections/LivechatQueueUser.js', 'client'); | ||
api.addFiles('client/collections/LivechatTrigger.js', 'client'); | ||
api.addFiles('client/collections/LivechatInquiry.js', 'client'); | ||
api.addFiles('client/collections/livechatOfficeHour.js', 'client'); | ||
api.addFiles('client/collections/LivechatVisitor.js', 'client'); | ||
|
||
api.addFiles('client/lib/chartHandler.js', 'client'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're using the import
approach, you don't need this declaration here.
api.addFiles('client/collections/LivechatPageVisited.js', 'client'); | ||
api.addFiles('client/collections/LivechatQueueUser.js', 'client'); | ||
api.addFiles('client/collections/LivechatTrigger.js', 'client'); | ||
api.addFiles('client/collections/LivechatInquiry.js', 'client'); | ||
api.addFiles('client/collections/livechatOfficeHour.js', 'client'); | ||
api.addFiles('client/collections/LivechatVisitor.js', 'client'); | ||
|
||
api.addFiles('client/lib/chartHandler.js', 'client'); | ||
api.addFiles('client/lib/dataHandler.js', 'client'); | ||
api.addFiles('client/lib/dateHandler.js', 'client'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is duplicated, but as you've been using the import
approach so you don't need any of them stated here.
let analyticsData; | ||
|
||
// if the message has a token, it was sent by the visitor | ||
if (!message.token) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's improve this code... you can add something like this above the Meteor.defer()
:
if (message.token) {
return message;
}
This change will improve the readability of the rest of the code as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it has to be this way, because even if message.token
is true
, we still call the method saveAnalyticsDataByRoomId
to update message timestamps (since we have merged other method into one).
analyticsData.reactionTime = (now.getTime() - visitorLastQuery) / 1000; | ||
} // ignore, its continuing response | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can improve all of this code.. you just need to create variables instead of props, like this:
let firstReactionDate;
let firstReactionTime;
At the end of the process you can use the shorthand properties like below:
const analyticsData = {
...
firstReactionDate,
firstReactionTime,
...
}
analyticsData.firstResponseDate = now; | ||
analyticsData.firstResponseTime = (now.getTime() - visitorLastQuery) / 1000; | ||
analyticsData.responseTime = (now.getTime() - visitorLastQuery) / 1000; | ||
analyticsData.avgResponseTime = (((room.metrics && room.metrics.response && room.metrics.response.tt) ? room.metrics.response.tt : 0) + analyticsData.responseTime) / (((room.metrics && room.metrics.response && room.metrics.response.total) ? room.metrics.response.total : 0) + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, move cases like this -> room.metrics && room.metrics.response && room.metrics.response.tt
to const
.
You will be able to reuse them and will improve the readability.
return; | ||
} | ||
|
||
const from = moment(options.daterange.from); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still have moment
on server-side. Please, replace this.
return; | ||
} | ||
|
||
const from = moment(options.daterange.from); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still have moment
on server-side. Please, replace this.
return; | ||
} | ||
|
||
const from = moment(options.daterange.from); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still have moment
on server-side. Please, replace this.
Livechat Analytics and Reports project
Info we wish to show:
... and some more planned! Stay tuned.
Dependent on #11733 .
Planned:
Analytics - containing chart
Real-time monitoring - Real-time analytics
@renatobecker