Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Bug 1354096 - Stop using Adjust for UI telemetry (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
justindarc committed May 23, 2017
1 parent fce54c7 commit 64ab58e
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 156 deletions.
41 changes: 0 additions & 41 deletions Blockzilla/Adjust-Focus.plist
Expand Up @@ -4,46 +4,5 @@
<dict>
<key>AppToken</key>
<string>XXX</string>
<key>Events</key>
<dict>
<key>Browse</key>
<string>hjuag8</string>
<key>Search</key>
<string>jf1b59</string>
<key>Clear</key>
<string>hy183e</string>
<key>OpenInFirefox</key>
<string>t7m1ru</string>
<key>OpenInSafari</key>
<string>ns4a3y</string>
<key>EnableBlockAds</key>
<string>1pmsby</string>
<key>DisableBlockAds</key>
<string>34xb7g</string>
<key>EnableBlockAnalytics</key>
<string>oimjge</string>
<key>DisableBlockAnalytics</key>
<string>pppabq</string>
<key>EnableBlockFonts</key>
<string>1zb5ah</string>
<key>DisableBlockFonts</key>
<string>nfi1np</string>
<key>EnableBlockOther</key>
<string>fr308r</string>
<key>DisableBlockOther</key>
<string>vp5tjk</string>
<key>EnableBlockSocial</key>
<string>9l4fiy</string>
<key>DisableBlockSocial</key>
<string>ha6nkv</string>
<key>EnableSafariIntegration</key>
<string>ec8kb7</string>
<key>DisableSafariIntegration</key>
<string>i0zoki</string>
<key>OpenSystemShare</key>
<string>n4k5jo</string>
<key>OpenFirefoxInstall</key>
<string>5qb7ma</string>
</dict>
</dict>
</plist>
41 changes: 0 additions & 41 deletions Blockzilla/Adjust-Klar.plist
Expand Up @@ -4,46 +4,5 @@
<dict>
<key>AppToken</key>
<string>XXX</string>
<key>Events</key>
<dict>
<key>Browse</key>
<string>58bwsk</string>
<key>Search</key>
<string>pxtu4v</string>
<key>Clear</key>
<string>n9hwgu</string>
<key>OpenInFirefox</key>
<string>usp0gb</string>
<key>OpenInSafari</key>
<string>5elufs</string>
<key>EnableBlockAds</key>
<string>frnano</string>
<key>DisableBlockAds</key>
<string>uqm3k4</string>
<key>EnableBlockAnalytics</key>
<string>au3px7</string>
<key>DisableBlockAnalytics</key>
<string>4t3lka</string>
<key>EnableBlockFonts</key>
<string>5fbqr5</string>
<key>DisableBlockFonts</key>
<string>oymwmb</string>
<key>EnableBlockOther</key>
<string>tz19iu</string>
<key>DisableBlockOther</key>
<string>vzlgmg</string>
<key>EnableBlockSocial</key>
<string>6ddntz</string>
<key>DisableBlockSocial</key>
<string>ohnn42</string>
<key>EnableSafariIntegration</key>
<string>w67hjo</string>
<key>DisableSafariIntegration</key>
<string>8a1gtl</string>
<key>OpenSystemShare</key>
<string>b42cgh</string>
<key>OpenFirefoxInstall</key>
<string>6r6cx6</string>
</dict>
</dict>
</plist>
46 changes: 1 addition & 45 deletions Blockzilla/AdjustIntegration.swift
Expand Up @@ -5,30 +5,7 @@
import Foundation
import AdjustSdk

enum AdjustEventName: String {
case browse = "Browse" // When the user opens a url
case search = "Search" // When the user does a search
case clear = "Clear" // When the user erases the browsing history
case openFirefox = "OpenInFirefox" // When the user opens the page in Firefox
case openSafari = "OpenInSafari" // When the user opens the page in Safari
case openFirefoxInstall = "OpenFirefoxInstall" // When the user opens the App Store page for Firefox
case openSystemShare = "OpenSystemShare" // When the user opens the system share menu
case enableSafariIntegration = "EnableSafariIntegration" // When the user enables the Safari blocklist
case disableSafariIntegration = "DisableSafariIntegration" // When the user disables the Safari blocklist
case enableBlockAds = "EnableBlockAds" // When the user enables Block Ad Trackers
case disableBlockAds = "DisableBlockAds" // When the user disables Block Ad Trackers
case enableBlockAnalytics = "EnableBlockAnalytics" // When the user enables Block Analytics Trackers
case disableBlockAnalytics = "DisableBlockAnalytics" // When the user disabled Block Analytics Trackers
case enableBlockSocial = "EnableBlockSocial" // When the user enables Block Social Trackers
case disableBlockSocial = "DisableBlockSocial" // When the user disables Block Social Trackers
case enableBlockOther = "EnableBlockOther" // When the user enables Block Other Content Trackers
case disableBlockOther = "DisableBlockOther" // When the user disables Block Other Content Trackers
case enableBlockFonts = "EnableBlockFonts" // When the user enables Block Web Fonts
case disableBlockFonts = "DisableBlockFonts" // When the user disables Block Web Fonts
}

private let AdjustAppTokenKey = "AppToken"
private let AdjustEventsKey = "Events"

private enum AdjustEnvironment: String {
case sandbox = "sandbox"
Expand All @@ -38,29 +15,18 @@ private enum AdjustEnvironment: String {
private struct AdjustSettings {
var appToken: String
var environment: AdjustEnvironment
var events: [AdjustEventName: String]

init?(contentsOf url: URL) {
guard let config = NSDictionary(contentsOf: url), let appToken = config.object(forKey: AdjustAppTokenKey) as? String, let events = config.object(forKey: AdjustEventsKey) as? [String: String] else {
guard let config = NSDictionary(contentsOf: url), let appToken = config.object(forKey: AdjustAppTokenKey) as? String else {
return nil
}

var eventMappings = [AdjustEventName: String]()
for (name, token) in events {
guard let eventName = AdjustEventName(rawValue: name) else {
assertionFailure("Event <\(name)> from settings plist not found in enum")
continue
}
eventMappings[eventName] = token
}

self.appToken = appToken
#if DEBUG
self.environment = AdjustEnvironment.sandbox
#else
self.environment = AdjustEnvironment.production
#endif
self.events = eventMappings
}
}

Expand Down Expand Up @@ -89,14 +55,4 @@ class AdjustIntegration {
Adjust.setEnabled(newValue)
}
}

public static func track(eventName: AdjustEventName) {
if Adjust.isEnabled() {
guard let settings = adjustSettings, let eventToken = settings.events[eventName] else {
assertionFailure("Adjust not initialized or event <\(eventName.rawValue)> was not found in the settings")
return
}
Adjust.trackEvent(ADJEvent(eventToken: eventToken))
}
}
}
3 changes: 1 addition & 2 deletions Blockzilla/AppDelegate.swift
Expand Up @@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import UIKit
import AdjustSdk
import Telemetry

@UIApplicationMain
Expand Down Expand Up @@ -44,7 +43,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
telemetryConfig.isUploadEnabled = false
#else
telemetryConfig.updateChannel = "release"
telemetryConfig.isCollectionEnabled = true
telemetryConfig.isCollectionEnabled = Settings.getToggle(.sendAnonymousUsageData)
telemetryConfig.isUploadEnabled = Settings.getToggle(.sendAnonymousUsageData)
#endif

Expand Down
4 changes: 0 additions & 4 deletions Blockzilla/BrowserViewController.swift
Expand Up @@ -196,7 +196,6 @@ class BrowserViewController: UIViewController {
})

Telemetry.default.recordEvent(category: TelemetryEventCategory.action, method: TelemetryEventMethod.click, object: TelemetryEventObject.eraseButton)
AdjustIntegration.track(eventName: .clear)
}

fileprivate func showSettings() {
Expand Down Expand Up @@ -253,11 +252,9 @@ extension BrowserViewController: URLBarDelegate {
var url = URIFixup.getURL(entry: text)
if url == nil {
Telemetry.default.recordEvent(category: TelemetryEventCategory.action, method: TelemetryEventMethod.typeQuery, object: TelemetryEventObject.searchBar)
AdjustIntegration.track(eventName: .search)
url = searchEngineManager.activeEngine.urlForQuery(text)
} else {
Telemetry.default.recordEvent(category: TelemetryEventCategory.action, method: TelemetryEventMethod.typeURL, object: TelemetryEventObject.searchBar)
AdjustIntegration.track(eventName: .browse)
}

submit(url: url!)
Expand Down Expand Up @@ -520,7 +517,6 @@ extension BrowserViewController: OverlayViewDelegate {
func overlayView(_ overlayView: OverlayView, didSearchForQuery query: String) {
if let url = searchEngineManager.activeEngine.urlForQuery(query) {
Telemetry.default.recordEvent(category: TelemetryEventCategory.action, method: TelemetryEventMethod.typeQuery, object: TelemetryEventObject.searchBar)
AdjustIntegration.track(eventName: .search)
submit(url: url)
}

Expand Down
4 changes: 0 additions & 4 deletions Blockzilla/OpenUtils.swift
Expand Up @@ -20,19 +20,16 @@ class OpenUtils {
}

Telemetry.default.recordEvent(category: TelemetryEventCategory.action, method: TelemetryEventMethod.open, object: TelemetryEventObject.menu, value: "firefox")
AdjustIntegration.track(eventName: .openFirefox)
app.openURL(firefoxURL)
}

private static func openFirefoxInstall() {
Telemetry.default.recordEvent(category: TelemetryEventCategory.action, method: TelemetryEventMethod.openAppStore, object: TelemetryEventObject.menu, value: "firefox")
AdjustIntegration.track(eventName: .openFirefoxInstall)
UIApplication.shared.openURL(AppInfo.config.firefoxAppStoreURL)
}

private static func openInSafari(url: URL) {
Telemetry.default.recordEvent(category: TelemetryEventCategory.action, method: TelemetryEventMethod.open, object: TelemetryEventObject.menu, value: "default")
AdjustIntegration.track(eventName: .openSafari)
app.openURL(url)
}

Expand All @@ -55,7 +52,6 @@ class OpenUtils {

alert.addAction(UIAlertAction(title: UIConstants.strings.openMore, style: .default) { _ in
Telemetry.default.recordEvent(category: TelemetryEventCategory.action, method: TelemetryEventMethod.share, object: TelemetryEventObject.menu)
AdjustIntegration.track(eventName: .openSystemShare)

let controller = UIActivityViewController(activityItems: [url], applicationActivities: nil)
controller.popoverPresentationController?.sourceView = anchor
Expand Down
20 changes: 2 additions & 18 deletions Blockzilla/SettingsViewController.swift
Expand Up @@ -278,23 +278,6 @@ class SettingsViewController: UIViewController, UITableViewDataSource, UITableVi
let telemetryEvent = TelemetryEvent(category: TelemetryEventCategory.action, method: TelemetryEventMethod.change, object: "setting", value: toggle.setting.rawValue)
telemetryEvent.addExtra(key: "to", value: sender.isOn)
Telemetry.default.recordEvent(telemetryEvent)

switch toggle.setting {
case .safari:
AdjustIntegration.track(eventName: sender.isOn ? .enableSafariIntegration : .disableSafariIntegration)
case .blockAds:
AdjustIntegration.track(eventName: sender.isOn ? .enableBlockAds : .disableBlockAds)
case .blockAnalytics:
AdjustIntegration.track(eventName: sender.isOn ? .enableBlockAnalytics : .disableBlockAnalytics)
case .blockSocial:
AdjustIntegration.track(eventName: sender.isOn ? .enableBlockSocial : .disableBlockSocial)
case .blockOther:
AdjustIntegration.track(eventName: sender.isOn ? .enableBlockOther : .disableBlockOther)
case .blockFonts:
AdjustIntegration.track(eventName: sender.isOn ? .enableBlockFonts : .disableBlockFonts)
default:
break
}

Settings.set(sender.isOn, forToggle: toggle.setting)
Utils.reloadSafariContentBlocker()
Expand All @@ -304,7 +287,8 @@ class SettingsViewController: UIViewController, UITableViewDataSource, UITableVi
// First check if the user changed the anonymous usage data setting and follow that choice right
// here. Otherwise it will be delayed until the application restarts.
if toggle.setting == .sendAnonymousUsageData {
AdjustIntegration.enabled = sender.isOn
Telemetry.default.configuration.isCollectionEnabled = sender.isOn
Telemetry.default.configuration.isUploadEnabled = sender.isOn
}

switch toggle.setting {
Expand Down
2 changes: 1 addition & 1 deletion Cartfile.resolved
Expand Up @@ -3,5 +3,5 @@ github "SnapKit/SnapKit" "3.2.0"
github "adjust/ios_sdk" "v4.10.2"
github "cezheng/Fuzi" "1.0.1"
github "mozilla-mobile/AutocompleteTextField" "ddff214d4e7df7a13e828f4af1b6d480dbec31cd"
github "mozilla-mobile/telemetry-ios" "880be6572879a27efe996ee00305ec4891357a22"
github "mozilla-mobile/telemetry-ios" "97daf6d1b5b5b6548a4bead0a14795a3c6509db7"
github "swisspol/GCDWebServer" "3.3.3"

0 comments on commit 64ab58e

Please sign in to comment.