Skip to content
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

Extract TracksMini #24255

Merged
merged 4 commits into from
Mar 19, 2025
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
10 changes: 9 additions & 1 deletion Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ let package = Package(
cSettings: [.unsafeFlags(["-fno-objc-arc"])]
),
.target(name: "TextBundle"),
.target(
name: "TracksMini",
dependencies: ["BuildSettingsKit"],
swiftSettings: [.swiftLanguageMode(.v5)]
),
.target(name: "UITestsFoundation", dependencies: [
.product(name: "ScreenObject", package: "ScreenObject"),
.product(name: "XCUITestHelpers", package: "ScreenObject"),
Expand Down Expand Up @@ -177,6 +182,7 @@ enum XcodeSupport {
"WordPressShared",
"WordPressUI",
"TextBundle",
"TracksMini",
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
.product(name: "Down", package: "Down"),
.product(name: "Gridicons", package: "Gridicons-iOS"),
Expand Down Expand Up @@ -248,13 +254,15 @@ enum XcodeSupport {
.xcodeTarget("XcodeTarget_DraftActionExtension", dependencies: shareAndDraftExtensionsDependencies),
.xcodeTarget("XcodeTarget_NotificationServiceExtension", dependencies: [
"SFHFKeychainUtils",
"WordPressShared",
"BuildSettingsKit",
"WordPressShared",
"TracksMini",
]),
.xcodeTarget("XcodeTarget_StatsWidget", dependencies: [
"BuildSettingsKit",
"JetpackStatsWidgetsCore",
"SFHFKeychainUtils",
"TracksMini",
"WordPressShared",
"WordPressUI",
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ open class Tracks {
open var wpcomUserID: String?

// MARK: - Private Properties
fileprivate let uploader: Uploader
private let uploader: Uploader

// MARK: - Constants
fileprivate static let version = "1.0"
fileprivate static let userAgent = "Nosara Extensions Client for iOS Mark " + version
private static let version = "1.0"
private static let userAgent = "Nosara Extensions Client for iOS Mark " + version

private let eventNamePrefix: String

// MARK: - Initializers
init(appGroupName: String,
public init(appGroupName: String = BuildSettings.current.appGroupName,
eventNamePrefix: String = BuildSettings.current.eventNamePrefix) {
uploader = Uploader(appGroupName: appGroupName)
self.eventNamePrefix = eventNamePrefix
Expand All @@ -33,7 +33,7 @@ open class Tracks {
}

// MARK: - Private Helpers
fileprivate func payloadWithEventName(_ eventName: String, properties: [String: Any]?) -> [String: Any] {
private func payloadWithEventName(_ eventName: String, properties: [String: Any]?) -> [String: Any] {
let timestamp = NSNumber(value: Int64(Date().timeIntervalSince1970 * 1000) as Int64)
let anonUserID = UUID().uuidString
let device = UIDevice.current
Expand Down Expand Up @@ -80,16 +80,18 @@ open class Tracks {
/// Private Internal Helper:
/// Encapsulates all of the Backend Tracks Interaction, and deals with NSURLSession's API.
///
fileprivate class Uploader: NSObject, URLSessionDelegate {
private class Uploader: NSObject, URLSessionDelegate {
// MARK: - Properties
fileprivate var session: Foundation.URLSession!
private var session: Foundation.URLSession!

// MARK: - Constants
fileprivate let tracksURL = "https://public-api.wordpress.com/rest/v1.1/tracks/record"
fileprivate let httpMethod = "POST"
fileprivate let headers = [ "Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "WPiOS App Extension"]
private let tracksURL = "https://public-api.wordpress.com/rest/v1.1/tracks/record"
private let httpMethod = "POST"
private let headers = [
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "WPiOS App Extension"
]

// MARK: - Deinitializers
deinit {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import WidgetKit
import BuildSettingsKit
import SwiftUI
import JetpackStatsWidgetsCore
import TracksMini

struct LockScreenStatsWidget<T: LockScreenStatsWidgetConfig>: Widget {
private let tracks = Tracks(appGroupName: BuildSettings.current.appGroupName)
private let tracks = Tracks()
private let config: T

init(config: T) {
Expand Down
4 changes: 2 additions & 2 deletions WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import WidgetKit
import SwiftUI
import BuildSettingsKit
import JetpackStatsWidgetsCore
import TracksMini

struct HomeWidgetAllTime: Widget {
private let tracks = Tracks(appGroupName: BuildSettings.current.appGroupName)
private let tracks = Tracks()

private let placeholderContent = HomeWidgetAllTimeData(
siteID: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import WidgetKit
import SwiftUI
import BuildSettingsKit
import JetpackStatsWidgetsCore
import TracksMini

struct HomeWidgetThisWeek: Widget {
private let tracks = Tracks(appGroupName: BuildSettings.current.appGroupName)
private let tracks = Tracks()

static let secondsPerDay = 86400.0

Expand Down
4 changes: 2 additions & 2 deletions WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Foundation
import WidgetKit
import SwiftUI
import BuildSettingsKit
import JetpackStatsWidgetsCore
import TracksMini

struct HomeWidgetToday: Widget {
private let tracks = Tracks(appGroupName: BuildSettings.current.appGroupName)
private let tracks = Tracks()

private let placeholderContent = HomeWidgetTodayData(siteID: 0,
siteName: "My WordPress Site",
Expand Down
1 change: 1 addition & 0 deletions WordPress/Tracks+ShareExtension.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import TracksMini

/// This extension implements helper tracking methods, meant for Share Extension Usage.
///
Expand Down
Loading