iOS Application Pixel Integration

To set up Bloomreach pixels in your native iOS application, follow the steps below:

1. Add the SDK dependency package

The first step is to add the dependency package that contains the Bloomreach pixels for the iOS client library.
To add the dependency, follow these steps:

  1. Click on “Add Packages” from the File menu of Xcode.
504
  1. Paste the framework's GitHub URL in the search box: https://github.com/bloomreach/discovery-ios-sdk

  1. Click on discovery-ios-sdk, select the main branch, and add the package to the appropriate project.

2. Initialization

To initialize the Discovery Pixel SDK in your app, first import the discovery_ios_sdk module in your UIApplicationDelegate:

import discovery_ios_sdk

Then initialize the Discovery SDK in your app delegate's application(_:didFinishLaunchingWithOptions:) method as shown:

class AppDelegate: NSObject, UIApplicationDelegate {
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    let brPixel = BrPixel(
        accountId: "<ACCOUND_ID>",
        uuid: “<13_digit_random_number>”,
        visitorType: VisitorType.NEW_USER,
        baseUrl: "http://bloomique.com/")

        PixelTracker.shared.intialise(brPixel: brPixel)       
    
        return true
  }
}

If you are using SwiftUI, use the UIApplicationDelegateAdaptor property wrapper to tell SwiftUI it should use your AppDelegate class for the application delegate.

@main
struct MyApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Make sure to replace all the placeholder values for the parameter values in the snippet above.


Here is a reference of all the different parameters you can set based on your requirements:

ParameterDescription
accountIdYour Account ID provided by Bloomreach during integration
uuidA 13 Digit random number.
Eg: 2342698118212
visitorTypeenum type for new or returning visitors
baseUrlBase URL of your site, provided by Bloomreach
domainKey
(Optional)
The Bloomreach-provided ID of the domain receiving the request
userId
(Optional)
Unique ID used to track the visitor. This parameter is only required if you track visitors via a universal customer ID
testData
(Optional)
Enter a Boolean value. Set test_data to false in the pixel for your prod release app
currency
(Optional)
Regional currency or currency used in the app
debugMode
(Optional)
Set this to true to get valuable debugging info and insights from the Events Manager . By default, this is set to false
pixelUrlByRegionURL for Pixel server based on region. Defaults to the NA region
customerTierTier that the visitor belongs to. eg: Premium, Gold. For use with Relevance by Segment
customerCountryCountry that the visitor belongs to or is accessing the site from. For use with Relevance by Segment
customerGeoGeography or Region that the visitor belongs to. For use with Relevance by Segment
customerProfileProfile of the visitor. For use with Relevance by Segment
viewId
(Optional)
This parameter is only required if you are integrating on a site with multiple site versions with unique product catalog characteristics. Otherwise, viewId should not be declared in the pixel as this might cause issues with analytics.

During your technical kickoff call, the Bloomreach integrations team will inform you whether viewId will be required for your pixel integration or not.

The value must be consistent with the view_id value passed in the feed and API calls.

📘

The value of any of the above parameters can be modified later in the code, even after initialization. It can be done by using the following line:

PixelTracker.shared.brPixel.<FIELD_NAME> = <VALUE>

3. Triggering Pixels

Refer to the following guides to Trigger specific pixels in your Android Application:

4. Pixel validation

You can test the integration of the Pixel SDK using the Pixel validator built inside the SDK. No additional integration is needed.
The Pixel validator only works in debug mode. The response from Pixel validation will be printed in Logs of xCode, as below:

988