Skip to main content

Prerequisites

Before you get started, make sure you have the following:
  1. Obtain your publishable key (DUB_PUBLISHABLE_KEY) from your workspace’s Tracking settings page.
  2. You would also want to have your custom domain (DUB_DOMAIN) handy as well.
  3. (Optional) If you plan to track conversions, make sure to enable conversion tracking for your links.

Quickstart

This quick start guide will show you how to get started with Dub iOS SDK in your Swift project.
1

Install the Dub iOS SDK

Before installing, ensure your environment meets these minimum requirements:Build Tools:
  • Xcode 16+
  • Swift 4.0+
Platforms:
  • iOS 16.0+
  • macOS 10.13 (Ventura)+
The Dub iOS SDK can be installed using the Swift Package Manager.In Xcode, select File > Add Package Dependencies and add https://github.com/dubinc/dub-ios as the repository URL. Select the latest version of the SDK from the release page.
2

Initialize the SDK

You must call Dub.setup with your publishable key and domain prior to being able to use the dub instance.
3

Track deep link open events

Call trackOpen on the dub instance to track deep link and deferred deep link open events. The trackOpen function should be called once without a deepLink parameter on first launch, and then again with the deepLink parameter whenever the app is opened from a deep link.
UIKit apps: If your AppDelegate has multiple URL handlers chained with || (e.g., Facebook/Meta SDK alongside Dub), the short-circuit evaluation may prevent handleDeepLink and trackOpen from being called. Make sure all handlers execute independently. See the troubleshooting guide for details and a fix.
4

Track lead events (optional)

To track lead events, call trackLead on the dub instance with your customer’s external ID, name, and email.
Here are the properties you can include when sending a lead event:
5

Track sale events (optional)

To track sale events, call trackSale on the dub instance with your customer’s user ID and purchase information.
Here are the properties you can include when sending a sale event:

Examples

Here are some open-source code examples that you can reference:

Swift (SwiftUI)

See the full example on GitHub.

Swift (UIKit)

See the full example on GitHub.