-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Lock Screen Widgets: Add Tracks #21533
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ff44fd5
Group widget kind constants into enum
staskus 601c12f
Refactor widgets to use Kind enum
staskus b8f5918
Refactor StatsWidgets tracks to use Kind enum
staskus 6cb627b
Add track events for all the widget kinds
staskus 6f74d1c
Merge branch 'trunk' into task/21531-lock-screen-widgets-update-tracks
staskus 9916551
Log Widget Tracks events to Console for easier tracking
staskus 6b88167
Do not track widget type properties for lock screen widgets
staskus 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
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
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 |
|---|---|---|
|
|
@@ -5,44 +5,40 @@ import WidgetKit | |
| /// | ||
| extension Tracks { | ||
|
|
||
| func trackWidgetUpdatedIfNeeded(entry: LockScreenStatsWidgetEntry<some HomeWidgetData>, widgetKind: String, widgetCountKey: String) { | ||
| func trackWidgetUpdatedIfNeeded(entry: LockScreenStatsWidgetEntry<some HomeWidgetData>, widgetKind: AppConfiguration.Widget.Stats.Kind) { | ||
| switch entry { | ||
| case .siteSelected(_, let context): | ||
| if !context.isPreview { | ||
| trackWidgetUpdated(widgetKind: widgetKind, | ||
| widgetCountKey: widgetCountKey) | ||
| trackWidgetUpdated(widgetKind: widgetKind) | ||
| } | ||
|
|
||
| case .loggedOut, .noSite, .noData: | ||
| trackWidgetUpdated(widgetKind: widgetKind, | ||
| widgetCountKey: widgetCountKey) | ||
| trackWidgetUpdated(widgetKind: widgetKind) | ||
| } | ||
| } | ||
|
|
||
| func trackWidgetUpdatedIfNeeded(entry: StatsWidgetEntry, widgetKind: String, widgetCountKey: String) { | ||
| func trackWidgetUpdatedIfNeeded(entry: StatsWidgetEntry, widgetKind: AppConfiguration.Widget.Stats.Kind) { | ||
| switch entry { | ||
| case .siteSelected(_, let context): | ||
| if !context.isPreview { | ||
| trackWidgetUpdated(widgetKind: widgetKind, | ||
| widgetCountKey: widgetCountKey) | ||
| trackWidgetUpdated(widgetKind: widgetKind) | ||
| } | ||
|
|
||
| case .loggedOut, .noSite, .noData, .disabled: | ||
| trackWidgetUpdated(widgetKind: widgetKind, | ||
| widgetCountKey: widgetCountKey) | ||
| trackWidgetUpdated(widgetKind: widgetKind) | ||
| } | ||
| } | ||
|
|
||
| func trackWidgetUpdated(widgetKind: String, widgetCountKey: String) { | ||
| func trackWidgetUpdated(widgetKind: AppConfiguration.Widget.Stats.Kind) { | ||
|
|
||
| DispatchQueue.global().async { | ||
| WidgetCenter.shared.getCurrentConfigurations { result in | ||
|
|
||
| switch result { | ||
|
|
||
| case .success(let widgetInfo): | ||
| let widgetKindInfo = widgetInfo.filter { $0.kind == widgetKind } | ||
| self.trackUpdatedWidgetInfo(widgetInfo: widgetKindInfo, widgetPropertiesKey: widgetCountKey) | ||
| let widgetKindInfo = widgetInfo.filter { $0.kind == widgetKind.rawValue } | ||
| self.trackUpdatedWidgetInfo(widgetInfo: widgetKindInfo, widgetKind: widgetKind) | ||
|
|
||
| case .failure(let error): | ||
| DDLogError("Home Widget Today error: unable to read widget information. \(error.localizedDescription)") | ||
|
|
@@ -51,14 +47,19 @@ extension Tracks { | |
| } | ||
| } | ||
|
|
||
| private func trackUpdatedWidgetInfo(widgetInfo: [WidgetInfo], widgetPropertiesKey: String) { | ||
| private func trackUpdatedWidgetInfo(widgetInfo: [WidgetInfo], widgetKind: AppConfiguration.Widget.Stats.Kind) { | ||
| let widgetPropertiesKey = widgetKind.countKey | ||
|
|
||
| var properties = ["total_widgets": widgetInfo.count, | ||
| var properties: [String: Int] = [:] | ||
|
|
||
| switch widgetKind { | ||
| case .homeToday, .homeThisWeek, .homeAllTime: | ||
| properties = ["total_widgets": widgetInfo.count, | ||
| "small_widgets": widgetInfo.filter { $0.family == .systemSmall }.count, | ||
| "medium_widgets": widgetInfo.filter { $0.family == .systemMedium }.count, | ||
| "large_widgets": widgetInfo.filter { $0.family == .systemLarge }.count] | ||
| if #available(iOS 16.0, *) { | ||
| properties["rectangular_widgets"] = widgetInfo.filter { $0.family == .accessoryRectangular }.count | ||
| default: | ||
| break | ||
| } | ||
|
|
||
| let previousProperties = UserDefaults(suiteName: WPAppGroupName)?.object(forKey: widgetPropertiesKey) as? [String: Int] | ||
|
|
@@ -69,7 +70,7 @@ extension Tracks { | |
|
|
||
| UserDefaults(suiteName: WPAppGroupName)?.set(properties, forKey: widgetPropertiesKey) | ||
|
|
||
| trackExtensionEvent(ExtensionEvents.widgetUpdated(for: widgetPropertiesKey), properties: properties as [String: AnyObject]?) | ||
| trackExtensionEvent(ExtensionEvents.widgetUpdated(for: widgetKind), properties: properties as [String: AnyObject]?) | ||
| } | ||
|
|
||
| // MARK: - Private Helpers | ||
|
|
@@ -82,29 +83,37 @@ extension Tracks { | |
| // MARK: - Private Enums | ||
|
|
||
| fileprivate enum ExtensionEvents: String { | ||
| // User installs an instance of the today widget | ||
| case todayWidgetUpdated = "today_home_extension_widget_updated" | ||
| // User installs an instance of the all time widget | ||
| case allTimeWidgetUpdated = "alltime_home_extension_widget_updated" | ||
| // Users installs an instance of the this week widget | ||
| case thisWeekWidgetUpdated = "thisweek_home_extension_widget_updated" | ||
| // Users installs an instance of the lockscreen today views widget | ||
| case todayViewsLockScreenWidgetUpdated = "today_views_lockscreen_extension_widget_updated" | ||
|
|
||
| case noEvent | ||
|
|
||
| static func widgetUpdated(for key: String) -> ExtensionEvents { | ||
| switch key { | ||
| case AppConfiguration.Widget.Stats.todayProperties: | ||
| return .todayWidgetUpdated | ||
| case AppConfiguration.Widget.Stats.allTimeProperties: | ||
| return .allTimeWidgetUpdated | ||
| case AppConfiguration.Widget.Stats.thisWeekProperties: | ||
| return .thisWeekWidgetUpdated | ||
| case AppConfiguration.Widget.Stats.lockScreenTodayViewsProperties: | ||
| return .todayViewsLockScreenWidgetUpdated | ||
| default: | ||
| return .noEvent | ||
|
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. This is one of the reasons of this refactoring. I want switch to happen on a type, such as |
||
| // Events when user installs an instance of the widget | ||
| case homeTodayWidgetUpdated = "today_home_extension_widget_updated" | ||
| case homeAllTimeWidgetUpdated = "alltime_home_extension_widget_updated" | ||
| case homeThisWeekWidgetUpdated = "thisweek_home_extension_widget_updated" | ||
| case lockScreenTodayViewsWidgetUpdated = "today_views_lockscreen_widget_updated" | ||
| case lockScreenTodayLikesCommentsWidgetUpdated = "today_likes_comments_lockscreen_widget_updated" | ||
| case lockScreenTodayViewsVisitorsWidgetUpdated = "today_views_visitors_lockscreen_widget_updated" | ||
| case lockScreenAllTimeViewsWidgetUpdated = "all_time_views_lockscreen_widget_updated" | ||
| case lockScreenAllTimeViewsVisitorsWidgetUpdated = "all_time_views_visitors_lockscreen_widget_updated" | ||
| case lockScreenAllTimePostsBestViewsWidgetUpdated = "all_time_posts_best_views_lockscreen_widget_updated" | ||
|
|
||
| static func widgetUpdated(for widgetKind: AppConfiguration.Widget.Stats.Kind) -> ExtensionEvents { | ||
| switch widgetKind { | ||
| case .homeToday: | ||
| return .homeTodayWidgetUpdated | ||
| case .homeAllTime: | ||
| return .homeAllTimeWidgetUpdated | ||
| case .homeThisWeek: | ||
| return .homeThisWeekWidgetUpdated | ||
| case .lockScreenTodayViews: | ||
| return .lockScreenTodayViewsWidgetUpdated | ||
| case .lockScreenTodayLikesComments: | ||
| return .lockScreenTodayLikesCommentsWidgetUpdated | ||
| case .lockScreenTodayViewsVisitors: | ||
| return .lockScreenTodayViewsVisitorsWidgetUpdated | ||
| case .lockScreenAllTimeViews: | ||
| return .lockScreenAllTimeViewsWidgetUpdated | ||
| case .lockScreenAllTimeViewsVisitors: | ||
| return .lockScreenAllTimeViewsVisitorsWidgetUpdated | ||
| case .lockScreenAllTimePostsBestViews: | ||
| return .lockScreenAllTimePostsBestViewsWidgetUpdated | ||
| } | ||
| } | ||
| } | ||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.