Skip to content
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

Merged
merged 59 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
eb932a8
adding livechat metrics to rooms
pkgodara Jun 5, 2018
f09ad74
design prototype
pkgodara Jun 23, 2018
7b30300
design custom daterange popover
pkgodara Jun 23, 2018
f91824e
resolve conflicts
pkgodara Jun 26, 2018
b7b47c9
resolve conflicts
pkgodara Jun 26, 2018
c788bfa
Merge branch 'develop' into livechat-analytics
pkgodara Jun 26, 2018
3b63557
updated package-lock
pkgodara Jun 26, 2018
8777c0d
Merge branch 'develop' into livechat-analytics
pkgodara Jun 27, 2018
61a3920
reactive analytics view
pkgodara Jul 1, 2018
82dbdd0
using i18n translations
pkgodara Jul 6, 2018
3b38fca
fetching and processing analytics data
pkgodara Jul 10, 2018
eae93a8
move files together to analytics folder
pkgodara Jul 10, 2018
97b3c56
move configurations to lib
pkgodara Jul 10, 2018
97947fb
separate logic to save last message details
pkgodara Jul 10, 2018
39ce22d
Merge branch 'develop' into livechat-analytics
pkgodara Jul 10, 2018
e3b09bd
fix routes
pkgodara Jul 11, 2018
529f543
move chart data functions to lib
pkgodara Jul 11, 2018
b0d3ca7
move overview functions to lib
pkgodara Jul 11, 2018
433b5ba
move overview functions to lib
pkgodara Jul 11, 2018
f569b84
move client-side functions to lib
pkgodara Jul 11, 2018
9c44791
Add single day chart options
pkgodara Jul 11, 2018
71e4d67
Update design
pkgodara Jul 12, 2018
b92bb6b
Update daterange UX
pkgodara Jul 12, 2018
4ad9db3
Update custom daterange UX
pkgodara Jul 12, 2018
56f9c76
Merge branch 'develop' into livechat-analytics
pkgodara Jul 12, 2018
7e6f55a
fix mongo queries date format
pkgodara Jul 12, 2018
7207a52
total msgs chart & responsive overview text
pkgodara Jul 13, 2018
de07653
Merge branch 'develop' into livechat-analytics
pkgodara Jul 16, 2018
0a43128
chart and overview box design
pkgodara Jul 18, 2018
91e3bef
overview design, real data in agent overview
pkgodara Jul 18, 2018
d4d4810
fix scrollbar, decimals, representation
pkgodara Jul 18, 2018
b73ddb4
real-time monitoring
pkgodara Jul 30, 2018
2968549
Merge branch 'develop' into livechat-analytics
pkgodara Jul 30, 2018
b024e66
fix time format, agent ranks, real-time charts
pkgodara Aug 3, 2018
35c3d79
Monitoring overview added, fixed reload issue, translations, bug fixes
pkgodara Aug 6, 2018
30cc972
Fix charts
pkgodara Aug 6, 2018
cfa500d
total visitors count, fix time formats
pkgodara Aug 7, 2018
c06b691
fix date locale
pkgodara Aug 8, 2018
b27839e
Fix agent message counts, added new chart option, using export/imports
pkgodara Aug 12, 2018
30024db
fix names, translations
pkgodara Aug 14, 2018
bbcb319
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
pkgodara Aug 16, 2018
47ecb6a
Merge branch 'develop' into livechat-analytics
pkgodara Aug 17, 2018
4cca087
fix eslint issues
pkgodara Aug 17, 2018
4b178a7
Merge branch 'develop' into livechat-analytics
renatobecker Aug 20, 2018
8465f9b
merge
pkgodara Aug 21, 2018
bb5420a
Merge branch 'livechat-analytics' of https://github.com/pkgodara/Rock…
pkgodara Aug 21, 2018
580f4de
Merge remote-tracking branch 'upstream/develop' into livechat-analytics
pkgodara Aug 21, 2018
01276ce
move message timestamp updates to single method, monitoring subscript…
pkgodara Aug 21, 2018
d05a559
fix code format, readability
pkgodara Aug 22, 2018
8459ab4
fix dept enabled check, code format, readability
pkgodara Aug 22, 2018
be37a29
fix total visitor count, dept chart updates, analytics data hook
pkgodara Aug 22, 2018
e986dfd
fix moment locale
pkgodara Aug 22, 2018
073a5d3
remove moment from server-side
pkgodara Aug 22, 2018
4212b80
fix moment locale, passing ISOStrings
pkgodara Aug 22, 2018
9f6f001
remove meteor from server methods
pkgodara Aug 23, 2018
f5349b8
fix indentation
pkgodara Aug 23, 2018
755645e
Merge branch 'develop' into livechat-analytics
sampaiodiego Sep 20, 2018
32688af
Fix lint
sampaiodiego Sep 20, 2018
0857584
Add permission check to publications
sampaiodiego Sep 20, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,303 changes: 368 additions & 935 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"bunyan": "^1.8.12",
"busboy": "^0.2.14",
"cas": "https://github.com/kcbanner/node-cas/tarball/fcd27dad333223b3b75a048bce27973fb3ca0f62",
"chart.js": "^2.7.2",
"clipboard": "^2.0.1",
"codemirror": "^5.38.0",
"coffeescript": "^1.12.7",
Expand Down
19 changes: 19 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
"Allow_switching_departments": "Allow Visitor to Switch Departments",
"Alphabetical": "Alphabetical",
"Always_open_in_new_window": "Always Open in New Window",
"Analytics": "Analytics",
"Analytics_features_enabled": "Features Enabled",
"Analytics_features_messages_Description": "Tracks custom events related to actions a user does on messages.",
"Analytics_features_rooms_Description": "Tracks custom events related to actions on a channel or group (create, leave, delete).",
Expand Down Expand Up @@ -362,6 +363,8 @@
"Avatar_changed_successfully": "Avatar changed successfully",
"Avatar_URL": "Avatar URL",
"Avatar_url_invalid_or_error": "The url provided is invalid or not accessible. Please try again, but with a different url.",
"Avg_response_time": "Avg Response Time",
"Avg_reaction_time": "Avg Reaction Time",
"away": "away",
"Away": "Away",
"away_female": "away",
Expand Down Expand Up @@ -398,6 +401,8 @@
"bulk-create-c_description": "Permission to create channels in bulk",
"bulk-register-user": "Bulk Create Channels",
"bulk-register-user_description": "Permission to create channels in bulk",
"Busiest_day": "Busiest Day",
"Busiest_time": "Busiest Time",
"busy": "busy",
"Busy": "Busy",
"busy_female": "busy",
Expand Down Expand Up @@ -547,8 +552,10 @@
"Continue": "Continue",
"Continuous_sound_notifications_for_new_livechat_room": "Continuous sound notifications for new livechat room",
"Conversation": "Conversation",
"Conversations": "Conversations",
"Conversation_closed": "Conversation closed: __comment__.",
"Conversation_finished_message": "Conversation Finished Message",
"Conversations_per_day": "Conversations per Day",
"Convert_Ascii_Emojis": "Convert ASCII to Emoji",
"Copied": "Copied",
"Copy": "Copy",
Expand Down Expand Up @@ -817,6 +824,7 @@
"Current_Status": "Current Status",
"Custom": "Custom",
"Custom_agent": "Custom agent",
"Custom_dates": "Custom Dates",
"Custom_Emoji": "Custom Emoji",
"Custom_Emoji_Add": "Add New Emoji",
"Custom_Emoji_Added_Successfully": "Custom emoji added successfully",
Expand Down Expand Up @@ -1164,6 +1172,7 @@
"FileUpload_Webdav_Proxy_Uploads_Description": "Proxy upload file transmissions through your server instead of direct access to the asset's URL",
"Financial_Services": "Financial Services",
"First_Channel_After_Login": "First Channel After Login",
"First_response_time": "First Response Time",
"Flags": "Flags",
"Follow_social_profiles": "Follow our social profiles, fork us on github and share your thoughts about the rocket.chat app on our trello board.",
"Fonts": "Fonts",
Expand Down Expand Up @@ -1885,6 +1894,7 @@
"Oops_page_not_found": "Oops, page not found",
"Open": "Open",
"Open_channel_user_search": "`%s` - Open Channel / User search",
"Open_conversations": "Open Conversations",
"Open_days_of_the_week": "Open Days of the Week",
"Open_Livechats": "Open Livechats",
"Open_your_authentication_app_and_enter_the_code": "Open your authentication app and enter the code. You can also use one of your backup codes.",
Expand Down Expand Up @@ -1974,13 +1984,16 @@
"Preferences_saved": "Preferences saved",
"preview-c-room": "Preview Public Channel",
"preview-c-room_description": "Permission to view the contents of a public channel before joining",
"Previous_month": "Previous Month",
"Previous_week": "Previous Week",
"Privacy": "Privacy",
"Private": "Private",
"Private_Channel": "Private Channel",
"Private_Group": "Private Group",
"Private_Groups": "Private Groups",
"Private_Groups_list": "List of Private Groups",
"Private_Team": "Private Team",
"Productivity": "Productivity",
"Profile": "Profile",
"Profile_details": "Profile Details",
"Profile_picture": "Profile Picture",
Expand Down Expand Up @@ -2024,6 +2037,7 @@
"Read_only_group": "Read Only Group",
"Real_Estate": "Real Estate",
"RealName_Change_Disabled": "Your Rocket.Chat administrator has disabled the changing of names",
"Real_Time_Monitoring": "Real-time Monitoring",
"Reason_To_Join": "Reason to Join",
"Receive_alerts": "Receive alerts",
"Receive_Group_Mentions": "Receive @all and @here mentions",
Expand Down Expand Up @@ -2419,14 +2433,17 @@
"This_email_has_already_been_used_and_has_not_been_verified__Please_change_your_password": "This email has already been used and has not been verified. Please change your password.",
"This_is_a_desktop_notification": "This is a desktop notification",
"This_is_a_push_test_messsage": "This is a push test message",
"This_month": "This Month",
"This_room_has_been_archived_by__username_": "This room has been archived by __username__",
"This_room_has_been_unarchived_by__username_": "This room has been unarchived by __username__",
"This_week": "This Week",
"Thursday": "Thursday",
"Time_in_seconds": "Time in seconds",
"Title": "Title",
"Title_bar_color": "Title bar color",
"Title_bar_color_offline": "Title bar color offline",
"Title_offline": "Title offline",
"To": "To",
"To_additional_emails": "To additional emails",
"To_install_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site": "To install Rocket.Chat Livechat in your website, copy &amp; paste this code above the last <strong>&lt;/body&gt;</strong> tag on your site.",
"to_see_more_details_on_how_to_integrate": "to see more details on how to integrate.",
Expand All @@ -2445,6 +2462,8 @@
"Tokens_Required_Input_Error": "Invalid typed tokens.",
"Tokens_Required_Input_Placeholder": "Tokens asset names",
"Topic": "Topic",
"Total_conversations": "Total Conversations",
"Total_messages": "Total Messages",
"Tourism": "Tourism",
"Transcript_Enabled": "Ask Visitor if They Would Like a Transcript After Chat Closed",
"Transcript_message": "Message to Show When Asking About Transcript",
Expand Down
5 changes: 3 additions & 2 deletions packages/rocketchat-lib/server/lib/notifyUsersOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ function notifyUsersOnMessage(message, room) {
}
}

// Update all the room activity tracker fields
// Update all the room activity tracker fields, including livechat-analytics lm timestamps
// 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);

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


// Update all other subscriptions to alert their owners but witout incrementing
// the unread counter, as it is only for mentions and direct messages
// We now set alert and open properties in two separate update commands. This proved to be more efficient on MongoDB - because it uses a more efficient index.
Expand Down
18 changes: 16 additions & 2 deletions packages/rocketchat-lib/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link

@renatobecker-zz renatobecker-zz Jul 9, 2018

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.

if (inc == null) { inc = 1; }
const query = {_id};
const query = {_id: room._id};

const update = {
$set: {
Expand All @@ -574,6 +574,20 @@ class ModelRooms extends RocketChat.models._Base {
}
};

// livechat analytics : update last message timestamps
if (room.t === 'l') {
const visitorLastMessage = (room.metrics && room.metrics.v) ? room.metrics.v.lq : room.ts;
const agentLastMessage = (room.metrics && room.metrics.servedBy) ? room.metrics.servedBy.lr : room.ts;

if (token) { // update visitor timestamp, only if its new inquiry and not continuing message
if (agentLastMessage >= visitorLastMessage) { // if first query, not continuing query from visitor
update.$set['metrics.v.lq'] = lastMessageTimestamp;
}
} else if (visitorLastMessage > agentLastMessage) { // update agent timestamp, if first response, not continuing
update.$set['metrics.servedBy.lr'] = lastMessageTimestamp;
}
}

if (lastMessage) {
update.$set.lastMessage = lastMessage;
}
Expand Down
Loading