// /* * Copyright (c) 2021 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 MatomoTracker @objcMembers class BWIAnalytics : NSObject { static let sharedTracker = BWIAnalytics() public var running: Bool = false private let matomo: MatomoTracker? private let appName: String private let appVersion: String private let appPlattform = "iOS" private override init() { appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as! String appVersion = AppDelegate.theDelegate().appVersion if BuildSettings.bwiEnableErrorTracking { guard let url = URL(string: BuildSettings.bwiAnalyticsServerUrlString) else { matomo = nil return } matomo = MatomoTracker.init(siteId: BuildSettings.bwiAnalyticsAppId, baseURL:url, userAgent: nil) matomo?.isOptedOut = false matomo?.logger = DefaultLogger(minLevel: .verbose) matomo?.setCustomVariable(withIndex: 1, name: "App Platform", value: appPlattform) matomo?.setCustomVariable(withIndex: 2, name: "App Version", value: appVersion) } else { matomo = nil } } func trackScreen(_ screenName: String) { if running { matomo?.track(view: ["ios", appName, appVersion, screenName], url: nil) } } func trackEvent(_ category: String, action: String) { if running { matomo?.track(eventWithCategory: category, action: action, url:nil) } } func trackBwiDuration(_ duration: TimeInterval, _ category: String, _ name: String) { if running { matomo?.track(eventWithCategory: "Metrics", action: category, name: name, number: NSNumber(value: duration), url:nil) } } func trackBwiValue(_ value: NSNumber, _ category: String, _ action: String) { if running { matomo?.track(eventWithCategory: category, action: action, name: nil, number: value, url:nil) } } func trackBwiValue(_ value: NSNumber, _ category: String, _ action: String, _ name: String) { if running { matomo?.track(eventWithCategory: category, action: action, name: name, number: value, url:nil) } } } extension BWIAnalytics : MXAnalyticsDelegate { func trackJoinedRoom(asDM isDM: Bool, isSpace: Bool, memberCount: UInt) { // dont track NV specific logs } func trackValue(_ value: NSNumber, category: String, name: String) { // dont track NV specific logs } func trackDuration(_ milliseconds: Int, name: MXTaskProfileName, units: UInt) { // dont track NV specific logs } func trackCreatedRoom(asDM isDM: Bool) { // dont track NV specific logs } func trackCallStarted(withVideo isVideo: Bool, numberOfParticipants: Int, incoming isIncoming: Bool) { // dont track NV specific logs } func trackCallEnded(withDuration duration: Int, video isVideo: Bool, numberOfParticipants: Int, incoming isIncoming: Bool) { // dont track NV specific logs } func trackCallError(with reason: __MXCallHangupReason, video isVideo: Bool, numberOfParticipants: Int, incoming isIncoming: Bool) { // dont track NV specific logs } func trackJoinedRoom(asDM isDM: Bool, memberCount: UInt) { // dont track NV specific logs } func trackContactsAccessGranted(_ granted: Bool) { // dont track NV specific logs } func trackBwiSDKValue(_ value: NSNumber, category: String, action: String) { self.trackBwiValue(value, category, action) } func trackBwiSDKValue(_ value: NSNumber, category: String, action: String, name: String) { self.trackBwiValue(value, category, action, name); } func trackBwiEvent(_ category: String, action: String) { self.trackEvent(category, action: action) } }