-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send daily pixel with open tabs count (#3587)
Task/Issue URL: https://app.asana.com/0/1206226850447395/1208014614013438/f Tech Design URL: CC: **Description**: Adds a daily pixel with number of total open tabs and number of new tabs when Tab switcher is opened. **Steps to test this PR**: 1. Modify `DailyPixel.hasBeenFiredToday` to always return `false`. 2. Open a bunch of tabs including a few new tabs. 3. Check Pixel is fired when opening tab switcher containing tabs count buckets that are in line with https://app.asana.com/0/1206226850447395/1208014614013438/f. **Definition of Done (Internal Only)**: * [ ] Does this PR satisfy our [Definition of Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)? --- ###### Internal references: [Software Engineering Expectations](https://app.asana.com/0/59792373528535/199064865822552) [Technical Design Template](https://app.asana.com/0/59792373528535/184709971311943)
- Loading branch information
Showing
5 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// TabSwitcherOpenDailyPixel.swift | ||
// DuckDuckGo | ||
// | ||
// 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 | ||
|
||
struct TabSwitcherOpenDailyPixel { | ||
func parameters(with tabs: [Tab]) -> [String: String] { | ||
var parameters = [String: String]() | ||
|
||
parameters[ParameterName.tabCount] = tabCountBucket(for: tabs) | ||
parameters[ParameterName.newTabCount] = newTabCountBucket(for: tabs) | ||
|
||
return parameters | ||
} | ||
|
||
private func tabCountBucket(for tabs: [Tab]) -> String? { | ||
let count = tabs.count | ||
|
||
switch count { | ||
case 0: return nil | ||
case 1...1: return "1" | ||
case 2...5: return "2-5" | ||
case 6...10: return "6-10" | ||
case 11...20: return "11-20" | ||
case 21...40: return "21-40" | ||
case 41...60: return "41-60" | ||
case 61...80: return "61-80" | ||
case 81...100: return "81-100" | ||
case 101...125: return "101-125" | ||
case 126...150: return "126-150" | ||
case 151...250: return "151-250" | ||
case 251...500: return "251-500" | ||
default: return "501+" | ||
} | ||
|
||
} | ||
|
||
private func newTabCountBucket(for tabs: [Tab]) -> String? { | ||
let count = tabs.count { $0.link == nil } | ||
|
||
switch count { | ||
case 0...1: return "0-1" | ||
case 2...10: return "2-10" | ||
default: return "11+" | ||
} | ||
} | ||
|
||
private enum ParameterName { | ||
static let tabCount = "tab_count" | ||
static let newTabCount = "new_tab_count" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// TabSwitcherDailyPixelTests.swift | ||
// DuckDuckGo | ||
// | ||
// 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 XCTest | ||
import Core | ||
@testable import DuckDuckGo | ||
|
||
final class TabSwitcherDailyPixelTests: XCTestCase { | ||
func testPopulatesParameters() { | ||
let tabs = [Tab(), Tab(), Tab()] | ||
let pixel = TabSwitcherOpenDailyPixel() | ||
|
||
let parameters = pixel.parameters(with: tabs) | ||
|
||
XCTAssertNotNil(parameters[ParameterName.tabCount]) | ||
XCTAssertNotNil(parameters[ParameterName.newTabCount]) | ||
} | ||
|
||
func testIncludesProperCountsForParameters() { | ||
let tabs = [Tab(), Tab(), .mock()] | ||
let pixel = TabSwitcherOpenDailyPixel() | ||
|
||
let parameters = pixel.parameters(with: tabs) | ||
|
||
XCTAssertEqual(parameters[ParameterName.tabCount], "2-5") | ||
XCTAssertEqual(parameters[ParameterName.newTabCount], "2-10") | ||
} | ||
|
||
func testBucketsAggregation() { | ||
let bucketValues = [ | ||
1...1: "1", | ||
2...5: "2-5", | ||
6...10: "6-10", | ||
11...20: "11-20", | ||
21...40: "21-40", | ||
41...60: "41-60", | ||
61...80: "61-80", | ||
81...100: "81-100", | ||
101...125: "101-125", | ||
126...150: "126-150", | ||
151...250: "151-250", | ||
251...500: "251-500", | ||
501...504: "501+"] | ||
|
||
for bucket in bucketValues { | ||
for value in bucket.key { | ||
let tabs = Array(repeating: Tab.mock(), count: value) | ||
|
||
let countParameter = TabSwitcherOpenDailyPixel().parameters(with: tabs)[ParameterName.tabCount] | ||
|
||
XCTAssertEqual(countParameter, bucket.value) | ||
} | ||
} | ||
} | ||
|
||
func testNewTabBucketsAggregation() { | ||
let bucketValues = [ | ||
0...1: "0-1", | ||
2...10: "2-10", | ||
11...20: "11+"] | ||
|
||
for bucket in bucketValues { | ||
for value in bucket.key { | ||
let tabs = Array(repeating: Tab(), count: value) | ||
|
||
let countParameter = TabSwitcherOpenDailyPixel().parameters(with: tabs)[ParameterName.newTabCount] | ||
|
||
XCTAssertEqual(countParameter, bucket.value) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private extension Tab { | ||
static func mock() -> Tab { | ||
Tab(link: Link(title: nil, url: URL("https://example.com")!)) | ||
} | ||
} | ||
|
||
private enum ParameterName { | ||
static let newTabCount = "new_tab_count" | ||
static let tabCount = "tab_count" | ||
} |