Skip to content
Snippets Groups Projects
Unverified Commit 833a22b4 authored by graywolf336's avatar graywolf336
Browse files

More work on the piwik analytics and callbacks running on the client side for other analtyics

parent c47d7173
No related branches found
No related tags found
No related merge requests found
......@@ -83,40 +83,41 @@ Template.channelSettings.onCreated ->
return true
@saveSetting = =>
room = ChatRoom.findOne @data?.rid
switch @editing.get()
when 'roomName'
room = ChatRoom.findOne @data?.rid
if $('input[name=roomName]').val() is room.name
toastr.success TAPi18n.__ 'Room_name_changed_successfully'
RocketChat.callbacks.run 'roomNameChanged', ChatRoom.findOne(room._id)
else
if @validateRoomName()
Meteor.call 'saveRoomSettings', @data?.rid, 'roomName', @$('input[name=roomName]').val(), (err, result) ->
if err
return handleError(err)
Meteor.call 'saveRoomSettings', room._id, 'roomName', @$('input[name=roomName]').val(), (err, result) ->
return handleError err if err
toastr.success TAPi18n.__ 'Room_name_changed_successfully'
#RocketChat.callbacks.run 'roomNameChanged', ChatRoom.findOne(result.rid)
when 'roomTopic'
if @validateRoomTopic()
Meteor.call 'saveRoomSettings', @data?.rid, 'roomTopic', @$('input[name=roomTopic]').val(), (err, result) ->
if err
return handleError(err)
Meteor.call 'saveRoomSettings', room._id, 'roomTopic', @$('input[name=roomTopic]').val(), (err, result) ->
return handleError err if err
toastr.success TAPi18n.__ 'Room_topic_changed_successfully'
RocketChat.callbacks.run 'roomTopicChanged', ChatRoom.findOne(result.rid)
when 'roomType'
if @validateRoomType()
Meteor.call 'saveRoomSettings', @data?.rid, 'roomType', @$('input[name=roomType]:checked').val(), (err, result) ->
if err
return handleError(err)
Meteor.call 'saveRoomSettings', room._id, 'roomType', @$('input[name=roomType]:checked').val(), (err, result) ->
return handleError err if err
toastr.success TAPi18n.__ 'Room_type_changed_successfully'
#RocketChat.callbacks.run 'roomTypeChanged', ChatRoom.findOne(result.rid)
when 'archivationState'
if @$('input[name=archivationState]:checked').val() is 'true'
if ChatRoom.findOne(@data.rid)?.archived isnt true
Meteor.call 'archiveRoom', @data?.rid, (err, results) ->
if room.archived isnt true
Meteor.call 'archiveRoom', room._id, (err, results) ->
return handleError err if err
toastr.success TAPi18n.__ 'Room_archived'
#TODO: callback channel archived
RocketChat.callbacks.run 'archiveRoom', ChatRoom.findOne(room._id)
else
if ChatRoom.findOne(@data.rid)?.archived is true
Meteor.call 'unarchiveRoom', @data?.rid, (err, results) ->
if room.archived is true
Meteor.call 'unarchiveRoom', room._id, (err, results) ->
return handleError err if err
toastr.success TAPi18n.__ 'Room_unarchived'
#TODO: callback channel unarchived
RocketChat.callbacks.run 'unarchiveRoom', ChatRoom.findOne(room._id)
@editing.set()
......@@ -33,4 +33,4 @@ Meteor.methods
when 'default'
RocketChat.models.Rooms.saveDefaultById rid, value
return true
return { result: true, rid: room._id }
# Piwik Analytics Tracking
Rocket.Chat supports adding Piwik url and site id to track the analytics of your
server. Through this you will be able to see details analytics of per user,
including how many messages a session they send via custom events in Piwik and
how many channels they interact with.
## Piwik & Google Chrome
Google Chrome has a setting which sends a Do Not Track with each request and by
default Piwik respects that and you have to manually disable that feature inside
of Piwik. [Piwik has great documentation on how to disable this feature.](http://piwik.org/docs/privacy/#step-4-respect-donottrack-preference)
## Piwik Settings in Rocket.Chat
Settings -> Piwik
### General
* **URL**: The url where your piwik is located. This is used for generating the tracking code and is required. Recommended format is: `//rocketchat.piwikpro.com/`
* **Client ID**: The client id which this website is. This is a number without any decimals, example: `1`
### Features Enabled
* **Messages**: `true/false` determines whether to use custom events to track how many times a user does something with a message. This ranges from sending messages, editing messages, reacting to messages, pinning, starring, and etc.
* **Rooms**: `true/false` determines whether to use custom events to track how many times a user does actions related to a room (channel, direct message, group). This ranges from creating, leaving, archiving, renaming, and etc.
......@@ -13,12 +13,43 @@ FlowRouter.triggers.enter([function updatePiwik(route) {
//Custom events
RocketChat.callbacks.add('afterSaveMessage', (message) => {
if (window._paq && RocketChat.settings.get('PiwikAnalytics_features_messages')) {
window._paq.push(['trackEvent', 'Message', 'Send', ChatRoom.findOne({ _id: message.rid }).name ]);
let room = ChatRoom.findOne({ _id: message.rid });
window._paq.push(['trackEvent', 'Message', 'Send', room.name + ' (' + room._id + ')' ]);
}
}, 2000);
RocketChat.callbacks.add('afterCreateChannel', (channel) => {
RocketChat.callbacks.add('afterCreateChannel', (room) => {
if (window._paq && RocketChat.settings.get('PiwikAnalytics_features_rooms')) {
window._paq.push(['trackEvent', 'Room', 'Create', channel.name]);
window._paq.push(['trackEvent', 'Room', 'Create', room.name + ' (' + room._id + ')' ]);
}
});
RocketChat.callbacks.add('roomNameChanged', (room) => {
if (window._paq && RocketChat.settings.get('PiwikAnalytics_features_rooms')) {
window._paq.push(['trackEvent', 'Room', 'Changed Name', room.name + ' (' + room._id + ')' ]);
}
});
RocketChat.callbacks.add('roomTopicChanged', (room) => {
if (window._paq && RocketChat.settings.get('PiwikAnalytics_features_rooms')) {
window._paq.push(['trackEvent', 'Room', 'Changed Topic', room.name + ' (' + room._id + ')' ]);
}
});
RocketChat.callbacks.add('roomTypeChanged', (room) => {
if (window._paq && RocketChat.settings.get('PiwikAnalytics_features_rooms')) {
window._paq.push(['trackEvent', 'Room', 'Changed Room Type', room.name + ' (' + room._id + ')' ]);
}
});
RocketChat.callbacks.add('archiveRoom', (room) => {
if (window._paq && RocketChat.settings.get('PiwikAnalytics_features_rooms')) {
window._paq.push(['trackEvent', 'Room', 'Archived', room.name + ' (' + room._id + ')' ]);
}
});
RocketChat.callbacks.add('unarchiveRoom', (room) => {
if (window._paq && RocketChat.settings.get('PiwikAnalytics_features_rooms')) {
window._paq.push(['trackEvent', 'Room', 'Unarchived', room.name + ' (' + room._id + ')' ]);
}
});
......@@ -5,6 +5,8 @@ Package.describe({
git: ''
});
//Note: Piwik respects Google Chrome's No Track: http://piwik.org/docs/privacy/#step-4-respect-donottrack-preference
Package.onUse(function(api) {
api.versionsFrom('1.0');
......
......@@ -10,10 +10,11 @@ Package.onUse(function(api) {
api.versionsFrom('1.0');
api.use([
'rocketchat:lib'
'rocketchat:lib',
'ecmascript'
]);
api.use('ecmascript');
api.use(['rocketchat:authorization'], ['client', 'server']);
api.addFiles('topic.js', ['client', 'server']);
});
......@@ -5,11 +5,15 @@
function Topic(command, params, item) {
if (command === 'topic') {
if (RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', item.rid)) {
if (Meteor.isClient && RocketChat.authz.hasAtLeastOnePermission('edit-room', item.rid) || (Meteor.isServer && RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', item.rid))) {
Meteor.call('saveRoomSettings', item.rid, 'roomTopic', params, (err) => {
if (err) {
return handleError(err);
}
if (Meteor.isClient) {
RocketChat.callbacks.run('roomTopicChanged', ChatRoom.findOne(item.rid));
}
});
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment