add snowplow stats: upgrade button, preferences save, logout, premium server

This commit is contained in:
murad
2021-11-02 20:23:21 +03:00
parent eded5e4a82
commit 53a4e922b2
11 changed files with 89 additions and 29 deletions
@@ -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
@@ -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:
@@ -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)
}
}
@@ -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)
}
}
@@ -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
@@ -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()
}
}
@@ -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()
}
}
@@ -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 ],
@@ -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))
}
}
@@ -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) {
@@ -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: ""),