-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add Ads tab #25145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kean
wants to merge
6
commits into
trunk
Choose a base branch
from
task/jetpack-stats-ads-tab
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−21
Open
Add Ads tab #25145
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8b9cdbd
Add initial AdsTabView
kean 455e2d9
Integrate Ads tab in SiteStatsDashboardViewController
kean e8eb00b
Fix how we check if the Ads module is enabled
kean edc7b9b
Simplify StatsMainView
kean c3b1812
Revert AdaptiveTabBar changes
kean b998d6f
Add FF
kean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,28 @@ | ||
| import SwiftUI | ||
|
|
||
| public struct AdsTabView: View { | ||
|
|
||
| public init() {} | ||
|
|
||
| public var body: some View { | ||
| ScrollView { | ||
| VStack(spacing: 16) { | ||
| Text("Ads") | ||
| .font(.largeTitle) | ||
| .fontWeight(.bold) | ||
| .padding(.top, 20) | ||
|
|
||
| Text("Coming Soon") | ||
| .font(.headline) | ||
| .foregroundColor(.secondary) | ||
|
|
||
| Spacer(minLength: 100) | ||
| } | ||
| .padding() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| AdsTabView() | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,11 +6,13 @@ import WordPressUI | |
| import Combine | ||
| import TipKit | ||
| import BuildSettingsKit | ||
| import JetpackStats | ||
|
|
||
| enum StatsTabType: Int, AdaptiveTabBarItem, CaseIterable { | ||
| case insights = 0 | ||
| case traffic | ||
| case subscribers | ||
| case ads | ||
|
|
||
| var id: StatsTabType { self } | ||
|
|
||
|
|
@@ -19,6 +21,7 @@ enum StatsTabType: Int, AdaptiveTabBarItem, CaseIterable { | |
| case .insights: return NSLocalizedString("Insights", comment: "Title of Insights stats filter.") | ||
| case .traffic: return NSLocalizedString("stats.dashboard.tab.traffic", value: "Traffic", comment: "Title of Traffic stats tab.") | ||
| case .subscribers: return NSLocalizedString("stats.dashboard.tab.subscribers", value: "Subscribers", comment: "Title of Subscribers stats tab.") | ||
| case .ads: return NSLocalizedString("stats.dashboard.tab.ads", value: "Ads", comment: "Title of Ads stats tab.") | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -30,35 +33,54 @@ enum StatsTabType: Int, AdaptiveTabBarItem, CaseIterable { | |
| self = .traffic | ||
| case "subscribers": | ||
| self = .subscribers | ||
| case "ads": | ||
| self = .ads | ||
| default: | ||
| return nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fileprivate extension StatsTabType { | ||
| static var displayedTabs: [StatsTabType] { | ||
| return [.traffic, .insights, .subscribers] | ||
| } | ||
|
|
||
| var analyticsAccessEvent: WPAnalyticsStat? { | ||
| switch self { | ||
| case .insights: return .statsInsightsAccessed | ||
| case .traffic: return nil | ||
| case .traffic: return nil | ||
| case .subscribers: return .statsSubscribersAccessed | ||
| case .ads: return nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public class SiteStatsDashboardViewController: UIViewController { | ||
| static let lastSelectedStatsDateKey = "LastSelectedStatsDate" | ||
|
|
||
| // MARK: - Helpers | ||
|
|
||
| /// Returns the current blog from SiteStatsInformation if available | ||
| private static func currentBlog() -> Blog? { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not ideal, but this is how this screen operates. I don't want to refactor it in the scope of this PR. |
||
| guard let siteID = SiteStatsInformation.sharedInstance.siteID, | ||
| let blog = Blog.lookup(withID: siteID, in: ContextManager.shared.mainContext) else { | ||
| return nil | ||
| } | ||
| return blog | ||
| } | ||
|
|
||
| // MARK: - Properties | ||
|
|
||
| private let containerView = UIView() | ||
|
|
||
| private var currentChildViewController: UIViewController? | ||
| private lazy var displayedTabs: [StatsTabType] = StatsTabType.displayedTabs | ||
| private lazy var displayedTabs: [StatsTabType] = { | ||
| var tabs: [StatsTabType] = [.traffic, .insights, .subscribers] | ||
|
|
||
| // Add Ads tab if feature flag is enabled and WordAds is active on the site | ||
| if FeatureFlag.statsAds.enabled, | ||
| let blog = Self.currentBlog(), | ||
| blog.isWordAdsActive() { | ||
| tabs.append(.ads) | ||
| } | ||
|
|
||
| return tabs | ||
| }() | ||
| private var tipObserver: TipObserver? | ||
| private var isUsingMockData = UITestConfigurator.isEnabled(.useMockData) | ||
| private var navigationItemObserver: NSKeyValueObservation? | ||
|
|
@@ -100,8 +122,7 @@ public class SiteStatsDashboardViewController: UIViewController { | |
| // Create with demo context for mock data | ||
| return StatsHostingViewController.makeNewTrafficViewController(blog: nil, parentViewController: self, isDemo: true) | ||
| } else { | ||
| guard let siteID = SiteStatsInformation.sharedInstance.siteID, | ||
| let blog = Blog.lookup(withID: siteID, in: ContextManager.shared.mainContext) else { | ||
| guard let blog = Self.currentBlog() else { | ||
| return nil | ||
| } | ||
| return StatsHostingViewController.makeNewTrafficViewController(blog: blog, parentViewController: self, isDemo: false) | ||
|
|
@@ -126,6 +147,13 @@ public class SiteStatsDashboardViewController: UIViewController { | |
| return StatsSubscribersViewController(viewModel: viewModel) | ||
| }() | ||
|
|
||
| private lazy var adsViewController: UIViewController = { | ||
| let adsView = AdsTabView() | ||
| let hostingController = UIHostingController(rootView: adsView) | ||
| hostingController.view.backgroundColor = .systemBackground | ||
| return hostingController | ||
| }() | ||
|
|
||
| // MARK: - View | ||
|
|
||
| deinit { | ||
|
|
@@ -183,6 +211,8 @@ public class SiteStatsDashboardViewController: UIViewController { | |
| self.showNewStatsTip() | ||
| } | ||
| } | ||
| case .ads: | ||
| parent?.navigationItem.rightBarButtonItem = nil | ||
| default: | ||
| parent?.navigationItem.rightBarButtonItem = nil | ||
| } | ||
|
|
@@ -358,7 +388,7 @@ private extension SiteStatsDashboardViewController { | |
| func setupFilterBar() { | ||
| wpAssert(parent != nil) | ||
| filterBarController.navigationItem = parent?.navigationItem | ||
| filterBarController.configure(StatsTabType.displayedTabs, in: self) { [weak self] in | ||
| filterBarController.configure(displayedTabs, in: self) { [weak self] in | ||
| self?.selectedFilterDidChange($0) | ||
| } | ||
| filterBarController.accessibilityIdentifier = "site-stats-dashboard-filter-bar" | ||
|
|
@@ -429,6 +459,10 @@ private extension SiteStatsDashboardViewController { | |
| } else { | ||
| subscribersViewController.refreshData() | ||
| } | ||
| case .ads: | ||
| if oldSelectedTab != .ads || containerIsEmpty { | ||
| showChildViewController(adsViewController) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not using it yet, but I decided to model it anyway since I spent a bit of time discovering it.