Merge branch 'feature/4795_feature_tracking_matomo' into 'develop'

Feature/4795 feature tracking matomo

See merge request bwmessenger/bundesmessenger/bundesmessenger-ios!150
This commit is contained in:
Frank Rotermund
2023-06-21 06:24:46 +00:00
7 changed files with 155 additions and 34 deletions
+1
View File
@@ -36,6 +36,7 @@
@class VoiceBroadcastService;
@class ComposerLinkActionBridgePresenter;
@class PerformanceProfile;
@class BWIAnalyticsHelper;
NS_ASSUME_NONNULL_BEGIN
+13 -5
View File
@@ -8179,6 +8179,7 @@ static CGSize kThreadListBarButtonItemImageSize;
{
[self.roomDataSource sendVoiceMessage:url additionalContentParams:nil mimeType:nil duration:duration samples:samples success:^(NSString *eventId) {
MXLogDebug(@"Success with event id %@", eventId);
[self trackVoiceMessage: duration];
completion(YES);
} failure:^(NSError *error) {
MXLogError(@"Failed sending voice message");
@@ -8210,17 +8211,24 @@ static CGSize kThreadListBarButtonItemImageSize;
if( [profile isLogable] ) {
[self.roomDataSource.room members:^(MXRoomMembers *roomMembers) {
NSUInteger noOfUsers = roomMembers.joinedMembers.count;
NSUInteger noOfDevices = 0;
for (MXRoomMember* member in roomMembers.joinedMembers) {
noOfDevices += [self.mainSession.crypto devicesForUser:member.userId].count;
}
[profile log2AnalyticsWithUsers:noOfUsers devices:noOfDevices];
[BWIAnalyticsHelper getRoomDeviceCountWithRoom:self.roomDataSource.room completion:^(NSInteger deviceCount) {
[profile log2AnalyticsWithUsers:noOfUsers devices:deviceCount];
}];
} failure:^(NSError *error) {
}];
}
}
// Bwi #4795: voice message
- (void) trackVoiceMessage:(NSInteger)duration {
[BWIAnalyticsHelper getRoomDeviceCountWithRoom:self.roomDataSource.room completion:^(NSInteger deviceCount) {
NSString *deviceCountString = [BWIAnalyticsHelper dimensionForDeviceCount: deviceCount];
NSNumber *durationInSeconds = [NSNumber numberWithInteger:(duration / 1000)];
[BWIAnalytics.sharedTracker trackEventWithDimensionWithCategory:@"Feature" action:@"SendVoiceMessage" dimension:deviceCountString value:durationInSeconds name:nil];
}];
}
#pragma mark - BWI Emoji History
- (void) bwiAddedEmoji:(NSString*)emoji {
@@ -53,10 +53,10 @@ class ForwardingShareItemSender: NSObject, ShareItemSenderProtocol {
var localEcho: MXEvent?
room.sendMessage(withContent: event.content, threadId: nil, localEcho: &localEcho) { result in
switch result {
case .success(_):
self.trackForwardMessage(room: room)
case .failure(let innerError):
errors.append(innerError)
default:
break
}
dispatchGroup.leave()
@@ -72,4 +72,12 @@ class ForwardingShareItemSender: NSObject, ShareItemSenderProtocol {
success()
}
}
func trackForwardMessage(room: MXRoom) {
BWIAnalyticsHelper.getRoomDeviceCount(room: room) { deviceCount in
let deviceCountString = BWIAnalyticsHelper.dimensionForDeviceCount(deviceCount)
let messageType = BWIAnalyticsHelper.getForwardingType(event: self.event)
BWIAnalytics.sharedTracker.trackEventWithDimension(category: "Feature", action: "ForwardMessage", dimension: deviceCountString, value: nil, name: messageType)
}
}
}
@@ -79,6 +79,7 @@ final class PollEditFormCoordinator: Coordinator, Presentable {
guard let self = self else { return }
self.pollEditFormViewModel.stopLoading()
self.log2Analytics(details: details, room: self.parameters.room)
self.completion?()
} failure: { [weak self] error in
guard let self = self else { return }
@@ -154,4 +155,28 @@ final class PollEditFormCoordinator: Coordinator, Presentable {
return mapping[key] ?? EditFormPollType.disclosed
}
// MARK: Bwi tracking
private func log2Analytics(details: EditFormPollDetails, room: MXRoom) {
BWIAnalyticsHelper.getRoomDeviceCount(room: room) { deviceCount in
var eventName: String
switch details.type {
case .undisclosed:
if details.showParticipants {
eventName = "undisclosed_show_participants"
} else {
eventName = "undisclosed"
}
case .disclosed:
if details.showParticipants {
eventName = "disclosed_show_participants"
} else {
eventName = "disclosed"
}
}
BWIAnalytics.sharedTracker.trackEventWithDimension(category: "Feature", action: "SendPoll", dimension: BWIAnalyticsHelper.dimensionForDeviceCount(deviceCount), value: NSNumber(value: details.answerOptions.count), name: eventName)
}
}
}
+11
View File
@@ -195,6 +195,17 @@ import MatomoTracker
}
}
}
func trackEventWithDimension(category: String, action: String, dimension: String, value: NSNumber?, name: String?) {
if fastRunning {
// bwi: Analytics use custom config
if let dimensionIndex = analyticsConfig.selectedSendMessageDimensionIndex() {
matomo?.setDimension(dimension, forIndex: dimensionIndex)
matomo?.track(eventWithCategory: category, action: action, name: name, number: value, url:nil) // name optional unwrap?
matomo?.remove(dimensionAtIndex: dimensionIndex)
}
}
}
}
extension BWIAnalytics : MXAnalyticsDelegate {
@@ -0,0 +1,94 @@
//
/*
* Copyright (c) 2023 BWI GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation
import MatrixSDK
@objc class BWIAnalyticsHelper: NSObject {
@objc static func getRoomDeviceCount(room: MXRoom, completion: @escaping(Int) -> ()) {
room.members { roomMembers in
var noOfDevices = 0
for member in roomMembers?.joinedMembers ?? [MXRoomMember]() {
noOfDevices += room.mxSession.crypto.devices(forUser: member.userId).count
}
completion(noOfDevices)
} lazyLoadedMembers: { _ in
completion(0)
} failure: { error in
MXLog.error("[RoomAnalyticsHelper] Failed loading room", context: error)
completion(0)
}
}
@objc static func getForwardingType(event: MXEvent) -> String? {
guard let messageType: MXMessageType = event.messageType else {
return nil
}
switch messageType {
case .text:
return "text"
case .image:
return "image"
case .video:
return "video"
case .audio:
if (event.content["org.matrix.msc2516.voice"] != nil) || (event.content["org.matrix.msc3245.voice"] != nil) {
return "voice_message"
} else {
return "audio"
}
case .emote:
return nil
case .notice:
return nil
case .location:
return "location"
case .file:
return "file"
case .custom(_):
return nil
}
}
// MARK: custom dimensions
@objc static func dimensionForDeviceCount(_ deviceCount: Int) -> String {
if deviceCount <= 0 {
return "Undefiniert"
}
if deviceCount <= 10 {
return "1 bis 10"
}
if deviceCount <= 100 {
return "11 bis 100"
}
if deviceCount <= 200 {
return "101 bis 200"
}
if deviceCount <= 500 {
return "201 bis 500"
}
if deviceCount <= 1000 {
return "501 bis 1000"
}
if deviceCount <= 2500 {
return "1001 bis 2500"
} else {
return "mehr als 2500"
}
}
}
@@ -53,33 +53,7 @@ import Foundation
func log2Analytics(users: Int, devices: Int) {
if isLogable() {
BWIAnalytics.sharedTracker.trackSlowMessage(dimension: dimensionForDeviceCount(devices), value: Int(timeInterval*1000))
}
}
func dimensionForDeviceCount(_ deviceCount: Int) -> String {
if deviceCount <= 0 {
return "Undefiniert"
}
if deviceCount <= 10 {
return "1 bis 10"
}
if deviceCount <= 100 {
return "11 bis 100"
}
if deviceCount <= 200 {
return "101 bis 200"
}
if deviceCount <= 500 {
return "201 bis 500"
}
if deviceCount <= 1000 {
return "501 bis 1000"
}
if deviceCount <= 2500 {
return "1001 bis 2500"
} else {
return "mehr als 2500"
BWIAnalytics.sharedTracker.trackSlowMessage(dimension: BWIAnalyticsHelper.dimensionForDeviceCount(devices), value: Int(timeInterval*1000))
}
}
}