diff --git a/macOS/Privado/Sources/Core/Logger/SnowplowLogger.swift b/macOS/Privado/Sources/Core/Logger/SnowplowLogger.swift index e2e906a8..89444e5d 100644 --- a/macOS/Privado/Sources/Core/Logger/SnowplowLogger.swift +++ b/macOS/Privado/Sources/Core/Logger/SnowplowLogger.swift @@ -73,7 +73,7 @@ final class SnowplowLogger: EventComet, VPNComet { case PrivadoConstants.Event.Statistic.Application.killswitch: self.track(applicationEvent: "KillSwitchExecuteTrackEvent", attributes: attributes) case PrivadoConstants.Event.Statistic.Application.settings: - self.track(applicationEvent: "SaveSettingsTrackEvent", attributes: [PrivadoConstants.Event.Attributes.value: "true"]) + self.track(applicationEvent: "SaveSettingsTrackEvent", attributes: attributes) case PrivadoConstants.Event.Statistic.Application.premiumServer: self.track(applicationEvent: "PremiumServerClick", attributes: attributes) case PrivadoConstants.Event.Statistic.Application.upgradeButton: @@ -83,7 +83,8 @@ final class SnowplowLogger: EventComet, VPNComet { self.track(accountEvent: "LoginTrackEvent", attributes: attributes) case PrivadoConstants.Event.Statistic.Account.create: self.track(accountEvent: "CreateFreemiumTrackEvent", attributes: attributes) - + case PrivadoConstants.Event.Statistic.Account.logout: + self.track(accountEvent: "LogoutTrackEvent", attributes: attributes) default: break @@ -117,11 +118,19 @@ final class SnowplowLogger: EventComet, VPNComet { // MARK: - Private private func track(applicationEvent: String, attributes: [String: Any]) { - + + var attributes = attributes + + if let extraData = attributes[PrivadoConstants.Event.Attributes.extradata] as? [String: Any] { + + let jsonText = convetToJSONString(extraData) + attributes[PrivadoConstants.Event.Attributes.extradata] = jsonText + } + let params: [String: Any] = [ Constants.Param.name: applicationEvent, Constants.Param.value: attributes[PrivadoConstants.Event.Attributes.value] ?? "", - Constants.Param.extradata: "" + Constants.Param.extradata: attributes[PrivadoConstants.Event.Attributes.extradata] ?? "" ] Self.track(schema: Constants.Schema.application, data: params, using: self.tracker) @@ -134,7 +143,7 @@ final class SnowplowLogger: EventComet, VPNComet { let params: [String: Any] = [ Constants.Param.name: accountEvent, Constants.Param.value: value ? "success" : "failure", - Constants.Param.extradata: "" + Constants.Param.extradata: attributes[PrivadoConstants.Event.Attributes.extradata] ?? "" ] Self.track(schema: Constants.Schema.account, data: params, using: self.tracker) @@ -153,6 +162,16 @@ final class SnowplowLogger: EventComet, VPNComet { Self.track(schema: Constants.Schema.connection, data: params, using: self.tracker) } + private func convetToJSONString(_ data: [String: Any]) -> String { + + guard let jsonData = try? JSONSerialization.data(withJSONObject: data, options: .prettyPrinted), + let jsonText = String(data: jsonData, encoding: .ascii) else { return "" } + + let text = jsonText.replacingOccurrences(of: "[ \n]", with: "", options: .regularExpression, range: nil) + + return text + } + // MARK: - Static private static func track(schema: String, data: [String: Any], using tracker: TrackerController) { @@ -160,7 +179,7 @@ final class SnowplowLogger: EventComet, VPNComet { var params = data params[Constants.Param.appversion] = Environment.shortVersion params[Constants.Param.timestamp] = Self.dateFormatter.string(from: Date()) - + guard let data = params as NSObject? , let selfDescribing = SelfDescribingJson(schema: schema, andData: data) else { return diff --git a/macOS/Privado/Sources/Flows/LoginFlow/Coordinator/LoginCoordinator.swift b/macOS/Privado/Sources/Flows/LoginFlow/Coordinator/LoginCoordinator.swift index c3bd3334..460543e3 100644 --- a/macOS/Privado/Sources/Flows/LoginFlow/Coordinator/LoginCoordinator.swift +++ b/macOS/Privado/Sources/Flows/LoginFlow/Coordinator/LoginCoordinator.swift @@ -82,6 +82,9 @@ extension LoginCoordinator: CoordinatorProtocol { switch type { case .signout: + CometLogger.shared.event(name: PrivadoConstants.Event.Statistic.Account.logout, + attributes: [PrivadoConstants.Event.Attributes.value: true], + secured: nil) self.handleSignOut() return case .authenticate: diff --git a/macOS/Privado/Sources/Flows/MainFlow/Submodules/TrafficPanel/Presenter/TrafficPanelPresenter.swift b/macOS/Privado/Sources/Flows/MainFlow/Submodules/TrafficPanel/Presenter/TrafficPanelPresenter.swift index c96573d0..5ddc6c3a 100644 --- a/macOS/Privado/Sources/Flows/MainFlow/Submodules/TrafficPanel/Presenter/TrafficPanelPresenter.swift +++ b/macOS/Privado/Sources/Flows/MainFlow/Submodules/TrafficPanel/Presenter/TrafficPanelPresenter.swift @@ -235,7 +235,9 @@ extension TrafficPanelPresenter: TrafficPanelViewOutput { func viewButtonClicked(viewInput: TrafficPanelViewInput) { guard let url = self.actionUrl else { return } - CometLogger.shared.event(name: PrivadoConstants.Event.Statistic.Application.upgradeButton, attributes: [PrivadoConstants.Event.Attributes.screenId : PrivadoConstants.Event.Screen.trafficProgress], secured: nil) + CometLogger.shared.event(name: PrivadoConstants.Event.Statistic.Application.upgradeButton, + attributes: [PrivadoConstants.Event.Attributes.extradata : [PrivadoConstants.Event.Attributes.screenId : PrivadoConstants.Event.Screen.trafficProgress]], + secured: nil) self.output?.navigate(to: url) } } diff --git a/macOS/Privado/Sources/Flows/ModalFlow/Module/Presenter/ModalPresenter.swift b/macOS/Privado/Sources/Flows/ModalFlow/Module/Presenter/ModalPresenter.swift index 0b6e00ef..6b710e91 100644 --- a/macOS/Privado/Sources/Flows/ModalFlow/Module/Presenter/ModalPresenter.swift +++ b/macOS/Privado/Sources/Flows/ModalFlow/Module/Presenter/ModalPresenter.swift @@ -72,6 +72,9 @@ extension ModalPresenter: ModalControllerOutput { func modalControllerAction(_ controller: ModalControllerInput) { guard let url = self.actionUrl, let output = self.output else { return } + CometLogger.shared.event(name: PrivadoConstants.Event.Statistic.Application.upgradeButton, + attributes: [ PrivadoConstants.Event.Attributes.extradata: [ PrivadoConstants.Event.Attributes.screenId : PrivadoConstants.Event.Screen.overlay ] ], + secured: nil) output.openUrl(url: url) } } diff --git a/macOS/Privado/Sources/Flows/PreferenceFlow/Module/Builder/PreferencesBuilder.swift b/macOS/Privado/Sources/Flows/PreferenceFlow/Module/Builder/PreferencesBuilder.swift index 6f090bd6..51f28a90 100644 --- a/macOS/Privado/Sources/Flows/PreferenceFlow/Module/Builder/PreferencesBuilder.swift +++ b/macOS/Privado/Sources/Flows/PreferenceFlow/Module/Builder/PreferencesBuilder.swift @@ -10,11 +10,11 @@ import Foundation final class PreferencesBuilder { - static func build(output: PreferenceOutputProtocol) -> SettingsViewController { + static func build(output: PreferenceOutputProtocol) -> PreferencesViewController { let interactor = PreferencesInteractor(customerEmitter: CustomerModuleBuilder.shared().customerEmitter) - let presenter = PreferencesPresenter(interactor: interactor) - let controller = SettingsViewController(output: presenter, windowOutput: output) + let presenter = PreferencesPresenter(interactor: interactor, windowOutput: output) + let controller = PreferencesViewController(output: presenter) presenter.viewInput = controller return controller diff --git a/macOS/Privado/Sources/Flows/PreferenceFlow/Module/Presenter/PreferencesPresenter.swift b/macOS/Privado/Sources/Flows/PreferenceFlow/Module/Presenter/PreferencesPresenter.swift index 2e53fd97..729ee084 100644 --- a/macOS/Privado/Sources/Flows/PreferenceFlow/Module/Presenter/PreferencesPresenter.swift +++ b/macOS/Privado/Sources/Flows/PreferenceFlow/Module/Presenter/PreferencesPresenter.swift @@ -10,13 +10,16 @@ import Foundation final class PreferencesPresenter: PreferencesViewOutput { + private var windowOutput: PreferenceOutputProtocol? + weak var viewInput: PreferencesViewInput? private let interactor: PreferencesInteractorInput - init(interactor: PreferencesInteractorInput) { + init(interactor: PreferencesInteractorInput, windowOutput: PreferenceOutputProtocol) { self.interactor = interactor + self.windowOutput = windowOutput interactor.customerChanged = { [weak self] customerIsExist in if !customerIsExist { @@ -24,4 +27,31 @@ final class PreferencesPresenter: PreferencesViewOutput { } } } + + // MARK: PreferencesViewOutput + + func closeWindow() { + + var proto = "" + + if let savedProtocol = UserSettings.shared.vpnType { + proto = savedProtocol.description + } + + let savedPrefences: [String: Any] = [ + PrivadoConstants.Event.Preferences.killswitch : UserSettings.shared.killSwitchEnabled, + PrivadoConstants.Event.Preferences.autostart : UserSettings.shared.autostartEnabled, + PrivadoConstants.Event.Preferences.autoconnect : UserSettings.shared.preferredServer == .none ? true : false, + PrivadoConstants.Event.Preferences.autoconnectvalue : UserSettings.shared.preferredServer.description, + PrivadoConstants.Event.Preferences.proto : proto, + PrivadoConstants.Event.Preferences.dock : UserSettings.shared.isDocked + ] + + CometLogger.shared.event(name: PrivadoConstants.Event.Statistic.Application.settings, + attributes: [ + PrivadoConstants.Event.Attributes.value : PrivadoConstants.Event.Attributes.success, + PrivadoConstants.Event.Attributes.extradata : savedPrefences + ], secured: nil) + self.windowOutput?.closePreferences() + } } diff --git a/macOS/Privado/Sources/Flows/PreferenceFlow/Module/View/SettingsViewController.swift b/macOS/Privado/Sources/Flows/PreferenceFlow/Module/View/PreferencesViewController.swift similarity index 96% rename from macOS/Privado/Sources/Flows/PreferenceFlow/Module/View/SettingsViewController.swift rename to macOS/Privado/Sources/Flows/PreferenceFlow/Module/View/PreferencesViewController.swift index 6b023812..8c237517 100644 --- a/macOS/Privado/Sources/Flows/PreferenceFlow/Module/View/SettingsViewController.swift +++ b/macOS/Privado/Sources/Flows/PreferenceFlow/Module/View/PreferencesViewController.swift @@ -1,5 +1,5 @@ // -// SettingsViewController.swift +// PreferencesViewController.swift // PrivadoVPN // // Created by Murad Shabanov on 20.07.2021. @@ -12,9 +12,11 @@ protocol PreferencesViewInput: AnyObject { func closeWindow() } -protocol PreferencesViewOutput: AnyObject { } +protocol PreferencesViewOutput: AnyObject { + func closeWindow() +} -final class SettingsViewController: NSViewController, PreferencesViewInput { +final class PreferencesViewController: NSViewController, PreferencesViewInput { var preferencePanes = [PreferencePane]() { didSet { @@ -35,9 +37,8 @@ final class SettingsViewController: NSViewController, PreferencesViewInput { private let controllerView: NSView private var output: PreferencesViewOutput? - private var windowOutput: PreferenceOutputProtocol? - init(output: PreferencesViewOutput, windowOutput: PreferenceOutputProtocol) { + init(output: PreferencesViewOutput) { self.titleBarView = TopView() self.titleBarView.viewBackgroundColor = .red self.closeButton = ImageView(image: NSImage(named: "closeMenu")!) @@ -45,7 +46,6 @@ final class SettingsViewController: NSViewController, PreferencesViewInput { self.segmentedControl = SegmentedControl() self.controllerView = BottomView(backgroundColor: NSColor(red: 0, green: 8, blue: 44)) self.output = output - self.windowOutput = windowOutput super.init(nibName: nil, bundle: nil) } @@ -145,7 +145,7 @@ final class SettingsViewController: NSViewController, PreferencesViewInput { @objc private func onCloseAction() { - self.windowOutput?.closePreferences() + self.output?.closeWindow() } func activateTab(preferenceIdentifier: PreferencePane.Identifier, animated: Bool) { @@ -261,7 +261,7 @@ final class SettingsViewController: NSViewController, PreferencesViewInput { // MARK: - PreferencesViewInput - func closeWindow() { - self.windowOutput?.closePreferences() + self.output?.closeWindow() } } diff --git a/macOS/Privado/Sources/Flows/PreferenceFlow/Module/View/WindowController.swift b/macOS/Privado/Sources/Flows/PreferenceFlow/Module/View/WindowController.swift index d62b4625..b4f9bdec 100644 --- a/macOS/Privado/Sources/Flows/PreferenceFlow/Module/View/WindowController.swift +++ b/macOS/Privado/Sources/Flows/PreferenceFlow/Module/View/WindowController.swift @@ -14,9 +14,9 @@ extension NSWindow.FrameAutosaveName { final class WindowController: NSWindowController { - private var viewController: SettingsViewController + private var viewController: PreferencesViewController - init(panes: [PreferencePane], output: PreferenceOutputProtocol, controller: SettingsViewController) { + init(panes: [PreferencePane], output: PreferenceOutputProtocol, controller: PreferencesViewController) { let window = UserInteractionPausableWindow( // temp contentRect contentRect: NSRect(x: 0, y: 0, width: 500, height: 500), styleMask: [ .borderless ], diff --git a/macOS/Privado/Sources/Flows/PreferenceFlow/Submodules/Account/Presenter/AccountPreferencesPresenter.swift b/macOS/Privado/Sources/Flows/PreferenceFlow/Submodules/Account/Presenter/AccountPreferencesPresenter.swift index 661f6fdf..d694ac45 100644 --- a/macOS/Privado/Sources/Flows/PreferenceFlow/Submodules/Account/Presenter/AccountPreferencesPresenter.swift +++ b/macOS/Privado/Sources/Flows/PreferenceFlow/Submodules/Account/Presenter/AccountPreferencesPresenter.swift @@ -94,8 +94,6 @@ final class AccountPreferencesPresenter: AccountPreferencesViewOutput { let formatterShort = DateFormatter() formatterShort.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" - - print("end date = \(self.customerModule.customerEmitter.value??.endDate)") guard let customer = self.customerModule.customerEmitter.value, let endDate = customer?.endDate, @@ -160,7 +158,9 @@ final class AccountPreferencesPresenter: AccountPreferencesViewOutput { func viewButtonClicked() { guard let url = self.actionUrl else { return } - CometLogger.shared.event(name: PrivadoConstants.Event.Statistic.Application.upgradeButton, attributes: [PrivadoConstants.Event.Attributes.screenId : PrivadoConstants.Event.Screen.preferences], secured: nil) + CometLogger.shared.event(name: PrivadoConstants.Event.Statistic.Application.upgradeButton, + attributes: [PrivadoConstants.Event.Attributes.extradata : [PrivadoConstants.Event.Attributes.screenId : PrivadoConstants.Event.Screen.preferences]], + secured: nil) openApplicationRoute(.navigate(url: url)) } } diff --git a/macOS/Privado/Sources/Flows/PreferenceFlow/Submodules/Protocol/Presenter/ProtocolPreferencesPresenter.swift b/macOS/Privado/Sources/Flows/PreferenceFlow/Submodules/Protocol/Presenter/ProtocolPreferencesPresenter.swift index c7fb25ca..a8eae2a0 100644 --- a/macOS/Privado/Sources/Flows/PreferenceFlow/Submodules/Protocol/Presenter/ProtocolPreferencesPresenter.swift +++ b/macOS/Privado/Sources/Flows/PreferenceFlow/Submodules/Protocol/Presenter/ProtocolPreferencesPresenter.swift @@ -142,7 +142,6 @@ final class ProtocolPreferencesPresenter: ProtocolPreferencesViewOutput { attributes: [PrivadoConstants.Event.Attributes.proto: UserSettings.shared.proto, PrivadoConstants.Event.Attributes.port: UserSettings.shared.port], secured: nil) - } private func update(value enable: Bool, with identity: Int) { diff --git a/macOS/Privado/Sources/Flows/ServerFlow/Module/Presenter/ServersPresenter.swift b/macOS/Privado/Sources/Flows/ServerFlow/Module/Presenter/ServersPresenter.swift index 2f3e208a..d7afaeed 100644 --- a/macOS/Privado/Sources/Flows/ServerFlow/Module/Presenter/ServersPresenter.swift +++ b/macOS/Privado/Sources/Flows/ServerFlow/Module/Presenter/ServersPresenter.swift @@ -270,10 +270,14 @@ extension ServersPresenter: ServersControllerOutput { let plan = self.output?.currentPlan ?? .freemium if plan == .freemium, !city.isFreemium { - CometLogger.shared.event(name: PrivadoConstants.Event.Statistic.Application.premiumServer, attributes: [ - PrivadoConstants.Event.Attributes.city : city, - PrivadoConstants.Event.Attributes.country : country - ], secured: nil) + CometLogger.shared.event(name: PrivadoConstants.Event.Statistic.Application.premiumServer, + attributes: [ + PrivadoConstants.Event.Attributes.extradata : [ + PrivadoConstants.Event.Attributes.city : city.city, + PrivadoConstants.Event.Attributes.country : country.country + ] + ], + secured: nil) let settings: Route.ModalSettings = .closable(title: NSLocalizedString(Constants.LocalizedString.premiumTitle, comment: ""), description: NSLocalizedString(Constants.LocalizedString.premiumDescription, comment: ""), buttonTitle: NSLocalizedString(Constants.LocalizedString.premiumButton, comment: ""),