Authentication
To use the SDK, you need a public API key (beginning with pk_) to send data to Customer.io. If you upgrade from an earlier SDK version, or use in-app messaging with an SDK version before 5.1.0, you also need your Site ID.
To get your SDK keys and send data to the right places, set up a data in An integration that feeds data into Customer.io.
If you haven’t already set up your app as an integration in Customer.io, set up your integration first.
Credentials you’ll need
- Public API key: This key starts with
pk_and is shown in code samples ascdpApiKey. It lets your app send data to Customer.io, and you need it to initialize the SDK. Customer.io creates one when you set up your integration. You can also create one for an existing integration on the API Credentials page. - Site ID: If you’re upgrading from version 2.x or earlier, you set your previous Site ID as the
migrationSiteId. In SDK versions before 5.1.0, you also need it to initialize theCioMessagingInApppackage. In 5.1.0 and later, the SDK uses your public key for in-app messages instead.
Set up a new iOS integration in Customer.io
If you don’t already have a public key, set up a new data in An integration that feeds data into Customer.io.
-
Go to Integrations and click Add integration.
-
Select iOS.
-
Enter a Name for your integration, like “My iOS App”.
-
Click the Copy and paste code tab. Customer.io shows a code sample with the credentials you need. The sample includes
cdpApiKey, your public key, which initializes the SDK and sends data to Customer.io. If you use in-app messaging, it also includessiteId, which initializesCioMessagingInApp.
Copy the code—or at least the
cdpApiKey—into your app. If you use in-app messaging with an SDK version before 5.1.0, copy thesiteIdtoo.SWIFTCustomerIO.initialize( withConfig: SDKConfigBuilder(cdpApiKey: "YOUR_CDP_API_KEY") .region(.US) .build() ) // Before iOS SDK 4.12.0, use MessagingInAppConfigBuilder(siteId: "YOUR_SITE_ID", region: .US), and use .EU if your account is in our EU data center. MessagingInApp.initialize( withConfig: MessagingInAppConfigBuilder(siteId: "YOUR_SITE_ID") .build() ) -
Click Test connection to check that Customer.io receives data from your app, and then click Complete setup. If you aren’t ready to test your app yet, click Save for later.
Get credentials from an existing iOS integration
Use this section if you’ve already set up an iOS integration and need to copy your credentials again.
Get your public key
Use your public key to initialize the SDK and send data to Customer.io. You can find this key on your mobile app’s integration card in Customer.io, or under Account Settings > API Credentials.
- Go to Integrations.
- Select your iOS integration in the Overview tab. If you don’t see an iOS integration, you’ll need to set it up.
- Go to Settings and find your public key. It starts with
pk_. Copy this key into your initialization call.
SWIFTfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { ... let config = SDKConfigBuilder(cdpApiKey: "YOUR_CDP_API_KEY") .autoTrackDeviceAttributes(true) CustomerIO.initialize(withConfig: config.build()) }
Find your Site ID manually
You only need your Site ID if you use in-app messaging with an SDK version before 5.1.0, or if you’re setting migrationSiteId while upgrading from version 2.x or earlier.
-
Go to and select Workspace Settings in the upper-right corner of the Customer.io app. Then go to API and Webhook Credentials.
-
Copy the Site ID for the set of credentials that you want to send your in-app messages from. If you don’t have a set of credentials, click Create Tracking API Key.
In SDK versions before 5.1.0, use this value in MessagingInAppConfigBuilder(siteId: "YOUR_SITE_ID"). Before 4.12.0, also pass region: .US, or region: .EU if your account is in our EU data center. In 5.1.0 and later, the SDK uses your public key, so you can use MessagingInAppConfigBuilder() instead. If you’re upgrading from version 2.x or earlier, use the Site ID from your previous SDK setup as migrationSiteId.
Securing your credentials
To simplify things, code samples in our documentation sometimes show API keys directly in your code. But you don’t have to hard-code your keys in your app. You can use environment variables, management tools that handle secrets, or other methods to keep your keys secure if you’re concerned about security.
To be clear, the keys that you’ll use to initialize the SDK don’t provide read access to data in Customer.io; they only write data to Customer.io. A bad actor who found your credentials can’t use your keys to read data from our servers.