Skip to main content
Topsort’s Swift library enables our clients to easily send auction requests and track events within iOS applications.
Minimum requirements: Swift 6 toolchain (Xcode 16) and iOS 15.

Installation

Install using package.swift:

Configuration

Call Topsort.shared.set(opaqueUserId:) after configuring whenever you have your own id for the user, logged in or not. Without one, the SDK generates an id and keeps it across launches.

Requesting Auctions

Reporting Events

Renders

A render records that a sponsored ad was inserted into the view hierarchy, separately from the impression, which records when it becomes visible. Report it as soon as the ad is placed on the screen, before the impression. Renders are sponsored-only, so resolvedBidId is required. winner is one of the winners in the auction response (result.results[i].winners).
Topsort.shared sends only the first render and the first impression of each resolvedBidId for a user and drops any repeat, so reporting from onAppear is safe when a view reappears, for example while scrolling a lazy list.

Impressions

An impression records that an ad or product became visible to the shopper.
For organic results, build the event with Event(entity: Entity(type: .product, id: product.id), occurredAt: Date.now) instead.

Clicks

A click records that the shopper clicked an ad or product.
Organic clicks use the same Event(entity:occurredAt:) initializer as impressions.

Purchases

A purchase records the products a shopper bought. Topsort attributes it to the ads the shopper interacted with.

Displaying Banners

TopsortBanner reports the render when the auction returns a winner, the impression when the image loads, and the click when it is tapped. Do not report these events yourself for banners it displays. For full documentation, see the GitHub repository.