Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 3bb9e04

Browse files
authored
Remote Messaging (#1263)
Implementation of Remote Messaging functionality
1 parent 806dadf commit 3bb9e04

68 files changed

Lines changed: 1665 additions & 191 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Core/APIHeaders.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
//
1919

2020
import Foundation
21+
import BrowserServicesKit
2122

2223
public typealias HTTPHeaders = [String: String]
2324

‎Core/AppUrls.swift‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public struct AppUrls {
5353

5454
static var emailProtectionLink = "https://duckduckgo.com/email"
5555
static var emailProtectionQuickLink = "ddgQuickLink://https://duckduckgo.com/email"
56+
57+
static let appStore = "https://apps.apple.com/app/duckduckgo-privacy-browser/id663592361"
5658
}
5759

5860
private enum DDGStaticURL: String {
@@ -299,6 +301,10 @@ public struct AppUrls {
299301
return URL(string: "https://duckduckgo.com/mac")!
300302
}
301303

304+
public var appStoreURL: URL {
305+
return URL(string: Url.appStore)!
306+
}
307+
302308
public func pixelUrl(forPixelNamed pixelName: String, formFactor: String? = nil, includeATB: Bool = true) -> URL {
303309
var urlString = Url.pixel.format(arguments: pixelName)
304310
if let formFactor = formFactor {

‎Core/AppVersion.swift‎

Lines changed: 0 additions & 66 deletions
This file was deleted.

‎Core/AtbAndVariantCleanup.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import Foundation
2121
import Core
22+
import BrowserServicesKit
2223

2324
public class AtbAndVariantCleanup {
2425

‎Core/BookmarksCachingSearch.swift‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ public class BookmarksCachingSearch {
7676
return cachedBookmarksAndFavorites ?? []
7777
}
7878

79+
public var bookmarksCount: Int {
80+
let bookmarksAndFavorites = bookmarksAndFavorites
81+
let bookmarksOnly = bookmarksAndFavorites.filter { !$0.isFavorite }
82+
return bookmarksOnly.count
83+
}
84+
85+
public var favoritesCount: Int {
86+
let bookmarksAndFavorites = bookmarksAndFavorites
87+
let favoritesOnly = bookmarksAndFavorites.filter { $0.isFavorite }
88+
return favoritesOnly.count
89+
}
90+
7991
public func containsDomain(_ domain: String) -> Bool {
8092
return bookmarksAndFavorites.contains { $0.url?.host == domain }
8193
}
Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// VariantManager.swift
2+
// DefaultVariantManager.swift
33
// DuckDuckGo
44
//
55
// Copyright © 2017 DuckDuckGo. All rights reserved.
@@ -20,14 +20,10 @@
2020
import Foundation
2121
import os.log
2222
import Speech
23+
import BrowserServicesKit
2324

24-
public enum FeatureName: String {
2525

26-
// Used for unit tests
27-
case dummy
28-
}
29-
30-
public struct Variant {
26+
public struct VariantIOS: Variant {
3127

3228
struct When {
3329
static let always = { return true }
@@ -53,16 +49,16 @@ public struct Variant {
5349
public static let defaultVariants: [Variant] = [
5450

5551
// SERP testing
56-
Variant(name: "sc", weight: doNotAllocate, isIncluded: When.always, features: []),
57-
Variant(name: "sd", weight: doNotAllocate, isIncluded: When.always, features: []),
58-
Variant(name: "se", weight: doNotAllocate, isIncluded: When.always, features: [])
52+
VariantIOS(name: "sc", weight: doNotAllocate, isIncluded: When.always, features: []),
53+
VariantIOS(name: "sd", weight: doNotAllocate, isIncluded: When.always, features: []),
54+
VariantIOS(name: "se", weight: doNotAllocate, isIncluded: When.always, features: [])
5955

6056
]
6157

62-
public let name: String
63-
public let weight: Int
64-
public let isIncluded: () -> Bool
65-
public let features: [FeatureName]
58+
public var name: String
59+
public var weight: Int
60+
public var isIncluded: () -> Bool
61+
public var features: [FeatureName]
6662

6763
}
6864

@@ -72,14 +68,6 @@ public protocol VariantRNG {
7268

7369
}
7470

75-
public protocol VariantManager {
76-
77-
var currentVariant: Variant? { get }
78-
func assignVariantIfNeeded(_ newInstallCompletion: (VariantManager) -> Void)
79-
func isSupported(feature: FeatureName) -> Bool
80-
81-
}
82-
8371
public class DefaultVariantManager: VariantManager {
8472

8573
public var currentVariant: Variant? {
@@ -91,7 +79,7 @@ public class DefaultVariantManager: VariantManager {
9179
private let storage: StatisticsStore
9280
private let rng: VariantRNG
9381

94-
public init(variants: [Variant] = Variant.defaultVariants,
82+
public init(variants: [Variant] = VariantIOS.defaultVariants,
9583
storage: StatisticsStore = StatisticsUserDefaults(),
9684
rng: VariantRNG = Arc4RandomUniformVariantRNG()) {
9785
self.variants = variants

‎Core/Logging.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import Foundation
2121
import os.log
22+
import BrowserServicesKit
2223

2324
public let generalLog: OSLog = OSLog(subsystem: Bundle.main.bundleIdentifier ?? AppVersion.shared.identifier, category: "DDG General")
2425
public let contentBlockingLog: OSLog = OSLog(subsystem: Bundle.main.bundleIdentifier ?? AppVersion.shared.identifier,

‎Core/Pixel.swift‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import Foundation
2121
import os.log
22+
import BrowserServicesKit
2223

2324
// swiftlint:enable type_body_length
2425
// swiftlint:enable identifier_name
@@ -94,8 +95,10 @@ public struct PixelParameters {
9495
public static let emailKeychainAccessType = "access_type"
9596
public static let emailKeychainError = "error"
9697
public static let emailKeychainKeychainStatus = "keychain_status"
97-
98+
9899
public static let bookmarkErrorOrphanedFolderCount = "bookmark_error_orphaned_count"
100+
101+
public static let ctaShown = "cta"
99102
}
100103

101104
public struct PixelValues {

‎Core/PixelEvent.swift‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ extension Pixel {
253253

254254
case macBrowserWaitlistNotificationShown
255255
case macBrowserWaitlistNotificationLaunched
256+
257+
// MARK: remote messaging pixels
258+
259+
case remoteMessageShown
260+
case remoteMessageShownUnique
261+
case remoteMessageDismissed
262+
case remoteMessageShownPrimaryActionClicked
263+
case remoteMessageShownSecondaryActionClicked
256264

257265
// MARK: debug pixels
258266

@@ -263,7 +271,13 @@ extension Pixel {
263271
case dbInitializationError
264272
case dbSaveExcludedHTTPSDomainsError
265273
case dbSaveBloomFilterError
266-
274+
case dbRemoteMessagingSaveConfigError
275+
case dbRemoteMessagingInvalidateConfigError
276+
case dbRemoteMessagingSaveMessageError
277+
case dbRemoteMessagingUpdateMessageShownError
278+
case dbRemoteMessagingUpdateMessageStatusError
279+
case dbRemoteMessagingDeleteScheduledMessageError
280+
267281
case configurationFetchInfo
268282

269283
case trackerDataParseFailed
@@ -569,7 +583,15 @@ extension Pixel.Event {
569583

570584
case .macBrowserWaitlistNotificationShown: return "m_notification_shown_mac_waitlist"
571585
case .macBrowserWaitlistNotificationLaunched: return "m_notification_launch_mac_waitlist"
572-
586+
587+
// MARK: remote messaging pixels
588+
589+
case .remoteMessageShown: return "m_remote_message_shown"
590+
case .remoteMessageShownUnique: return "m_remote_message_shown_unique"
591+
case .remoteMessageDismissed: return "m_remote_message_dismissed"
592+
case .remoteMessageShownPrimaryActionClicked: return "m_remote_message_primary_action_clicked"
593+
case .remoteMessageShownSecondaryActionClicked: return "m_remote_message_secondary_action_clicked"
594+
573595
// MARK: debug pixels
574596

575597
case .dbMigrationError: return "m_d_dbme"
@@ -579,7 +601,13 @@ extension Pixel.Event {
579601
case .dbInitializationError: return "m_d_dbie"
580602
case .dbSaveExcludedHTTPSDomainsError: return "m_d_dbsw"
581603
case .dbSaveBloomFilterError: return "m_d_dbsb"
582-
604+
case .dbRemoteMessagingSaveConfigError: return "m_d_db_rm_save_config"
605+
case .dbRemoteMessagingInvalidateConfigError: return "m_d_db_rm_invalidate_config"
606+
case .dbRemoteMessagingSaveMessageError: return "m_d_db_rm_save_message"
607+
case .dbRemoteMessagingUpdateMessageShownError: return "m_d_db_rm_update_message_shown"
608+
case .dbRemoteMessagingUpdateMessageStatusError: return "m_d_db_rm_update_message_status"
609+
case .dbRemoteMessagingDeleteScheduledMessageError: return "m_d_db_rm_delete_scheduled_message"
610+
583611
case .configurationFetchInfo: return "m_d_cfgfetch"
584612

585613
case .trackerDataParseFailed: return "m_d_tds_p"

‎Core/StatisticsLoader.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import Foundation
2121
import os.log
22+
import BrowserServicesKit
2223

2324
public class StatisticsLoader {
2425

0 commit comments

Comments
 (0)