Skip to content

Commit

Permalink
Non standard pixels fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
federicocappelli committed May 8, 2024
1 parent f1f51cd commit dbb2a13
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 28 deletions.
10 changes: 8 additions & 2 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2552,6 +2552,8 @@
F116A7C32BD1924B00F3FCF7 /* PixelKitTestingUtilities in Frameworks */ = {isa = PBXBuildFile; productRef = F116A7C22BD1924B00F3FCF7 /* PixelKitTestingUtilities */; };
F116A7C72BD1925500F3FCF7 /* PixelKitTestingUtilities in Frameworks */ = {isa = PBXBuildFile; productRef = F116A7C62BD1925500F3FCF7 /* PixelKitTestingUtilities */; };
F116A7C92BD1929000F3FCF7 /* PixelKitTestingUtilities in Frameworks */ = {isa = PBXBuildFile; productRef = F116A7C82BD1929000F3FCF7 /* PixelKitTestingUtilities */; };
F118EA852BEACC7000F77634 /* NonStandardPixel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F118EA842BEACC7000F77634 /* NonStandardPixel.swift */; };
F118EA862BEACC7000F77634 /* NonStandardPixel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F118EA842BEACC7000F77634 /* NonStandardPixel.swift */; };
F188267C2BBEB3AA00D9AC4F /* GeneralPixel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F188267B2BBEB3AA00D9AC4F /* GeneralPixel.swift */; };
F188267D2BBEB3AA00D9AC4F /* GeneralPixel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F188267B2BBEB3AA00D9AC4F /* GeneralPixel.swift */; };
F18826802BBEB58100D9AC4F /* PrivacyProPixel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F188267F2BBEB58100D9AC4F /* PrivacyProPixel.swift */; };
Expand Down Expand Up @@ -4034,6 +4036,7 @@
EEDE50102BA360C80017F3C4 /* NetworkProtection+VPNAgentConvenienceInitializers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NetworkProtection+VPNAgentConvenienceInitializers.swift"; sourceTree = "<group>"; };
EEF12E6D2A2111880023E6BF /* MacPacketTunnelProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacPacketTunnelProvider.swift; sourceTree = "<group>"; };
EEF53E172950CED5002D78F4 /* JSAlertViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSAlertViewModelTests.swift; sourceTree = "<group>"; };
F118EA842BEACC7000F77634 /* NonStandardPixel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonStandardPixel.swift; sourceTree = "<group>"; };
F188267B2BBEB3AA00D9AC4F /* GeneralPixel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralPixel.swift; sourceTree = "<group>"; };
F188267F2BBEB58100D9AC4F /* PrivacyProPixel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyProPixel.swift; sourceTree = "<group>"; };
F18826832BBEE31700D9AC4F /* PixelKit+Assertion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "PixelKit+Assertion.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7823,6 +7826,7 @@
857E5AF32A79044900FC0FB4 /* Experiment */,
B610F2BA27A145C500FCEBE9 /* RulesCompilationMonitor.swift */,
F188267B2BBEB3AA00D9AC4F /* GeneralPixel.swift */,
F118EA842BEACC7000F77634 /* NonStandardPixel.swift */,
F18826832BBEE31700D9AC4F /* PixelKit+Assertion.swift */,
F188267F2BBEB58100D9AC4F /* PrivacyProPixel.swift */,
);
Expand Down Expand Up @@ -10022,6 +10026,7 @@
3706FC38293F65D500E42796 /* BundleExtension.swift in Sources */,
4B9DB04B2A983B24000927DB /* NotificationService.swift in Sources */,
3706FC3A293F65D500E42796 /* NSOpenPanelExtensions.swift in Sources */,
F118EA862BEACC7000F77634 /* NonStandardPixel.swift in Sources */,
3706FC3B293F65D500E42796 /* FirePopover.swift in Sources */,
4B4D60C12A0C848E00BCD287 /* NetworkProtectionControllerErrorStore.swift in Sources */,
3706FC3E293F65D500E42796 /* VariantManager.swift in Sources */,
Expand Down Expand Up @@ -11232,6 +11237,7 @@
4B9DB04A2A983B24000927DB /* NotificationService.swift in Sources */,
3775912D29AAC72700E26367 /* SyncPreferences.swift in Sources */,
F1B33DF22BAD929D001128B3 /* SubscriptionAppStoreRestorer.swift in Sources */,
F118EA852BEACC7000F77634 /* NonStandardPixel.swift in Sources */,
1DB9618329F67F6200CF5568 /* FaviconNullStore.swift in Sources */,
BB5789722B2CA70F0009DFE2 /* DataBrokerProtectionSubscriptionEventHandler.swift in Sources */,
B693954F26F04BEB0015B914 /* PaddedImageButton.swift in Sources */,
Expand Down Expand Up @@ -12771,8 +12777,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 144.0.0;
branch = fcappelli/pixelkit_invalid_name_fix;
kind = branch;
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "9906b9464f6f12e94f3cc62456b5b5a9c1a43db8",
"version" : "144.0.0"
"branch" : "fcappelli/pixelkit_invalid_name_fix",
"revision" : "d4751757763f7379e54bd7bafd1f7b0d10e8af13"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}

private func emailDidSignInNotification(_ notification: Notification) {
PixelKit.fire(GeneralPixel.emailEnabled)
PixelKit.fire(NonStandardEvent(NonStandardPixel.emailEnabled))
if AppDelegate.isNewUser {
PixelKit.fire(GeneralPixel.emailEnabledInitial, frequency: .legacyInitial)
}
Expand All @@ -543,7 +543,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}

private func emailDidSignOutNotification(_ notification: Notification) {
PixelKit.fire(GeneralPixel.emailDisabled)
PixelKit.fire(NonStandardEvent(NonStandardPixel.emailDisabled))
if let object = notification.object as? EmailManager, let emailManager = syncDataProviders.settingsAdapter.emailManager, object !== emailManager {
syncService?.scheduler.notifyDataChanged()
}
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ final class EmailOptionsButtonSubMenu: NSMenu {
let pixelParameters = self.emailManager.emailPixelParameters
self.emailManager.updateLastUseDate()

PixelKit.fire(GeneralPixel.emailUserCreatedAlias, withAdditionalParameters: pixelParameters)
PixelKit.fire(NonStandardEvent(NonStandardPixel.emailUserCreatedAlias), withAdditionalParameters: pixelParameters)

NSPasteboard.general.copy(address)
NotificationCenter.default.post(name: NSNotification.Name.privateEmailCopiedToClipboard, object: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class PrivacyDashboardViewController: NSViewController {

private let brokenSiteReporter: BrokenSiteReporter = {
BrokenSiteReporter(pixelHandler: { parameters in
PixelKit.fire(GeneralPixel.brokenSiteReport,
PixelKit.fire(NonStandardEvent(NonStandardPixel.brokenSiteReport),
withAdditionalParameters: parameters,
allowedQueryReservedCharacters: BrokenSiteReport.allowedQueryReservedCharacters)
}, keyValueStoring: UserDefaults.standard)
Expand Down
17 changes: 0 additions & 17 deletions DuckDuckGo/Statistics/GeneralPixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import Configuration
enum GeneralPixel: PixelKitEventV2 {

case crash
case brokenSiteReport
case compileRulesWait(onboardingShown: OnboardingShown, waitTime: CompileRulesWaitTime, result: WaitResult)
case launchInitial(cohort: String)

Expand Down Expand Up @@ -55,12 +54,6 @@ enum GeneralPixel: PixelKitEventV2 {
case adClickAttributionActive
case adClickAttributionPageLoads

case emailEnabled
case emailDisabled
case emailUserPressedUseAddress
case emailUserPressedUseAlias
case emailUserCreatedAlias

case jsPixel(_ pixel: AutofillUserScript.JSPixel)

// Activation Points
Expand Down Expand Up @@ -321,9 +314,6 @@ enum GeneralPixel: PixelKitEventV2 {
case .crash:
return "m_mac_crash"

case .brokenSiteReport:
return "epbf_macos_desktop"

case .compileRulesWait(onboardingShown: let onboardingShown, waitTime: let waitTime, result: let result):
return "m_mac_cbr-wait_\(onboardingShown)_\(waitTime)_\(result)"

Expand Down Expand Up @@ -371,13 +361,6 @@ enum GeneralPixel: PixelKitEventV2 {
case .adClickAttributionPageLoads:
return "m_mac_ad_click_page_loads"

// Deliberately omit the `m_mac_` prefix in order to format these pixels the same way as other platforms
case .emailEnabled: return "email_enabled_macos_desktop"
case .emailDisabled: return "email_disabled_macos_desktop"
case .emailUserPressedUseAddress: return "email_filled_main_macos_desktop"
case .emailUserPressedUseAlias: return "email_filled_random_macos_desktop"
case .emailUserCreatedAlias: return "email_generated_button_macos_desktop"

case .jsPixel(let pixel):
// Email pixels deliberately avoid using the `m_mac_` prefix.
if pixel.isEmailPixel {
Expand Down
53 changes: 53 additions & 0 deletions DuckDuckGo/Statistics/NonStandardPixel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// NonStandardPixel.swift
//
// Copyright © 2024 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 Foundation
import PixelKit
import BrowserServicesKit
import DDGSync
import Configuration

/// These pixels deliberately omit the `m_mac_` prefix in order to format these pixel the same way as other platforms, they are sent unchanged
enum NonStandardPixel: PixelKitEventV2 {

case brokenSiteReport
case emailEnabled
case emailDisabled
case emailUserPressedUseAddress
case emailUserPressedUseAlias
case emailUserCreatedAlias

var name: String {
switch self {
case .brokenSiteReport: return "epbf_macos_desktop"
case .emailEnabled: return "email_enabled_macos_desktop"
case .emailDisabled: return "email_disabled_macos_desktop"
case .emailUserPressedUseAddress: return "email_filled_main_macos_desktop"
case .emailUserPressedUseAlias: return "email_filled_random_macos_desktop"
case .emailUserCreatedAlias: return "email_generated_button_macos_desktop"
}
}

var parameters: [String: String]? {
return nil
}

var error: Error? {
return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class BrokenSiteReportingReferenceTests: XCTestCase {
APIRequest.Headers.setUserAgent("")
var params = parameters
params["test"] = "1"
let configuration = APIRequest.Configuration(url: URL.pixelUrl(forPixelNamed: GeneralPixel.brokenSiteReport.name),
let configuration = APIRequest.Configuration(url: URL.pixelUrl(forPixelNamed: NonStandardPixel.brokenSiteReport.name),
queryParameters: params,
allowedQueryReservedCharacters: BrokenSiteReport.allowedQueryReservedCharacters)
return configuration.request
Expand Down
13 changes: 11 additions & 2 deletions UnitTests/WebsiteBreakageReport/WebsiteBreakageReportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@

import PrivacyDashboard
import XCTest

import PixelKit
import PixelKitTestingUtilities
@testable import DuckDuckGo_Privacy_Browser
@testable import Networking

class WebsiteBreakageReportTests: XCTestCase {

func testReportBrokenSitePixel() {
fire(NonStandardEvent(NonStandardPixel.brokenSiteReport),
frequency: .standard,
and: .expect(pixelName: "epbf_macos_desktop"),
file: #filePath,
line: #line)
}

func testCommonSetOfFields() throws {
let breakage = BrokenSiteReport(
siteUrl: URL(string: "https://example.test/")!,
Expand Down Expand Up @@ -129,7 +138,7 @@ class WebsiteBreakageReportTests: XCTestCase {
APIRequest.Headers.setUserAgent("")
var params = parameters
params["test"] = "1"
let configuration = APIRequest.Configuration(url: URL.pixelUrl(forPixelNamed: GeneralPixel.brokenSiteReport.name),
let configuration = APIRequest.Configuration(url: URL.pixelUrl(forPixelNamed: NonStandardPixel.brokenSiteReport.name),
queryParameters: params,
allowedQueryReservedCharacters: BrokenSiteReport.allowedQueryReservedCharacters)
return configuration.request
Expand Down

0 comments on commit dbb2a13

Please sign in to comment.