mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 13:47:33 +01:00
Move group chat analytics event to server
This commit is contained in:
committed by
Sabe Jones
parent
a30c4379a6
commit
d934d9d759
@@ -23,25 +23,6 @@ export async function postChat (store, payload) {
|
||||
});
|
||||
}
|
||||
|
||||
if (group.privacy === 'public') {
|
||||
Analytics.track({
|
||||
hitType: 'event',
|
||||
eventCategory: 'behavior',
|
||||
eventAction: 'group chat',
|
||||
groupType: group.type,
|
||||
privacy: group.privacy,
|
||||
groupName: group.name,
|
||||
});
|
||||
} else {
|
||||
Analytics.track({
|
||||
hitType: 'event',
|
||||
eventCategory: 'behavior',
|
||||
eventAction: 'group chat',
|
||||
groupType: group.type,
|
||||
privacy: group.privacy,
|
||||
});
|
||||
}
|
||||
|
||||
let response = await axios.post(url, {
|
||||
message: payload.message,
|
||||
});
|
||||
|
||||
@@ -83,6 +83,8 @@ function getBannedWordsFromText (message) {
|
||||
return getMatchesByWordArray(message, bannedWords);
|
||||
}
|
||||
|
||||
|
||||
const mentionRegex = new RegExp('\\B@[-\\w]+', 'g');
|
||||
/**
|
||||
* @api {post} /api/v3/groups/:groupId/chat Post chat message to a group
|
||||
* @apiName PostChat
|
||||
@@ -185,6 +187,28 @@ api.postChat = {
|
||||
|
||||
await Promise.all(toSave);
|
||||
|
||||
let analyticsObject = {
|
||||
uuid: user._id,
|
||||
hitType: 'event',
|
||||
category: 'behavior',
|
||||
groupType: group.type,
|
||||
privacy: group.privacy,
|
||||
headers: req.headers,
|
||||
};
|
||||
|
||||
const mentions = req.body.message.match(mentionRegex);
|
||||
if (mentions) {
|
||||
analyticsObject.mentionsCount = mentions.length;
|
||||
} else {
|
||||
analyticsObject.mentionsCount = 0;
|
||||
}
|
||||
if (group.privacy === 'public') {
|
||||
analyticsObject.groupName = group.name;
|
||||
}
|
||||
|
||||
console.log(analyticsObject);
|
||||
res.analytics.track('group chat', analyticsObject);
|
||||
|
||||
if (chatUpdated) {
|
||||
res.respond(200, {chat: chatRes.chat});
|
||||
} else {
|
||||
|
||||
@@ -269,6 +269,7 @@ let _sendPurchaseDataToGoogle = (data) => {
|
||||
};
|
||||
|
||||
function track (eventType, data) {
|
||||
console.log(eventType, data);
|
||||
return Promise.all([
|
||||
_sendDataToAmplitude(eventType, data),
|
||||
_sendDataToGoogle(eventType, data),
|
||||
|
||||
Reference in New Issue
Block a user