Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

Links the app opens to crabrowser.app name the button they came from

Victor94c1fc38c2b9
diff --git a/Packages/CraCore/Sources/CraCore/SiteLinks.swift b/Packages/CraCore/Sources/CraCore/SiteLinks.swift
new file mode 100644
index 0000000..2e7d97f
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/SiteLinks.swift
@@ -0,0 +1,35 @@
+import Foundation
+
+/// Links the app opens to crabrowser.app, tagged with the button that opened them.
+///
+/// A tab Cra opens by itself sends no referrer, so the site's analytics (Phantom) counted
+/// these visits as "Direct / None", the same as a typed address. `utm_source=cra-app` plus a
+/// campaign that names the button lets the site's stats tell the "Cra updated!" card's
+/// What's new from Help → Release Notes. The tag names the button and nothing else: nothing
+/// about the person or the Mac goes in it. The site removes it from the address bar once the
+/// page view is counted (cra-website `CampaignTagCleanup`).
+public enum SiteLinks {
+ public static let source = "cra-app"
+
+ /// The button a link was opened from: the `utm_campaign` value.
+ public enum Origin: String, CaseIterable, Sendable {
+ /// What's new on the "Cra updated!" card.
+ case whatsNew = "whats-new"
+ /// The Help menu's links.
+ case helpMenu = "help-menu"
+ /// "Learn more" on the site control center's protected-media card.
+ case protectedMedia = "protected-media"
+ }
+
+ /// `url` with Cra's tag when it points at crabrowser.app; any other URL (GitHub, a typo)
+ /// comes back unchanged. A tag already on the URL is replaced, other parameters and the
+ /// fragment are kept.
+ public static func tagged(_ url: String, from origin: Origin) -> String {
+ guard var parts = URLComponents(string: url), parts.scheme == "https",
+ let host = parts.host?.lowercased(), host == "crabrowser.app" || host == "www.crabrowser.app"
+ else { return url }
+ let kept = (parts.queryItems ?? []).filter { $0.name != "utm_source" && $0.name != "utm_campaign" }
+ parts.queryItems = kept + [URLQueryItem(name: "utm_source", value: source), URLQueryItem(name: "utm_campaign", value: origin.rawValue)]
+ return parts.string ?? url
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/SiteLinksTests.swift b/Packages/CraCore/Tests/CraCoreTests/SiteLinksTests.swift
new file mode 100644
index 0000000..34a6556
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/SiteLinksTests.swift
@@ -0,0 +1,28 @@
+import CraCore
+import Testing
+
+/// Visits from the app's buttons showed up as "Direct / None" on the site's analytics.
+struct SiteLinksTests {
+ @Test func tagsSiteLinksWithTheButton() {
+ #expect(SiteLinks.tagged("https://crabrowser.app/release-notes", from: .whatsNew)
+ == "https://crabrowser.app/release-notes?utm_source=cra-app&utm_campaign=whats-new")
+ #expect(SiteLinks.tagged("https://www.crabrowser.app/help", from: .helpMenu)
+ == "https://www.crabrowser.app/help?utm_source=cra-app&utm_campaign=help-menu")
+ }
+
+ @Test func keepsOtherParametersAndTheFragment() {
+ #expect(SiteLinks.tagged("https://crabrowser.app/help/protected-media?x=1#spotify", from: .protectedMedia)
+ == "https://crabrowser.app/help/protected-media?x=1&utm_source=cra-app&utm_campaign=protected-media#spotify")
+ }
+
+ @Test func replacesATagAlreadyThere() {
+ #expect(SiteLinks.tagged("https://crabrowser.app/?utm_campaign=old&utm_source=x", from: .helpMenu)
+ == "https://crabrowser.app/?utm_source=cra-app&utm_campaign=help-menu")
+ }
+
+ @Test(arguments: ["https://github.com/VictorKildahl/cra/issues", "http://crabrowser.app/help",
+ "https://crabrowser.app.evil.example/", "https://evilcrabrowser.app/", "not a url"])
+ func leavesEverythingElseAlone(url: String) {
+ #expect(SiteLinks.tagged(url, from: .helpMenu) == url)
+ }
+}
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 238118a..49c8c16 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -1349,7 +1349,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
("Report an Issue…", "https://github.com/VictorKildahl/cra/issues"), ("Support Cra…", "https://crabrowser.app/support")] {
let link = NSMenuItem(title: title, action: #selector(openHelpLink(_:)), keyEquivalent: "")
link.target = self
- link.representedObject = url
+ link.representedObject = SiteLinks.tagged(url, from: .helpMenu)
help.addItem(link)
}
help.addItem(.separator())
diff --git a/Sources/Cra/Services/SoftwareUpdater.swift b/Sources/Cra/Services/SoftwareUpdater.swift
index 3775f2d..ad45fe8 100644
--- a/Sources/Cra/Services/SoftwareUpdater.swift
+++ b/Sources/Cra/Services/SoftwareUpdater.swift
@@ -73,7 +73,8 @@ final class SoftwareUpdater: NSObject {
/// This launch came from an automatic restart, so it should not take focus.
private(set) var launchedByAutoUpdate = false
- static let releaseNotesURL = "https://crabrowser.app/release-notes"
+ /// What's new on the "Cra updated!" card, tagged so the site can count visits from it.
+ static let releaseNotesURL = SiteLinks.tagged("https://crabrowser.app/release-notes", from: .whatsNew)
static let downloadURL = "https://github.com/VictorKildahl/cra/releases/latest"
@ObservationIgnored private var updater: SPUUpdater?
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 0ec6688..a04f370 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -2498,7 +2498,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
}
/// The help centre's page on why Spotify, Netflix and the others play in Safari's engine.
- static let protectedMediaHelp = "https://crabrowser.app/help/protected-media"
+ static let protectedMediaHelp = SiteLinks.tagged("https://crabrowser.app/help/protected-media", from: .protectedMedia)
func debugSiteControlsShown() -> Bool { siteControlCenter.isShown
}