Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Foundation
@objc static let todayKind = "WordPressHomeWidgetToday"
@objc static let allTimeKind = "WordPressHomeWidgetAllTime"
@objc static let thisWeekKind = "WordPressHomeWidgetThisWeek"
@objc static let lockScreenTodayViewsProperties = "WordPressLockScreenWidgetTodayViewsProperties"
@objc static let todayProperties = "WordPressHomeWidgetTodayProperties"
@objc static let allTimeProperties = "WordPressHomeWidgetAllTimeProperties"
@objc static let thisWeekProperties = "WordPressHomeWidgetThisWeekProperties"
Expand Down
3 changes: 3 additions & 0 deletions WordPress/Classes/Utility/Universal Links/Route.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ enum DeepLinkSource: Equatable {
case banner
case email(campaign: String)
case widget
case lockScreenWidget
case inApp(presenter: UIViewController?)

init?(sourceName: String) {
Expand All @@ -102,6 +103,8 @@ enum DeepLinkSource: Equatable {
// add others in the future if necessary.
case "widget":
self = .widget
case "lockscreen_widget":
self = .lockScreenWidget
default:
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ extension DeepLinkSource {
return "email"
case .widget:
return "widget"
case .lockScreenWidget:
return "lockscreen_widget"
case .inApp:
return "internal"
}
Expand Down
1 change: 1 addition & 0 deletions WordPress/Jetpack/WidgetConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Foundation
@objc static let todayKind = "JetpackHomeWidgetToday"
@objc static let allTimeKind = "JetpackHomeWidgetAllTime"
@objc static let thisWeekKind = "JetpackHomeWidgetThisWeek"
@objc static let lockScreenTodayViewsProperties = "JetpackLockScreenWidgetTodayViewsProperties"
@objc static let todayProperties = "JetpackHomeWidgetTodayProperties"
@objc static let allTimeProperties = "JetpackHomeWidgetAllTimeProperties"
@objc static let thisWeekProperties = "JetpackHomeWidgetThisWeekProperties"
Expand Down
12 changes: 12 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2857,6 +2857,10 @@
C94C0B1B25DCFA0100F2F69B /* FilterableCategoriesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94C0B1A25DCFA0100F2F69B /* FilterableCategoriesViewController.swift */; };
C957C20626DCC1770037628F /* LandInTheEditorHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C957C20526DCC1770037628F /* LandInTheEditorHelper.swift */; };
C957C20726DCC1770037628F /* LandInTheEditorHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C957C20526DCC1770037628F /* LandInTheEditorHelper.swift */; };
C995C22229D306DD00ACEF43 /* URL+WidgetSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C995C22129D306DD00ACEF43 /* URL+WidgetSource.swift */; };
C995C22329D306E100ACEF43 /* URL+WidgetSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C995C22129D306DD00ACEF43 /* URL+WidgetSource.swift */; };
C995C22429D30A9900ACEF43 /* URL+WidgetSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C995C22129D306DD00ACEF43 /* URL+WidgetSource.swift */; };
C995C22629D30AB000ACEF43 /* WidgetUrlSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C995C22529D30AB000ACEF43 /* WidgetUrlSourceTests.swift */; };
C99B08FC26081AD600CA71EB /* TemplatePreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99B08FB26081AD600CA71EB /* TemplatePreviewViewController.swift */; };
C9B4778429C85949008CBF49 /* LockScreenStatsWidgetData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9B4778229C85948008CBF49 /* LockScreenStatsWidgetData.swift */; };
C9B4778529C85949008CBF49 /* LockScreenStatsWidgetData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9B4778229C85948008CBF49 /* LockScreenStatsWidgetData.swift */; };
Expand Down Expand Up @@ -8132,6 +8136,8 @@
C9264D275F6288F66C33D2CE /* Pods-WordPressTest.release-internal.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressTest.release-internal.xcconfig"; path = "../Pods/Target Support Files/Pods-WordPressTest/Pods-WordPressTest.release-internal.xcconfig"; sourceTree = "<group>"; };
C94C0B1A25DCFA0100F2F69B /* FilterableCategoriesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterableCategoriesViewController.swift; sourceTree = "<group>"; };
C957C20526DCC1770037628F /* LandInTheEditorHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LandInTheEditorHelper.swift; sourceTree = "<group>"; };
C995C22129D306DD00ACEF43 /* URL+WidgetSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+WidgetSource.swift"; sourceTree = "<group>"; };
C995C22529D30AB000ACEF43 /* WidgetUrlSourceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetUrlSourceTests.swift; sourceTree = "<group>"; };
C99B039B2602F3CB00CA71EB /* WordPress 117.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 117.xcdatamodel"; sourceTree = "<group>"; };
C99B08FB26081AD600CA71EB /* TemplatePreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplatePreviewViewController.swift; sourceTree = "<group>"; };
C9B4778229C85948008CBF49 /* LockScreenStatsWidgetData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LockScreenStatsWidgetData.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -15733,6 +15739,7 @@
children = (
C9FE382129C2040600D39841 /* HomeWidgetData+StatsURL.swift */,
C9B4778829C85956008CBF49 /* HomeWidgetData+LockScreenStatsWidgetData.swift */,
C995C22129D306DD00ACEF43 /* URL+WidgetSource.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -15762,6 +15769,7 @@
children = (
C9FE383629C2067E00D39841 /* WidgetsViewModelMapperTests.swift */,
C9B477AF29CC35C5008CBF49 /* WidgetDataReaderTests.swift */,
C995C22529D30AB000ACEF43 /* WidgetUrlSourceTests.swift */,
);
path = Widgets;
sourceTree = "<group>";
Expand Down Expand Up @@ -20532,6 +20540,7 @@
files = (
C9B4778729C85949008CBF49 /* LockScreenStatsWidgetEntry.swift in Sources */,
0107E0B428F97D5000DE87DB /* Constants.m in Sources */,
C995C22329D306E100ACEF43 /* URL+WidgetSource.swift in Sources */,
01CE5012290A890B00A9C2E0 /* TracksConfiguration.swift in Sources */,
C9C21D7C29BED18C009F68E5 /* LockScreenStatsWidgetsView.swift in Sources */,
C9FE382F29C204E700D39841 /* LockScreenSingleStatViewModel.swift in Sources */,
Expand Down Expand Up @@ -22010,6 +22019,7 @@
010459E629153FFF000C7778 /* JetpackNotificationMigrationService.swift in Sources */,
FAC1B82729B1F1EE00E0C542 /* BlazePostPreviewView.swift in Sources */,
E61084C21B9B47BA008050C5 /* ReaderTagTopic.swift in Sources */,
C995C22429D30A9900ACEF43 /* URL+WidgetSource.swift in Sources */,
F110239B2318479000C4E84A /* Media.swift in Sources */,
176CE91627FB44C100F1E32B /* StatsBaseCell.swift in Sources */,
E1C2260723901AAD0021D03C /* WordPressOrgRestApi+WordPress.swift in Sources */,
Expand Down Expand Up @@ -22412,6 +22422,7 @@
files = (
C9B4778629C85949008CBF49 /* LockScreenStatsWidgetEntry.swift in Sources */,
3F1FD30D2548B0A80060C53A /* Constants.m in Sources */,
C995C22229D306DD00ACEF43 /* URL+WidgetSource.swift in Sources */,
01CE500C290A88BF00A9C2E0 /* TracksConfiguration.swift in Sources */,
C9C21D7B29BED18C009F68E5 /* LockScreenStatsWidgetsView.swift in Sources */,
C9FE382E29C204E700D39841 /* LockScreenSingleStatViewModel.swift in Sources */,
Expand Down Expand Up @@ -23215,6 +23226,7 @@
DC13DB7E293FD09F00E33561 /* StatsInsightsStoreTests.swift in Sources */,
ACACE3AE28D729FA000992F9 /* NoResultsViewControllerTests.swift in Sources */,
8BFE36FF230F1C850061EBA8 /* AbstractPost+fixLocalMediaURLsTests.swift in Sources */,
C995C22629D30AB000ACEF43 /* WidgetUrlSourceTests.swift in Sources */,
08A2AD791CCED2A800E84454 /* PostTagServiceTests.m in Sources */,
F543AF5723A84E4D0022F595 /* PublishSettingsControllerTests.swift in Sources */,
027AC5212278983F0033E56E /* DomainCreditEligibilityTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ extension HomeWidgetTodayData {
static let statsUrl = "https://wordpress.com/stats/day/"

var statsURL: URL? {
URL(string: Self.statsUrl + "\(siteID)?source=widget")
URL(string: Self.statsUrl + "\(siteID)")
}
}

extension HomeWidgetAllTimeData {
static let statsUrl = "https://wordpress.com/stats/insights/"

var statsURL: URL? {
URL(string: Self.statsUrl + "\(siteID)?source=widget")
URL(string: Self.statsUrl + "\(siteID)")
}
}

extension HomeWidgetThisWeekData {
static let statsUrl = "https://wordpress.com/stats/week/"

var statsURL: URL? {
URL(string: Self.statsUrl + "\(siteID)?source=widget")
URL(string: Self.statsUrl + "\(siteID)")
}
}
17 changes: 17 additions & 0 deletions WordPress/WordPressStatsWidgets/Extensions/URL+WidgetSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Foundation

enum WidgetUrlSource: String {
case homeScreenWidget = "widget"
case lockScreenWidget = "lockscreen_widget"
}

extension URL {
func appendingSource(_ source: WidgetUrlSource) -> URL {
var components = URLComponents(url: self, resolvingAgainstBaseURL: false)
var queryItems = components?.queryItems ?? []
let sourceQuery = URLQueryItem(name: "source", value: source.rawValue)
queryItems.append(sourceQuery)
components?.queryItems = queryItems
return components?.url ?? self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ protocol LockScreenStatsWidgetConfig {
var displayName: String { get }
var description: String { get }
var kind: String { get }
var countKey: String { get }
var placeholderContent: WidgetData { get }
var viewProvider: ViewProvider { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ struct LockScreenTodayViewsStatWidgetConfig: LockScreenStatsWidgetConfig {
AppConfiguration.Widget.Stats.lockScreenTodayViewsKind
}

var countKey: String {
AppConfiguration.Widget.Stats.lockScreenTodayViewsProperties
}

var placeholderContent: HomeWidgetTodayData {
HomeWidgetTodayData(
siteID: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SwiftUI

@available(iOS 16.0, *)
struct LockScreenStatsWidget<T: LockScreenStatsWidgetConfig>: Widget {
private let tracks = Tracks(appGroupName: WPAppGroupName)
private let config: T

init(config: T) {
Expand All @@ -23,6 +24,11 @@ struct LockScreenStatsWidget<T: LockScreenStatsWidgetConfig>: Widget {
placeholderContent: config.placeholderContent
)
) { (entry: LockScreenStatsWidgetEntry) -> LockScreenStatsWidgetsView in
defer {
tracks.trackWidgetUpdatedIfNeeded(entry: entry,
widgetKind: config.kind,
widgetCountKey: config.countKey)
}
return LockScreenStatsWidgetsView(
timelineEntry: entry,
viewProvider: config.viewProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct LockScreenStatsWidgetsView<T: LockScreenStatsWidgetsViewProvider>: View {
case let .siteSelected(data, _):
viewProvider
.buildSiteSelectedView(data)
.widgetURL(data.statsURL)
.widgetURL(data.statsURL?.appendingSource(.lockScreenWidget))
case .loggedOut:
viewProvider
.buildLoggedOutView()
Expand Down
23 changes: 22 additions & 1 deletion WordPress/WordPressStatsWidgets/Tracks/Tracks+StatsWidgets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ import WidgetKit
///
extension Tracks {

func trackWidgetUpdatedIfNeeded(entry: LockScreenStatsWidgetEntry, widgetKind: String, widgetCountKey: String) {
switch entry {
case .siteSelected(_, let context):
if !context.isPreview {
trackWidgetUpdated(widgetKind: widgetKind,
widgetCountKey: widgetCountKey)
}

case .loggedOut, .noSite, .noData:
trackWidgetUpdated(widgetKind: widgetKind,
widgetCountKey: widgetCountKey)
}
}

func trackWidgetUpdatedIfNeeded(entry: StatsWidgetEntry, widgetKind: String, widgetCountKey: String) {
switch entry {
case .siteSelected(_, let context):
Expand Down Expand Up @@ -39,10 +53,13 @@ extension Tracks {

private func trackUpdatedWidgetInfo(widgetInfo: [WidgetInfo], widgetPropertiesKey: String) {

let properties = ["total_widgets": widgetInfo.count,
var 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
}

let previousProperties = UserDefaults(suiteName: WPAppGroupName)?.object(forKey: widgetPropertiesKey) as? [String: Int]

Expand Down Expand Up @@ -71,6 +88,8 @@ extension Tracks {
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

Expand All @@ -82,6 +101,8 @@ extension Tracks {
return .allTimeWidgetUpdated
case AppConfiguration.Widget.Stats.thisWeekProperties:
return .thisWeekWidgetUpdated
case AppConfiguration.Widget.Stats.lockScreenTodayViewsProperties:
return .todayViewsLockScreenWidgetUpdated
default:
return .noEvent
}
Expand Down
6 changes: 3 additions & 3 deletions WordPress/WordPressStatsWidgets/Views/StatsWidgetsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct StatsWidgetsView: View {

case .disabled(let kind):
UnconfiguredView(timelineEntry: timelineEntry)
.widgetURL(kind.statsURL)
.widgetURL(kind.statsURL?.appendingSource(.homeScreenWidget))
case .loggedOut, .noSite, .noData:
UnconfiguredView(timelineEntry: timelineEntry)
.widgetURL(nil)
Expand All @@ -25,12 +25,12 @@ struct StatsWidgetsView: View {

case .systemSmall:
SingleStatView(viewData: viewData)
.widgetURL(viewData.statsURL)
.widgetURL(viewData.statsURL?.appendingSource(.homeScreenWidget))
.padding()

case .systemMedium:
MultiStatsView(viewData: viewData)
.widgetURL(viewData.statsURL)
.widgetURL(viewData.statsURL?.appendingSource(.homeScreenWidget))
.padding()

default:
Expand Down
28 changes: 28 additions & 0 deletions WordPress/WordPressTest/Widgets/WidgetUrlSourceTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import XCTest
@testable import WordPress

final class WidgetUrlSourceTests: XCTestCase {
func testHomeScreenWidgetSource() throws {
let url = try XCTUnwrap(URL(string: "https://test"))
let widgetUrl = url.appendingSource(.homeScreenWidget)
XCTAssertEqual(widgetUrl.absoluteString, "https://test?source=widget")
}

func testLockScreenWidgetSource() throws {
let url = try XCTUnwrap(URL(string: "https://test"))
let widgetUrl = url.appendingSource(.lockScreenWidget)
XCTAssertEqual(widgetUrl.absoluteString, "https://test?source=lockscreen_widget")
}

func testHomeScreenWidgetSourceType() {
let source = WidgetUrlSource.homeScreenWidget.rawValue
let deepLinkSource = DeepLinkSource(sourceName: source)
XCTAssertEqual(deepLinkSource, .widget)
}

func testLockScreenWidgetSourceType() {
let source = WidgetUrlSource.lockScreenWidget.rawValue
let deepLinkSource = DeepLinkSource(sourceName: source)
XCTAssertEqual(deepLinkSource, .lockScreenWidget)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class WidgetsViewModelMapperTests: XCTestCase {
let data = makeTodayData(stats: todayStats, date: Date())
let statsURL = data.statsURL

XCTAssertEqual(statsURL?.absoluteString, "https://wordpress.com/stats/day/0?source=widget")
XCTAssertEqual(statsURL?.absoluteString, "https://wordpress.com/stats/day/0")
}

func testUnconfiguredViewModel() {
Expand Down