Braze iOS Integration

Table of Contents

  • Getting started
    • Integrate your project with Bluedot Point SDK
    • Integrate your project with Braze’s Appboy SDK
  • Interaction between Appboy SDK and Bluedot Point SDK
    • Start Appboy SDK Services
    • Setup Bluedot Location Services

Getting started

This documentation depends on BluedotPointSDK and Appboy-iOS-SDK. Both dependencies can be managed by CocoaPods.

Integrate your project with Bluedot Point SDK

You can find detailed instructions at https://docs.bluedot.io/ios-sdk/ios-integrating-the-sdk/

  1. Implement BluedotPointSDKimport BDPointSDK to your class:import BDPointSDK
  2. Implement Bluedot location delegate:
    // Swift
    class YourClass: BDPLocationDelegate {
    
        func didCheck(
            intoFence fence: BDFenceInfo!,
            inZone zoneInfo: BDZoneInfo!,
            willCheckOut: Bool,
            withCustomData customData: [AnyHashable : Any]!
         ) {
     
            // Your logic when the device enters a Bluedot Zone
    
         }
    
         func didCheckOut(
             fromFence fence: BDFenceInfo!,
             inZone zoneInfo: BDZoneInfo!,
             on date: Date!,
             withDuration checkedInDuration: UInt,
             withCustomData customData: [AnyHashable : Any]!
         ) {
     
            // Your logic when the device leaves a Bluedot Zone
     
         }
    
         // Beacons entry / exit. This is optional, unless beacons are used.
         func didCheck(
             intoBeacon beacon: BDBeaconInfo!,
             inZone zoneInfo: BDZoneInfo!,
             atLocation locationInfo: BDLocationInfo!,
             with proximity: CLProximity,
             willCheckOut: Bool,
             withCustomData customData: [AnyHashable : Any]!
          ) {
    
             // Your logic when the device enters in the range of beacon in a Bluedot Zone
    
          }
    
    
          func didCheckOut(
              fromBeacon beacon: BDBeaconInfo!,
              inZone zoneInfo: BDZoneInfo!,
              with proximity: CLProximity,
              on date: Date!,
              withDuration checkedInDuration: UInt,
              withCustomData customData: [AnyHashable : Any]! 
          ) {
    
              // your logic when a devices leaves the range of beacon of a Bluedot Zone
    
          }
    }
  3. Assign location delegate with your implementation
    // Swift
    let instanceOfYourClass = YourClass()
    BDLocationManager.instance()?.locationDelegate = instanceOfYourClass
  4. Authenticate with the Bluedot services
    // Swift
    BDLocationManager.instance()?.authenticate(withApiKey: "Your assigned Bluedot API Key", requestAuthorization: .authorizedAlways)

Integrate your project with Appboy SDK

Import Appboy-iOS-SDK to your class

Swift
import Appboy_iOS_SDK

Start Appboy-iOS-SDK within the application:didFinishLaunchingWithOptions method.
For further information refer to Braze Developer Documentation

// Swift
Appboy.start(withApiKey: "Your assigned Braze API Key", in: application, withLaunchOptions: launchOptions)

Track Braze custom events in your Bluedot Entry / Exit events.

func didCheck(
    intoFence fence: BDFenceInfo!,
    inZone zoneInfo: BDZoneInfo!,
    atLocation location: BDLocationInfo!,
    willCheckOut: Bool,
    withCustomData customData: [AnyHashable : Any]!
) {
    // Name the custom event 
    let customEventName = "bluedot_entry"

    // Map the Location and Bluedot Zone attributes into a properties dictionary
    var properties = [
        "zone_id": "\(zoneInfo.id!)",
        "zone_name": "\(zoneInfo.name!)",
        "latitude": "\(location.latitude)",
        "longitude": "\(location.longitude)",
        "speed": "\(location.speed)",
        "bearing": "\(location.bearing)",
        "timestamp": "\(location.timestamp!)",
    ]

    // Map the Custom Data attributes into properties
    if customData != nil && !customData.isEmpty {
        customData.forEach { data in properties["\(data.key)"] = "\(data.value)"}
    }

    // Log the Custom Event in Appboy
    Appboy.sharedInstance()?.logCustomEvent(customEventName, withProperties: properties );
}

func didCheckOut(
    fromFence fence: BDFenceInfo!,
    inZone zoneInfo: BDZoneInfo!,
    on date: Date!,
    withDuration checkedInDuration: UInt,
    withCustomData customData: [AnyHashable : Any]!
) {
    // Name the custom event
    let customEventName = "bluedot_exit"
 
    // Map the Zone attributes into a properties dictionary
    var properties = [
        "zone_id": "\(zoneInfo.id!)",
        "zone_name": "\(zoneInfo.name!)",
        "timestamp": "\(date!)",
        "checkedInDuration": "\(checkedInDuration)"
    ]
 
    // Map the Custom Data attributes into properties
    if customData != nil && !customData.isEmpty {
        customData.forEach { data in properties["\(data.key)"] = "\(data.value)"}
    }

    // Log the Custom Event in Appboy
    Appboy.sharedInstance()?.logCustomEvent(customEventName, withProperties: properties );
}
Created by Daniel Toro on August 6, 2019