Skip to content

Commit

Permalink
Add Pixel for sync unauthenticated response (#1757)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1204729420609454/f

Description:
Report sync HTTP 401 responses as pixels.
  • Loading branch information
ayoy authored Jun 2, 2023
1 parent 2292f59 commit f331107
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ extension Pixel {
case bookmarksMigrationCouldNotValidateDatabase
case bookmarksMigrationCouldNotRemoveOldStore

case syncSentUnauthenticatedRequest
case syncMetadataCouldNotLoadDatabase
case syncBookmarksProviderInitializationFailed
case syncBookmarksFailed
Expand Down Expand Up @@ -819,6 +820,7 @@ extension Pixel.Event {
case .bookmarksMigrationCouldNotValidateDatabase: return "m_d_bookmarks_migration_could_not_validate_database"
case .bookmarksMigrationCouldNotRemoveOldStore: return "m_d_bookmarks_migration_could_not_remove_old_store"

case .syncSentUnauthenticatedRequest: return "m_d_sync_sent_unauthenticated_request"
case .syncMetadataCouldNotLoadDatabase: return "m_d_sync_metadata_could_not_load_database"
case .syncBookmarksProviderInitializationFailed: return "m_d_sync_bookmarks_provider_initialization_failed"
case .syncBookmarksFailed: return "m_d_sync_bookmarks_failed"
Expand Down
36 changes: 36 additions & 0 deletions Core/SyncErrorHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// SyncErrorHandler.swift
// DuckDuckGo
//
// Copyright © 2023 DuckDuckGo. All rights reserved.
//
// 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 Common
import DDGSync
import Foundation

public class SyncErrorHandler: EventMapping<SyncError> {

public init() {
super.init { event, _, _, _ in
let domainEvent = Pixel.Event.syncSentUnauthenticatedRequest
Pixel.fire(pixel: domainEvent, error: event)
}
}

override init(mapping: @escaping EventMapping<SyncError>.Mapping) {
fatalError("Use init()")
}
}
6 changes: 5 additions & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
37FCAAB629919CEB000E420A /* WindowsBrowserWaitlist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FCAAB529919CEB000E420A /* WindowsBrowserWaitlist.swift */; };
37FCAABC2992F592000E420A /* MultilineScrollableTextFix.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FCAABB2992F592000E420A /* MultilineScrollableTextFix.swift */; };
37FCAAC029930E26000E420A /* FailedAssertionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FCAABF29930E26000E420A /* FailedAssertionView.swift */; };
37FD780F2A29E28B00B36DB1 /* SyncErrorHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD780E2A29E28B00B36DB1 /* SyncErrorHandler.swift */; };
4B0295192537BC6700E00CEF /* ConfigurationDebugViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B0295182537BC6700E00CEF /* ConfigurationDebugViewController.swift */; };
4B2754EC29E8C7DF00394032 /* Lottie in Frameworks */ = {isa = PBXBuildFile; productRef = 4B2754EB29E8C7DF00394032 /* Lottie */; };
4B470ED6299C49800086EBDC /* AppTrackingProtectionDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B470ED5299C49800086EBDC /* AppTrackingProtectionDatabase.swift */; };
Expand Down Expand Up @@ -1198,6 +1199,7 @@
37FCAABB2992F592000E420A /* MultilineScrollableTextFix.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultilineScrollableTextFix.swift; sourceTree = "<group>"; };
37FCAABF29930E26000E420A /* FailedAssertionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FailedAssertionView.swift; sourceTree = "<group>"; };
37FCAACB2993149A000E420A /* Waitlist */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Waitlist; sourceTree = "<group>"; };
37FD780E2A29E28B00B36DB1 /* SyncErrorHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncErrorHandler.swift; sourceTree = "<group>"; };
4B0295182537BC6700E00CEF /* ConfigurationDebugViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationDebugViewController.swift; sourceTree = "<group>"; };
4B470ED5299C49800086EBDC /* AppTrackingProtectionDatabase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppTrackingProtectionDatabase.swift; sourceTree = "<group>"; };
4B470ED8299C4AED0086EBDC /* AppTrackingProtectionModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = AppTrackingProtectionModel.xcdatamodel; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3160,6 +3162,7 @@
37DF000929F9C416002B7D3E /* SyncMetadataDatabase.swift */,
37DF000E29F9D635002B7D3E /* SyncBookmarksAdapter.swift */,
37445F962A155F7C0029F789 /* SyncDataProviders.swift */,
37FD780E2A29E28B00B36DB1 /* SyncErrorHandler.swift */,
);
name = Sync;
sourceTree = "<group>";
Expand Down Expand Up @@ -6350,6 +6353,7 @@
85BDC3142434D8F80053DB07 /* DebugUserScript.swift in Sources */,
85011867290028C400BDEE27 /* BookmarksDatabase.swift in Sources */,
85D2187B24BF9F85004373D2 /* FaviconUserScript.swift in Sources */,
37FD780F2A29E28B00B36DB1 /* SyncErrorHandler.swift in Sources */,
85F21DC621145DD5002631A6 /* global.swift in Sources */,
F41C2DA326C1925700F9A760 /* BookmarksAndFolders.xcdatamodeld in Sources */,
F4F6DFBA26EFF28A00ED7E12 /* BookmarkObjects.swift in Sources */,
Expand Down Expand Up @@ -8191,7 +8195,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 58.1.1;
version = 59.0.0;
};
};
C14882EB27F211A000D59F0C /* XCRemoteSwiftPackageReference "SwiftSoup" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/DuckDuckGo/BrowserServicesKit",
"state": {
"branch": null,
"revision": "e1e50bab938c9722d1cf4f8b1f28a31308b14167",
"version": "58.1.1"
"revision": "97ba4cb21ae879aff65d70888deca31c4e4dfdbd",
"version": "59.0.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// MARK: Sync initialisation

syncDataProviders = SyncDataProviders(bookmarksDatabase: bookmarksDatabase)
syncService = DDGSync(dataProvidersSource: syncDataProviders, log: .syncLog)
syncService = DDGSync(dataProvidersSource: syncDataProviders, errorEvents: SyncErrorHandler(), log: .syncLog)

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)

Expand Down

0 comments on commit f331107

Please sign in to comment.