Skip to content

Commit

Permalink
chore: rename analytics.swift -> topsort.swift (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Margozzini <[email protected]>
  • Loading branch information
jbergstroem and smargozzini authored Aug 20, 2024
1 parent 1e3c2fa commit af66859
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 49 deletions.
16 changes: 8 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import PackageDescription

let package = Package(
name: "Topsort-Analytics",
name: "Topsort",
platforms: [
.macOS("12.00"),
.iOS("15.0"),
Expand All @@ -13,8 +13,8 @@ let package = Package(
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "Topsort-Analytics",
targets: ["Topsort-Analytics"]),
name: "Topsort",
targets: ["Topsort"]),
.library(
name: "TopsortBanners",
targets: ["TopsortBanners"]
Expand All @@ -24,16 +24,16 @@ let package = Package(
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "Topsort-Analytics"),
name: "Topsort"),
.testTarget(
name: "analytics.swiftTests",
dependencies: ["Topsort-Analytics"]),
name: "topsort.swiftTests",
dependencies: ["Topsort"]),
.target(
name: "TopsortBanners",
dependencies: ["Topsort-Analytics"]),
dependencies: ["Topsort"]),
.testTarget(
name: "banners.swiftTests",
dependencies: ["TopsortBanners", "Topsort-Analytics"]),
dependencies: ["TopsortBanners", "Topsort"]),

]
)
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Analytics.swift
# topsort.swift

## Install

Expand All @@ -8,7 +8,7 @@
let package = Package(
...
dependencies: [
.package(url: "https://github.com/Topsort/analytics.swift.git", from: "1.0.0"),
.package(url: "https://github.com/Topsort/topsort.swift.git", from: "1.0.0"),
]
...
)
Expand All @@ -20,12 +20,12 @@ let package = Package(

```swift
import SwiftUI
import Topsort_Analytics
import Topsort

@main
struct MyApp: App {
init() {
Analytics.shared.configure(apiKey: "your-api-key", url: "https://api.topsort.com")
Topsort.shared.configure(apiKey: "your-api-key", url: "https://api.topsort.com")
}
var body: some Scene {
WindowGroup {
Expand All @@ -37,11 +37,11 @@ struct MyApp: App {

### Auctions

View all auction models and their definitions in the [Swift package link](https://github.com/Topsort/analytics.swift/blob/main/Sources/Topsort-Analytics/Models/Auctions.swift).
View all auction models and their definitions in the [Swift package link](https://github.com/Topsort/topsort.swift/blob/main/Sources/Topsort/Models/Auctions.swift).

```swift
import SwiftUI
import Topsort_Analytics
import Topsort

let products = AuctionProducts(ids: ["p_dsad", "p_dvra", "p_oplf", "p_gjfo"])

Expand All @@ -51,13 +51,13 @@ let auctions = [
Auction(type: "banners", slots: 1, slotId: "home-banner", device: "mobile", category: category),
Auction(type: "listings", slots: 2, device: "mobile", products: products)
]
let result: AuctionResponse = await Analytics.shared.executeAuctions(auctions: auctions)
let result: AuctionResponse = await Topsort.shared.executeAuctions(auctions: auctions)

```

### Events

View all event models and their definitions in the [Swift package link](https://github.com/Topsort/analytics.swift/blob/main/Sources/Topsort-Analytics/Models/Events.swift).
View all event models and their definitions in the [Swift package link](https://github.com/Topsort/topsort.swift/blob/main/Sources/Topsort/Models/Events.swift).

#### Impression & click

Expand Down Expand Up @@ -90,10 +90,10 @@ struct ProductView: View {
Text(self.product.name)
}
.onAppear {
Analytics.shared.track(impression: self.event())
Topsort.shared.track(impression: self.event())
}
.onTapGesture {
Analytics.shared.track(click: self.event())
Topsort.shared.track(click: self.event())
}
}
}
Expand All @@ -110,7 +110,7 @@ struct ContentView: View {
Button("Purchase me!") {
let item = PurchaseItem(productId: myProduct.id, unitPrice: myProduct.price)
let event = PurchaseEvent(items: [item], occurredAt: Date.now)
Analytics.shared.track(purchase: event)
Topsort.shared.track(purchase: event)
}
}
.padding()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public struct Placement: Codable {
public struct Entity : Codable {
let type: EntityType
let id: String

public init(type: EntityType, id: String) {
self.type = type
self.id = id
Expand Down Expand Up @@ -110,7 +110,7 @@ public struct Event : Codable {
public init(entity: Entity, occurredAt: Date, placement: Placement? = nil) {
self.entity = entity
self.occurredAt = occurredAt
self.opaqueUserId = Analytics.shared.opaqueUserId
self.opaqueUserId = Topsort.shared.opaqueUserId
self.resolvedBidId = nil
self.placement = placement
self.id = UUID()
Expand All @@ -119,7 +119,7 @@ public struct Event : Codable {
public init(resolvedBidId: String, occurredAt: Date, placement: Placement? = nil) {
self.entity = nil
self.occurredAt = occurredAt
self.opaqueUserId = Analytics.shared.opaqueUserId
self.opaqueUserId = Topsort.shared.opaqueUserId
self.resolvedBidId = resolvedBidId
self.placement = placement
self.id = UUID()
Expand Down Expand Up @@ -171,7 +171,7 @@ public struct PurchaseEvent : Codable {
public init(items: [PurchaseItem], occurredAt: Date) {
self.items = items
self.occurredAt = occurredAt
self.opaqueUserId = Analytics.shared.opaqueUserId
self.opaqueUserId = Topsort.shared.opaqueUserId
self.id = UUID()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation


public protocol AnalyticsProtocol {
public protocol TopsortProtocol {
var opaqueUserId: String { get }
func set(opaqueUserId: String?)
func configure(apiKey: String, url: String?)
Expand All @@ -12,8 +12,8 @@ public protocol AnalyticsProtocol {
}


public class Analytics: AnalyticsProtocol {
public static let shared = Analytics()
public class Topsort: TopsortProtocol {
public static let shared = Topsort()
@FilePersistedValue(storePath: PathHelper.path(for: "com.topsort.analytics.opaque-user-id.plist"))
private var _opaqueUserId: String?
public var opaqueUserId: String {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions Sources/TopsortBanners/BannerView.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Foundation
import SwiftUI
import Topsort_Analytics
import Topsort

public struct TopsortBanner: View {
@ObservedObject var sharedValues = SharedValues()

var width: CGFloat
var height: CGFloat
var buttonClickedAction: (AuctionResponse?) -> Void
var analytics: AnalyticsProtocol
var topsort: TopsortProtocol

public init(
apiKey: String,
Expand All @@ -18,13 +18,13 @@ public struct TopsortBanner: View {
slotId: String,
deviceType: String,
buttonClickedAction: @escaping (AuctionResponse?) -> Void,
analytics: AnalyticsProtocol = Analytics.shared
topsort: TopsortProtocol = Topsort.shared
) {
Analytics.shared.configure(apiKey: apiKey, url: url)
Topsort.shared.configure(apiKey: apiKey, url: url)
self.width = width
self.height = height
self.buttonClickedAction = buttonClickedAction
self.analytics = analytics
self.topsort = topsort

self.run(deviceType: deviceType, slotId: slotId)
}
Expand All @@ -37,19 +37,19 @@ public struct TopsortBanner: View {

internal func executeAuctions(deviceType: String, slotId: String) async {
let auction: Auction = Auction(type: "banners", slots: 1, slotId: slotId, device: deviceType)
let response = await analytics.executeAuctions(auctions: [auction])
let response = await topsort.executeAuctions(auctions: [auction])

sharedValues.response = response
sharedValues.setResolvedBidIdAndUrlFromResponse()
sharedValues.loading = false

let event = Event(resolvedBidId: sharedValues.resolvedBidId!, occurredAt: Date.now)
analytics.track(impression: event)
topsort.track(impression: event)
}

private func buttonClicked() async {
let event = Event(resolvedBidId: sharedValues.resolvedBidId!, occurredAt: Date.now)
analytics.track(click: event)
topsort.track(click: event)
self.buttonClickedAction(sharedValues.response)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/TopsortBanners/SharedValues.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import Topsort_Analytics
import Topsort

class SharedValues: ObservableObject {
@Published var resolvedBidId: String?
Expand Down
10 changes: 5 additions & 5 deletions Tests/banners.swiftTests/bannerView_swiftTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import XCTest
@testable import Topsort
@testable import TopsortBanners
@testable import Topsort_Analytics

class TopsortBannerTests: XCTestCase {

Expand Down Expand Up @@ -32,9 +32,9 @@ class TopsortBannerTests: XCTestCase {
let auctionResult = AuctionResult(resultType: "result_type", winners: [winner], error: false)
let auctionResponse = AuctionResponse(results: [auctionResult])

// Mock Analytics and response
let mockAnalytics = MockAnalytics()
mockAnalytics.executeAuctionsMockResponse = auctionResponse
// Mock Topsort and response
let mockTopsort = MockTopsort()
mockTopsort.executeAuctionsMockResponse = auctionResponse

let banner = await TopsortBanner(
apiKey: "test_api_key",
Expand All @@ -45,7 +45,7 @@ class TopsortBannerTests: XCTestCase {
deviceType: "test_device_type",
buttonClickedAction: { response in
},
analytics: mockAnalytics
topsort: mockTopsort
)

// Execute the method
Expand Down
5 changes: 2 additions & 3 deletions Tests/banners.swiftTests/mocks/analyticsMock.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Foundation
import XCTest
@testable import Topsort_Analytics

public class MockAnalytics: AnalyticsProtocol {
@testable import Topsort
public class MockTopsort: TopsortProtocol {
public var opaqueUserId: String = "mocked-opaque-user-id"
public var executeAuctionsMockResponse: AuctionResponse?

Expand Down
2 changes: 1 addition & 1 deletion Tests/banners.swiftTests/sharedValues_swiftTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import XCTest
@testable import TopsortBanners
@testable import Topsort_Analytics
@testable import Topsort

class SharedValuesTests: XCTestCase {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import XCTest
@testable import Topsort_Analytics
@testable import Topsort

class AuctionManagerTests: XCTestCase {
var auctionManager: AuctionManager!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
@testable import Topsort_Analytics
@testable import Topsort

class MockHTTPClient: HTTPClient {
var postCalled = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import XCTest
@testable import Topsort_Analytics
@testable import Topsort

final class analytics_swiftTests: XCTestCase {
final class topsort_swiftTests: XCTestCase {
func testExample() throws {
// XCTest Documenation
// https://developer.apple.com/documentation/xctest
Expand All @@ -16,7 +16,7 @@ final class analytics_swiftTests: XCTestCase {
iso8601DateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
let occurredAt = iso8601DateFormatter.string(from: date)

Analytics.shared.set(opaqueUserId: "user-id")
Topsort.shared.set(opaqueUserId: "user-id")

let myEvent = Event(entity: Entity(type: EntityType.product, id: "product-id"), occurredAt: date)

Expand Down

0 comments on commit af66859

Please sign in to comment.