Skip to content

Commit

Permalink
feat(readme): update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
smargozzini committed Jul 29, 2024
1 parent e6ae957 commit 24a0e66
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(

## Usage

### With SwiftUI
### Setup

```swift
import SwiftUI
Expand All @@ -33,22 +33,35 @@ struct MyApp: App {
}
}
}
```

struct ContentView: View {
var myProduct = Product(id: "123", image_url: URL(string: "https://loremflickr.com/640/480?lock=1234")!, name: "My Product", resolvedBidId: "123", price: 12.00)
var body: some View {
VStack {
ProductView(product: myProduct)
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)
}
}
.padding()
}
}
### 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).

```swift
import SwiftUI
import Topsort_Analytics

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

let category = AuctionCategory(id: "c_fdfa")

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)

```

### 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).

#### Impression & click

```swift
struct Product {
let id: String
let image_url: URL
Expand All @@ -60,7 +73,7 @@ struct Product {
struct ProductView: View {
@State
public var product: Product

private func event() -> Event {
var event: Event;
if (self.product.resolvedBidId != nil) {
Expand All @@ -70,7 +83,7 @@ struct ProductView: View {
}
return event
}

var body: some View {
VStack {
AsyncImage(url: self.product.image_url)
Expand All @@ -85,3 +98,22 @@ struct ProductView: View {
}
}
```

#### Purchase

```swift
struct ContentView: View {
var myProduct = Product(id: "123", image_url: URL(string: "https://loremflickr.com/640/480?lock=1234")!, name: "My Product", resolvedBidId: "123", price: 12.00)
var body: some View {
VStack {
ProductView(product: myProduct)
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)
}
}
.padding()
}
}
```

0 comments on commit 24a0e66

Please sign in to comment.