Skip to content

Instantly share code, notes, and snippets.

@frosty
Created January 29, 2021 11:11
Show Gist options
  • Save frosty/21010244fb0148f380ac611bf82db3d9 to your computer and use it in GitHub Desktop.
Save frosty/21010244fb0148f380ac611bf82db3d9 to your computer and use it in GitHub Desktop.
diff --git a/WordPress/Classes/System/WordPressAppDelegate+openURL.swift b/WordPress/Classes/System/WordPressAppDelegate+openURL.swift
index 9634ed5983..503854cd86 100644
--- a/WordPress/Classes/System/WordPressAppDelegate+openURL.swift
+++ b/WordPress/Classes/System/WordPressAppDelegate+openURL.swift
@@ -11,6 +11,11 @@ import AutomatticTracks
return true
}
+ if UniversalLinkRouter.shared.canHandle(url: url) {
+ UniversalLinkRouter.shared.handle(url: url, shouldTrack: true)
+ return true
+ }
+
guard url.scheme == WPComScheme else {
return false
}
diff --git a/WordPress/Classes/Utility/Universal Links/UniversalLinkRouter.swift b/WordPress/Classes/Utility/Universal Links/UniversalLinkRouter.swift
index 14d77ec211..221f89c745 100644
--- a/WordPress/Classes/Utility/Universal Links/UniversalLinkRouter.swift
+++ b/WordPress/Classes/Utility/Universal Links/UniversalLinkRouter.swift
@@ -102,12 +102,12 @@ struct UniversalLinkRouter {
func canHandle(url: URL) -> Bool {
let matcherCanHandle = matcher.routesMatching(url).count > 0
- guard let host = url.host else {
+ guard let host = url.host, let scheme = url.scheme else {
return matcherCanHandle
}
// If there's a hostname, check it's WordPress.com
- return host == "wordpress.com" && matcherCanHandle
+ return scheme == "https" && host == "wordpress.com" && matcherCanHandle
}
/// Attempts to find a route that matches the url's path, and perform its
@@ -136,8 +136,18 @@ struct UniversalLinkRouter {
private func trackDeepLink(matchCount: Int, url: URL) {
let stat: WPAnalyticsStat = (matchCount > 0) ? .deepLinked : .deepLinkFailed
- let properties = ["url": url.absoluteString]
+ var properties = [TracksPropertyKeys.url: url.absoluteString]
+
+ let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
+ if let source = components?.queryItems?.first(where: { $0.name == TracksPropertyKeys.source }) {
+ properties[TracksPropertyKeys.source] = source.value
+ }
WPAppAnalytics.track(stat, withProperties: properties)
}
+
+ private enum TracksPropertyKeys {
+ static let url = "url"
+ static let source = "source"
+ }
}
diff --git a/WordPress/WordPressStatsWidgets/Views/TodayWidgetView.swift b/WordPress/WordPressStatsWidgets/Views/TodayWidgetView.swift
index d00e692e84..76eb83c13f 100644
--- a/WordPress/WordPressStatsWidgets/Views/TodayWidgetView.swift
+++ b/WordPress/WordPressStatsWidgets/Views/TodayWidgetView.swift
@@ -44,9 +44,9 @@ struct TodayWidgetView: View {
private extension HomeWidgetTodayData {
- static let statsUrl = "\(WPComScheme)://" + "viewstats?siteId="
+ static let statsUrl = "https://wordpress.com/stats/day/"
var statsURL: URL? {
- URL(string: Self.statsUrl + "\(siteID)")
+ URL(string: Self.statsUrl + "\(siteID)?source=widget")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment