Help Center

BlueConic SDK for iOS

How apple developers can use the BlueConic SDK for iOS to create custom mobile apps for their CDP use casesThe BlueConic SDK for iOS makes it easy for developers to collect profile data from their apps. This article explains how to integrate BlueConic into your iOS apps. If you are looking for information on Android apps, see the BlueConic SDK for Android.

You can use the BlueConic iOS SDK to do the following:

  • Set and retrieve profile property values
  • Serve (custom) dialogues 
  • Track user behavior using listeners

The BlueConicClient Framework provides the basis for communication with BlueConic. It provides possibilities to develop your own interactions by creating mobile plugins. In addition to creating your own plugins, BlueConicClient Framework allows you to make use of the standard BlueConic plugins. It contains several plugins that are mobile variants of the standard BlueConic plugins, such as Listeners and Dialogues.  


Before you begin

Before you start implementing the BlueConic SDK for iOS, make sure you have the following:

  • The latest version of Xcode (v14.3.1 or higher)
  • The BlueConic SDK for iOS (v3.0.0) Release, for submitting your app to the App Store. Valid architecture: arm64, x86_64.
  • An iOS app that you can use to implement the BlueConic SDK for iOS
  • The binary distribution files of the SDK have been built for iOS 12.

Updates to iOS Mobile SDK for Apple iOS 17

Beginning with iOS 17, developers now have the option to incorporate a "privacy manifest" file into their SDKs. This file will detail the SDK's data handling procedures, including the categories of data it gathers and the reasons for doing so. Moreover, SDK developers are permitted to add a "signature" to their SDKs as a means of confirming authenticity and origin. The introduction of the privacy manifest file provides app developers with transparent insight into the data practices of the SDKs they use, ensuring these practices meet standards and expectations.

Disclosing the data BlueConic automatically collects

Developers using the BlueConic SDK for iOS need to disclose to their customers what data they are collecting. Apple publishes a list of data types that require disclosure. This table describes how BlueConic collects data types that require disclosure:

Location data as defined by Apple BlueConic data collection
Coarse Location Information that describes the location of a user or device with a lower resolution than a latitude and longitude with three or more decimal places, such as Approximate Location Services. BlueConic collects this data. A low-resolution location is determined from the IP address of the user.

Identifiers as defined by Apple

User ID Data such as screen name, handle, account ID, assigned user ID, customer number, or other user- or account-level ID that can be used to identify a particular user or account. BlueConic collects this data. Users of the app will get a BlueConic ID.
Usage data as defined by Apple
Product Interaction Data such as app launches, taps, clicks, scrolling information, music listening data, video views, saved place in a game, video, or song, or other information about how the user interacts with the app. BlueConic collects data in relation to visits (app launches) such as visits, last visited date, and page views profile properties.
Other data as defined by Apple
Other data types Any other data types not mentioned.

BlueConic collects system information, including:

  • Operating system name
  • Operating system version
  • Screen resolution
  • App vendor
  • Mobile model

Privacy manifest file

BlueConic iOS SDK versions 3.2.0 and later include a privacy manifest file, which highlights the data collection done by the BlueConic SDK as described above. An example of the privacy manifest file, detailing the SDK data collection can be found here.

Tracking domains

Apple introduces the concept of NSPrivacyTrackingDomains to privacy manifests in iOS 17. This collection consists of strings specifying URLs that the application uses to facilitate tracking. If tracking permission has not been provided by the user through the App Tracking Transparency (ATT) framework, any network communications directed at these URLs will fail.

By default, the SDK does not include any URLs in its tracking domains section of the privacy manifest and when using the BlueConic iOS SDK, you are not required to add the BlueConic URL to the tracking domains.

If you track additional custom properties, such as the IDFA, then you will need to add the BlueConic URL to the tracking domains.

Listing the BlueConic URL in the tracking domains list will cause Apple to actively block BlueConic from receiving data for visitors who deny the ATT permission.

SDK signing

BlueConic iOS SDK versions 3.2.0 and later are signed using the official BlueConic iOS developer account. This ensures that the BlueConic iOS SDK is verified via Xcode and provides an additional layer of security for you when importing the SDK.

 


Getting Started

Note

The latest SDK version is 3.3.0.

Before you start implementing the SDK, use the following steps to set up your environment:

  1. Add the BlueConicClient framework to your app:
    There are three ways to do this:
    • Install with CocoaPods
      Add pod 'BlueConicClient' to your Podfile.
    • Install with Swift Package Manager
      In Xcode, go to File->Add Package Dependencies..., then search for https://github.com/blueconic/blueconic-ios-sdk in the top right search bar. Select the bluconic-ios-sdk entry, make sure to select the project you want to add it to and the latest version, and then press Add Package. Once the SDK is downloaded, click again to Add Package.
    • Add the BlueConicClient framework
      In Xcode add the BlueConicClient.xcframework for iOS by dragging the BlueConicClient.xcframework folder into the "Embedded Binaries" section on the General tab.
  2. Add the configuration key for BlueConic:
    Locate your app's Information Property List file under "Supporting Files".
    Select <project>-Info.plist and add a new row by right clicking the top row and selecting "Add row". Set the following key name:
    bc_server_url
    Double-click the value field and enter the URL for the hostname of your BlueConic server. For example:
    https://example.blueconic.net
  3. Import BlueConic:
    The BlueConic SDK for iOS enables you to set and retrieve profile property values for a BlueConic profile and enables interactions specific to this BlueConic profile. These methods can be used anywhere in the app. Make sure that you import the framework and get the instance before using the BlueConicClient methods:
    Swift Objective C
    import BlueConicClient
    
    let blueConic = BlueConic.getInstance(self)

    Note

    Make sure that you provide the current ViewController as argument when invoking getInstance. If no ViewController is available, pass an empty ViewControl.


Using the BlueConic iOS SDK

Create a page view event

Retrieve an instance of the BlueConic in the "viewDidAppear(animated: Bool)" of every ViewController and create a page view event. Make sure that a unique screen name is passed in the call. The screen name is shown in the BlueConic Simulator, and it can be used in listener rules or to restrict dialogue interactions to specific screens.

Note

Make sure that you provide the current ViewController as argument when invoking "getInstance" on the BlueConic. If no ViewController is available, pass an empty ViewController.

Swift Objective C
// Get the BlueConic instance. 
let blueConic = BlueConic.getInstance(self)

// Set screen name to identify the ViewController.
blueConic.createEvent("PAGEVIEW", properties:
["screenName": "Main/ExampleViewController"]
)

Important

Make sure you trigger a "PAGEVIEW" event in your application before using other functionalities from the SDK.

Triggering a "PAGEVIEW" event ensures that the SDK data collection works correctly.

The "screenName" property sent via a PAGEVIEW event is used by BlueConic to identify the location in the app.

Now the BlueConic user can retrieve the screen name "Main/Section1" as a value like so (using the regular expression (.*)):

Or the BlueConic user can add values when the Mobile Screen name contains certain words. Create a rule of type "URL / Mobile Screen" and configure the Mobile Screen name to listen to:

Once the "PAGEVIEW" event was triggered, the current screen name is saved in the SDK. You can use this value to validate that the SDK is currently registered to the desired screen. To retrieve the value use the following method:

Swift Objective C
let screenName = blueConic.getScreenName()

When you first interact with BlueConic using the SDK a profile ID is generated. This profile ID can be used to identify users in BlueConic. In order to retrieve the BlueConic assigned profile id, you can use the following method:

Swift Objective C
let profileId = blueConic.getProfileId()

Configure consent

In order to configure the consent information for the BlueConic SDK you can use the following methods:

Swift Objective C
// Get the SDK privacy legislation.
let privacyLegislation = blueConic.getPrivacyLegislation()

// Configure the SDK privacy legislation (e.g. GDPR, CCPA).
blueConic.setPrivacyLegislation("GDPR")

// Add consented objective.
// First, the objectives need to be configured in the BlueConic platform.
blueConic.addConsentedObjective("Marketing")

// Add refused objective.
// First, the objectives need to be configured in the BlueConic platform.
blueConic.addRefusedObjective("Tracking")

To configure consent information in BlueConic read more about it in the following article: Privacy management in BlueConic.

Collect Mobile Ad Id (IDFA)

If you want to send the Mobile Ad Id (IDFA) and have received the App Tracking Transparency(ATT) permission for the user, you can use the following method:

Swift Objective C
blueConic.setMobileAdId(IDFAValue)

Create a timeline event

The BlueConic SDK supports the ability to send timeline events using the following dedicated methods:

Swift Objective C
// Set the properties of the timeline event.
let properties = [
"propertyKey": "propertyValue",
"propertyNestedMap": [
"nestedKey": "nestedValue",
"nestedKey2": 123,
"nestedKey3": true
]
]

// Trigger the timeline event.
// Note that when using this method,
// the ID of the timeline event will be an automatically generated UUID.
blueConicClient.createTimelineEvent("MY_TIMELINE_EVENT",
eventDate: Date(), properties: properties)

//
Trigger the timeline event by ID.
blueConicClient.createTimelineEventById("MY_TIMELINE_ID",
eventType: "MY_TIMELINE_EVENT", eventDate: Date(), properties: properties)

To learn more about timeline events and how to configure them in BlueConic, check out the following article: Overview: Timeline events in BlueConic.

Use custom selectors to track page elements automatically

Some screens of our mobile app contain a view ID that we would like to pick up in BlueConic. As an example, create a new Behavior Listener in BlueConic and and add a content rule. Define the value as "Value from Page (custom selector)" with a human-readable name, e.g. "Chapter".

Use the ID of a component defined as @IBOutlet variable and prepend it with a # sign. E.g. use #chapterNumber in BlueConic when your app code defines a "chapterNumber" outlet:

Swift Objective C
@IBOutlet weak var chapterNumber: UILabel!

This allows the BlueConic user to define values:

It allows the BlueConic user to define a custom area that should contain words:

 

Retrieve and store profile properties

The BlueConic SDK for iOS enables you to set and retrieve profile property values for a BlueConic profile. These methods can be used anywhere in the app. The following example counts the number of times a specific activity is opened and stores this number in the BlueConic profile:

Swift Objective C
// Get profile property value
let propertyValue = blueConic.getProfileValue("propertyKey")
// Get profile property values (for multi-value properties) let profileProperties = blueConic.getProfileValues("propertyKey") // Set profile property value // Passing a property that was already set with values
// will cause for the old values to be removed. blueConic.setProfileValue("propertyKey", value: "propertyValue")
// Set profile property values (for multi-value properties) // Passing a property that was already set with values
// will cause for the old values to be removed. blueConic.setProfileValues("propertyKey", values: ["propertyValue1", "propertyValue2"])
// Add profile property value // If there are already values for a property the new value will be added. blueConic.addProfileValue("propertyKey", value: "propertyValue")
// Add profile property values (for multi-value properties) // If there are already values for a property the new values will be added. blueConic.addProfileValues("propertyKey", values: ["propertyValue1", "propertyValue2"])
// Increment profile property value // If there are already values for a property the new value
// will be the sum of all values. blueConic.incrementProfileValue("propertyKey", value: "1")

// Update the profile to sync over the data from the
// Mobile app to the BlueConic servers and;
// also pull in the data that has changed on the BlueConic side.
blueConic.updateProfile {
// This callback is called when the update is finished.
// You can now retrieve the new values from the profile.
}

A common use case for setting profile properties directly is to store attributes of the user, especially those that can be used for profile merging across devices. To do this, you would first need to note the ID of the user and email address profile properties you wish to populate (e.g. user_id and email). Then, the setProfileValue method should be used to populate these profile properties accordingly.

Track events

The BlueConic SDK allows you to send events to BlueConic. This allows you to keep BlueConic informed of what is happening in your app, even when it happens outside the scope of the basic operations.

Events are sent using the BlueConicEventManager's publish() function. Several kinds of events can be published:

ClickEvent
This event signals BlueConic that a component with a specific ID has been clicked in your app.
UpdateContentEvent
This event signals BlueConic that the content of a component with a specific ID has updated its content and also passes on the updated content.
UpdateValuesEvent
This event signals BlueConic that a component with a specific ID has received an updated list of values and passes on these updated values.
FormSubmitEvent
This event signals BlueConic that the form with a specific ID has been submitted.
AdvancedEvent
This allows you to send a custom event to BlueConic with its own specific name and a list of values.

 

Click event

BlueConic enables users to indicate the button that defines the click area in a Click / Tap rule as follows:

To make this work for your BlueConic users, add the following code to your app:

Swift Objective C
// Define click event for selector "#nextButton" 
let event = ClickEvent(selector: "#nextButton")
let eventWithContext = ClickEvent(selector: "#nextButton", context ["value"])

// Use EventManager to publish the event to BlueConic
let eventManager:EventManager = BlueConicEventFactory.getInstance()
eventManager.publish(event)
eventManager.publish(eventWithContext)

Updating content

BlueConic enables you to detect words on the mobile screen:

The BlueConic SDK will scan the mobile screen upon loading the view for the first time. But what if you change the contents of the screen without reloading the view?

To enable this for the BlueConic users at your site, publish an UpdateContentEvent. Add the following code to your app:

Swift Objective C
// Replace with the real new content 
let newContent = "..."
// Define update content event for UILabel or UIButton component "body"
let event = UpdateContentEvent(selector: "#body", content: newContent)

// Use EventManager to publish the event to BlueConic
let eventManager:EventManager = BlueConicEventFactory.getInstance()
eventManager.publish(event)

Updating values

BlueConic enables you to create a form listening rule that updates a profile property when a form field changes its value:

Most of the field classes will automatically pick up value changes provided you define them as an @IBOutlet. This is the list of supported fields:

  • UISegmentedControl
  • UIDatePicker
  • UIStepper
  • UISwitch
  • UISlider
  • UITextField

UIPickerView is not supported. This means you have to add code to pick up value changes for such field, as defining it as @IBOutlet will not be enough.

To make this work for your BlueConic users for non-supported fields, add the following code to your app:

Swift Objective C
// UITextField is supported; value change will automatically be picked up 
// by listening to selector "#emailAddress" in BlueConic.
@IBOutlet weak var emailAddress: UITextField!

// UIPickerView is not supported; value change will not automatically be
// picked up by listening to selector "#numberOfPersons" in BlueConic.
@IBOutlet weak var numberOfPersons: UIPickerView!

// Determine the value of the numberOfPersons picker,
// manually detect the value change
if let newValue = numberOfPersonsContent[numberOfPersons.selectedRowInComponent(0)]
where newValue != oldValue {
oldValue = newValue

// Define update values event for selector "#numberOfPersons"
let event = UpdateValuesEvent(selector: "#numberOfPersons",values: [newValue])

// Use EventManager to publish the event to BlueConic
let eventManager: BlueConicEventManager = BlueConicEventFactory.getInstance()
eventManager.publish(event)
}

Now, when the user enters an email address in your app, it will be picked up in BlueConic as well.

Form submit

BlueConic enables you to listen to in-app form submits as follows:

To enable this for your BlueConic users, add the following code to your app:

Swift Objective C
// Define form submit event for selector "#loginForm" 
let event = FormSubmitEvent(selector: "#loginForm")
let eventWithContext = FormSubmitEvent(selector: "#loginForm", context: "value")

// Use EventManager to publish the event to BlueConic
let eventManager:EventManager = BlueConicEventFactory.getInstance()
eventManager.publish(event)
eventManager.publish(eventWithContext)

Custom-defined event

BlueConic enables you to set profile property values when a custom-defined event is received. It even allows to check for specific values in the context of the event:

To enable this feature for your BlueConic users, add the following code to your app:

Swift Objective C
let valueList = ["blueberry", "sushi", "pancakes"] 

// Define advanced event with the name "video_started"
let event = AdvancedEvent(eventName: "video_started", context: valueList)

// Use EventManager to publish the event to BlueConic
let eventManager = BlueConicEventFactory.getInstance()
eventManager.publish(event)

The app publishes an event with the name "video_started" and a list of three values ("blueberry," "sushi," and "pancakes") is added as context. Adding values is optional; it provides extra information to allow BlueConic users at your site to make more specific rules.

On the BlueConic side, the example rule in the screenshot says "... if event video_started is received with a context that contains blueberry, raspberry for any value". The published example event contains one of those values (blueberry) for the event, which means there is a match. As a result, BlueConic will add the value "fruit" to the profile property "Food Preferences" of the profile for this particular app user.

Adding context

Adding context to an event makes it a lot easier to develop and configure which values a mobile developer is able to use and send through the event to BlueConic, where the event context can be used with BlueConic Listeners. Previously, this had to be configured by using a public UI element in order to retrieve data from a mobile app. Now mobile developers can use private or dynamic values and apply them directly as context to an event. This gives you more control and flexibility to publish BlueConic events within an app, and the marketing team can use them to define BlueConic Listeners, without having to know about the internal UI IDs of the mobile app.

Mobile developers can develop these events in their code, for example to publish a ClickEvent whenever a customer clicks on his favorite sport (code shown below). In addition, you can define a BlueConic Listener to keep track of a customer's favorite category or sport.

You can add the ClickEvent to a function in your app, for example, by adding a click handler a customer interacts with in the UI or when they navigate to a different page. 

Swift Objective C
func navigateToCategory(category: SportCategory) {
// Create a click event with context, e.g.: ClickEvent(selector:
// "#favoriteSport", context: ["soccer"])
let sportsClickEvent = ClickEvent(selector: "#favoriteSport", context: [category.name])
// Publish the event, so listeners can execute their rules
// when they have subscribed to the #favoriteSport selector
BlueConicEventFactory.getInstance().publish(sportsClickEvent)
// Execute the rest of the function...
}

Once the developer adds the events within the app, BlueConic users at your site can define BlueConic Listeners to keep track of these events and store data to the profile. To create listeners for these events, they just have to know the selectors the developer used in their events (e.g. “#favoriteSport”).

BlueConic users can use the event feature in any of the following BlueConic Listeners:

  • Behavior listener
  • Interest Ranker listener
  • Rule Based Form listener
  • Scoring listener

mobile-listeners-set.png

Inside these listeners, BlueConic users can define the following rules with the event option:

  • Click/tab rule
  • Form Submit rule (only accessible in the Rule-Based Form Listener)
  • Advanced rule

When setting up the BlueConic Listener, under “Expert Settings,” you select the “Value from context of an event” option, as shown here:

behavior-listener.png

Additional functionality

The SDK locale can be configured in the following way:

Swift Objective C
blueConic.setLocale("en_US")

To retrieve the segments the current user is currently part of, use the following methods:

Swift Objective C
let segments = blueConic.getSegments()
let segmentId = segments[0].getId()
let segmentName = segments[0].getName()

Create Custom Mobile Plugin

BlueConic offers the possibility to build your own custom plugins for mobile, that can be integrated into your application, providing additional functionality. 

To find out more about custom mobile plugins see: Custom Mobile Plugin for iOS


Test the SDK integration

Enable debug mode

Locate your app's Information Property List file under "Supporting Files".
Select <project>-Info.plist and add a new row by right clicking the top row and selecting "Add row". Set the following key name:

bc_debug

Click the type and select 'Boolean'. Set the value to "YES" if you want to receive debug logs from the BlueConic SDK. Adding a debug key is optional; if you do not want to receive debug logs from the SDK, you do not need to add it.
Setting Debug to true will provide more logging and enable the use of the BlueConic Simulator.

Warning

When you publish your apps, Debug should always be set false.

Add a URL Scheme key for BlueConic Simulator

Locate your app's Information Property List file under "Supporting Files".
Select <project>-Info.plist and add a new row by right clicking the top row and selecting "Add row". Set the following key name:

URL types

This creates an array that contains more property rows. Open "URL types" by clicking the triangle icon in front of the name to display the rows. Right click "Item 0" and select "Add row". You can also add a new item, and add the new row within that item. Set the following key name:

URL Schemes

This creates another array. Add a new row to this array's "Item 0" and enter your app's "Bundle Identifier", for example:

com.blueconic.testApp

Full example of the URL Schemes:

URL types

After you have added the URL Scheme value, select the AppDelegate class and add the following method to enable Simulator functionality:

Swift Objective C
// AppDelegate.swift file
func application(application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] ) -> Bool {    BlueConic.getInstance(nil).setURL(url)    
    return true
}

 


Release Notes

To see a list of updates and bug fixes for the SDK, see the BlueConic SDK for iOS Release Notes.

Was this article helpful?
0 out of 0 found this helpful