diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Blaze/DashboardBlazeCardCell.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Blaze/DashboardBlazeCardCell.swift index 083adbbbbb81..b2c1b4419761 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Blaze/DashboardBlazeCardCell.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Blaze/DashboardBlazeCardCell.swift @@ -31,25 +31,29 @@ final class DashboardBlazeCardCell: DashboardCollectionViewCell { switch viewModel.state { case .promo: let cardView = DashboardBlazePromoCardView(.make(with: blog, viewController: viewController)) - self.setCardView(cardView, subtype: .promo) + self.setCardView(cardView, subtype: .promo, blog: blog) case .campaign(let campaign): let cardView = DashboardBlazeCampaignsCardView() cardView.configure(blog: blog, viewController: viewController, campaign: campaign) - self.setCardView(cardView, subtype: .campaigns) + self.setCardView(cardView, subtype: .campaigns, blog: blog) } } - private func setCardView(_ cardView: UIView, subtype: DashboardBlazeCardSubtype) { + private func setCardView(_ cardView: UIView, subtype: DashboardBlazeCardSubtype, blog: Blog) { contentView.subviews.forEach { $0.removeFromSuperview() } cardView.translatesAutoresizingMaskIntoConstraints = false contentView.addSubview(cardView) contentView.pinSubviewToAllEdges(cardView, priority: UILayoutPriority(999)) - BlogDashboardAnalytics.shared.track(.dashboardCardShown, properties: [ - "type": DashboardCard.blaze.rawValue, - "sub_type": subtype.rawValue - ]) + BlogDashboardAnalytics.shared.track( + .dashboardCardShown, + properties: [ + "type": DashboardCard.blaze.rawValue, + "sub_type": subtype.rawValue + ], + blog: blog + ) } } diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Posts/DashboardPostsListCardCell.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Posts/DashboardPostsListCardCell.swift index 9319c38e3d00..286c93fb7c77 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Posts/DashboardPostsListCardCell.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Posts/DashboardPostsListCardCell.swift @@ -74,10 +74,6 @@ class DashboardPostsListCardCell: UICollectionViewCell, Reusable { contentView.addSubview(frameView) contentView.pinSubviewToAllEdges(frameView, priority: UILayoutPriority(999)) } - - func trackPostsDisplayed() { - BlogDashboardAnalytics.shared.track(.dashboardCardShown, properties: ["type": "post", "sub_type": status.rawValue]) - } } // MARK: BlogDashboardCardConfigurable diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Posts/PostsCardViewModel.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Posts/PostsCardViewModel.swift index 1f0ba85d29db..e1b6c64610ed 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Posts/PostsCardViewModel.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Posts/PostsCardViewModel.swift @@ -262,9 +262,9 @@ private extension PostsCardViewModel { func trackCardDisplayedIfNeeded() { switch currentState { case .posts: - BlogDashboardAnalytics.shared.track(.dashboardCardShown, properties: ["type": "post", "sub_type": status.rawValue]) + BlogDashboardAnalytics.shared.track(.dashboardCardShown, properties: ["type": "post", "sub_type": status.rawValue], blog: blog) case .error: - BlogDashboardAnalytics.shared.track(.dashboardCardShown, properties: ["type": "post", "sub_type": "error"]) + BlogDashboardAnalytics.shared.track(.dashboardCardShown, properties: ["type": "post", "sub_type": "error"], blog: blog) case .loading: return } diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Helpers/BlogDashboardAnalytics.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Helpers/BlogDashboardAnalytics.swift index ff74e743de9c..bf1d8dd2d6c0 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Helpers/BlogDashboardAnalytics.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Helpers/BlogDashboardAnalytics.swift @@ -17,19 +17,18 @@ class BlogDashboardAnalytics { /// This will track the given event and properties given they haven't been /// triggered before. /// + /// The My Site dashboard always shows exactly one site, so every card-shown + /// event carries that site. `blog` is required so the site identifier is + /// always attached and no future card can regress by omitting it. + /// /// - Parameters: /// - event: a `String` that represents the event name /// - properties: a `Hash` that represents the properties - /// - blog: a `Blog` asssociated with the event - func track(_ event: WPAnalyticsEvent, properties: [AnyHashable: String] = [:], blog: Blog? = nil) { + /// - blog: the `Blog` whose dashboard is being shown + func track(_ event: WPAnalyticsEvent, properties: [AnyHashable: String] = [:], blog: Blog) { if !fired.contains(where: { $0 == (event, properties) }) { fired.append((event, properties)) - - if let blog { - WPAnalytics.track(event, properties: properties, blog: blog) - } else { - WPAnalytics.track(event, properties: properties) - } + WPAnalytics.track(event, properties: properties, blog: blog) } }