Skip to content

Commit

Permalink
Track prompts dashboard card events
Browse files Browse the repository at this point in the history
  • Loading branch information
wargcm committed May 26, 2022
1 parent f2e1cb5 commit d8528bc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
17 changes: 16 additions & 1 deletion WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ import Foundation
case promptsIntroductionModalTryItNow
case promptsIntroductionModalRemindMe
case promptsIntroductionModalGotIt

case promptsDashboardCardAnswerPrompt
case promptsDashboardCardMenu
case promptsDashboardCardMenuViewMore
case promptsDashboardCardMenuSkip
case promptsDashboardCardMenuRemove

/// A String that represents the event
var value: String {
Expand Down Expand Up @@ -966,6 +970,17 @@ import Foundation
return "blogging_prompts_introduction_modal_remind_me_tapped"
case .promptsIntroductionModalGotIt:
return "blogging_prompts_introduction_modal_got_it_tapped"
case .promptsDashboardCardAnswerPrompt:
return "blogging_prompts_my_site_card_answer_prompt_tapped"
case .promptsDashboardCardMenu:
return "blogging_prompts_my_site_card_menu_tapped"
case .promptsDashboardCardMenuViewMore:
return "blogging_prompts_my_site_card_menu_view_more_prompts_tapped"
case .promptsDashboardCardMenuSkip:
return "blogging_prompts_my_site_card_menu_skip_this_prompt_tapped"
case .promptsDashboardCardMenuRemove:
return "blogging_prompts_my_site_card_menu_remove_from_dashboard_tapped"

} // END OF SWITCH
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ class DashboardPromptsCardCell: UICollectionViewCell, Reusable {
frameView.title = Strings.cardFrameTitle
frameView.icon = Style.frameIconImage

// NOTE: Remove the logic for iOS 13 once we drop that version.
if #available (iOS 14.0, *) {
// NOTE: Remove the logic when support for iOS 14 is dropped
if #available (iOS 15.0, *) {
// assign an empty closure so the button appears.
frameView.onEllipsisButtonTap = {}
frameView.ellipsisButton.showsMenuAsPrimaryAction = true
frameView.ellipsisButton.menu = contextMenu
} else {
// Show a fallback implementation using `MenuSheetViewController`.
// iOS 13 doesn't support showing UIMenu programmatically.
// iOS 14 doesn't support `UIDeferredMenuElement.uncached`.
frameView.onEllipsisButtonTap = { [weak self] in
self?.showMenuSheet()
}
Expand Down Expand Up @@ -291,9 +292,16 @@ class DashboardPromptsCardCell: UICollectionViewCell, Reusable {
return [defaultItems]
}

@available(iOS 15.0, *)
private var contextMenu: UIMenu {
return .init(title: String(), options: .displayInline, children: contextMenuItems.map { menuSection in
UIMenu(title: String(), options: .displayInline, children: menuSection.map { $0.toAction })
UIMenu(title: String(), options: .displayInline, children: [
// Use an uncached deferred element so we can track each time the menu is shown
UIDeferredMenuElement.uncached { completion in
WPAnalytics.track(.promptsDashboardCardMenu)
completion(menuSection.map { $0.toAction })
}
])
})
}

Expand Down Expand Up @@ -418,6 +426,7 @@ private extension DashboardPromptsCardCell {
let prompt = prompt else {
return
}
WPAnalytics.track(.promptsDashboardCardAnswerPrompt)

let editor = EditPostViewController(blog: blog, prompt: prompt)
editor.modalPresentationStyle = .fullScreen
Expand All @@ -434,15 +443,18 @@ private extension DashboardPromptsCardCell {
return
}

WPAnalytics.track(.promptsDashboardCardMenuViewMore)
BloggingPromptsViewController.show(for: blog, from: presenterViewController)
}

func skipMenuTapped() {
WPAnalytics.track(.promptsDashboardCardMenuSkip)
saveSkippedPromptForSite()
presenterViewController?.reloadCardsLocally()
}

func removeMenuTapped() {
WPAnalytics.track(.promptsDashboardCardMenuRemove)
// TODO.
}

Expand All @@ -451,6 +463,7 @@ private extension DashboardPromptsCardCell {
guard let presenterViewController = presenterViewController else {
return
}
WPAnalytics.track(.promptsDashboardCardMenu)

let menuViewController = MenuSheetViewController(items: contextMenuItems.map { menuSection in
menuSection.map { $0.toMenuSheetItem }
Expand Down

0 comments on commit d8528bc

Please sign in to comment.