Respectlytics Respect lytics
Menu
Swift (iOS) Add to cart Privacy-first

How to track add-to-cart events in Swift (iOS) without personal data

Add-to-cart is the canonical mid-funnel signal in mobile commerce. Most analytics SDKs default to ingesting the SKU, the price, the quantity, the variant, and sometimes the supplier — building a per-user shopping graph by accident. Respectlytics helps developers avoid collecting personal data in the first place: in Swift (iOS), add-to-cart is one named event per add, with no metadata. Below: where to fire, what stays in your commerce backend, and how to read add → checkout funnels.

Fire the call inside your add-to-cart action handler — after the cart state is updated locally. Don't pass the SKU, price, quantity, or variant; your commerce backend has all of them.

Install the Swift (iOS) SDK

swift Respectlytics
// Package.swift
dependencies: [
    .package(url: "https://github.com/respectlytics/respectlytics-swift.git", from: "3.0.0")
]
// Or via Xcode → File → Add Packages → paste the URL above.

The SDK ships only via Swift Package Manager. CocoaPods and Carthage are not published — fewer integration paths means fewer surfaces to keep audited.

Initialize Respectlytics in Swift (iOS)

swift Respectlytics
import Respectlytics

@main
struct MyApp: App {
    init() {
        Respectlytics.configure(appKey: "<YOUR_APP_KEY>")
    }
    var body: some Scene { WindowGroup { ContentView() } }
}

Call configure once at app launch — typically in your App struct's init. No Info.plist keys are required: the SDK does not call ATTrackingManager and does not request the IDFA, so NSUserTrackingUsageDescription should NOT be added.

Track the event in Swift (iOS)

swift Respectlytics
import Respectlytics

func addToCart(productID: String, quantity: Int) {
    cart.add(productID: productID, quantity: quantity)
    Respectlytics.track("add_to_cart")
    // No SKU, no price, no quantity passed.
}

func removeFromCart(productID: String) {
    cart.remove(productID: productID)
    Respectlytics.track("remove_from_cart")
}

If you have a small fixed set of top-level categories worth segmenting, use distinct event names: add_to_cart_apparel, etc.

Privacy & implementation notes

Your commerce platform (Shopify, BigCommerce, your own service) is the authoritative cart system — it has SKU, price, quantity, variant, with proper retention and access policies. Mirroring cart contents into product analytics duplicates a system of record and produces drift the moment products are renamed or repriced.

Most product decisions about add-to-cart are about rate changes — "did the new product detail page move our DE iOS add-to-cart rate?". That question doesn't require knowing what specific items got added; it requires knowing the count of add_to_cart events relative to product_detail_view.

Apple rejected approximately 3% of apps in 2024 for incorrectly omitting NSUserTrackingUsageDescription when ATT was required by the SDKs they shipped. Respectlytics doesn't trigger ATT. The corollary is also true: do not add the key on Respectlytics's account — its presence implies you track across apps, even if your code never calls requestTrackingAuthorization.

Internally the Swift SDK uses Swift Concurrency: events are queued in an actor-isolated buffer (RAM-only), flushed on a 30-second timer and on UIApplication.willResignActiveNotification. Force-quit before flush drops queued events — by design. There is no UserDefaults or file backing.

How this compares to other analytics SDKs

Add-to-cart eventFirebase AnalyticsMixpanelRespectlytics
SKU / variant IDRecommendedRecommendedOut of scope
Price / currency / quantityRecommendedRecommendedRejected by API
Cart total at this stepRecommendedRecommendedOut of scope
Per-user cart abandonment recoveryYesYesOut of scope (use cart backend)
Add-to-cart *rate* by country / platformYesYesYes

Frequently asked questions

How do we know what's in users' carts without storing items?

Your commerce backend already has authoritative cart state per user. Respectlytics tells you the add-to-cart rate and how it correlates with checkout completion at the session level. Per-user abandoned-cart recovery is a marketing-automation use case, handled by your cart backend's webhooks (Shopify Plus, Klaviyo, etc.).

What about category-level adds (apparel vs electronics)?

If you have a small fixed set of top-level categories (under 8), distinct event names: add_to_cart_apparel, add_to_cart_electronics. Past that, skip the breakdown — your commerce backend has the granular data.

Should we instrument every cart-line edit (quantity changes, removals)?

Removals: yes, distinct event name remove_from_cart — the rate of removals near checkout is a UX signal. Quantity changes: not usually; they don't carry much product signal at the aggregate.

What if the same user adds and removes the same item rapidly?

Both events fire — Respectlytics doesn't dedupe. The rate of remove_from_cart shortly after add_to_cart is itself a UX signal (price reveal, shipping shock, etc.). Bucketing rates over country / platform makes those patterns visible without per-user tracking.

Related guides

Track what matters. Collect nothing you don't.

Five-field event schema, RAM-only event queue, no IDFA, no AAID, no persistent user IDs. Helps developers avoid collecting personal data in the first place.