/Documentation

iOS SDK

Updated Aug 10, 2026

Overview of iOS SDK

How to set up iOS SDK

Cocoapods

SPM

Connection

import StapeSDK
if let url = URL(string: "https://yourdomain.com") { let c = Stape.Configuration(domain: url) Stape.start(configuration: c) }

Sending events

let e = Stape.Event(name: "foo", payload: ["bar": "baz"])
Stape.send(event: e) { result in switch result { case .success(let response): print("Event sent: \(response)") case .failure(let error): print("Failed to send event: \(error)") } }
public enum Key: String { case clientID = "client_id" case idfa = "idfa" case currency = "currency" case ipOverride = "ip_override" case language = "language" case pageEncoding = "page_encoding" case pageHostname = "page_hostname" case pageLocation = "page_location" case pagePath = "page_path" }
let e = Stape.Event(name: "foo", payload: [ .clientID: "bar", .language: "foo" ])

Firebase hooking

public static func addFBEventHandler(_ handler: @escaping Completion, forKey key: String) public static func removeFBEventHandler(forKey key: String)

Logging

Stape Data Client in server GTM

Data Client on GitHub.
Templates
Add new Client template
Add Data Client
Submit changes

How to add iOS SDK to your project

pod 'StapeSDK'
pod install
import StapeSDK @main class AppDelegate: UIResponder, UIApplicationDelegate {     var window: UIWindow?     func application(_ application: UIApplication,                      didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {         // Initialize Stape SDK with your domain         if let url = URL(string: "https://gtm.example.com") {             let configuration = Stape.Configuration(domain: url)             Stape.start(configuration: configuration)         }         return true     } }
import StapeSDK class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Send "add_to_cart" event sendAddToCartEvent() } func sendAddToCartEvent() { // Define event payload let payload: [String: Any] = [ "value": 68, "currency": "USD", "page_hostname": "stape.io", "page_location": "http://stape.io", "user_data": [ "email": sha256("jhonn@doe.com") // Hash email for privacy ] ] // Create event let event = Stape.Event(name: "add_to_cart", payload: payload) // Send event Stape.send(event: event) { result in switch result { case .success(let response): print("✅ Event Sent: \(response.payload)") case .failure(let error): print("❌ Error: \(error.localizedDescription)") } } } // SHA256 hashing function func sha256(_ input: String) -> String { guard let data = input.data(using: .utf8) else { return "" } var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) data.withUnsafeBytes { _ = CC_SHA256($0.baseAddress, CC_LONG(data.count), &hash) } return hash.map { String(format: "%02x", $0) }.joined() } }

Firebase hooking

public static func addFBEventHandler(_ handler: @escaping Completion, forKey key: String) public static func removeFBEventHandler(forKey key: String)

How to test the setup

The most common problem when using the SDK is getting a 400 error

Was this article helpful?

Comments

Can’t find what you are looking for?