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-quick-start

  1. Import BDPointSDK to your class:import BDPointSDK
  2. Implement Bluedot BDPGeoTriggeringEventDelegate:
    // Swift
    extension YourClass: BDPGeoTriggeringEventDelegate {
    
        func didEnterZone(_ enterEvent: BDZoneEntryEvent) {
            // Your logic when the device enters a Bluedot Zone
        }
    
         func didExitZone(_ exitEvent: BDZoneExitEvent) {
            // Your logic when the device leaves a Bluedot Zone
         }
    }
  3. Assign GeoTriggeringEvent delegate with your implementation
    // Swift
    let instanceOfYourClass = YourClass()
    BDLocationManager.instance()?.geoTriggeringEventDelegate = instanceOfYourClass
  4. Authenticate with the Bluedot services
    // Swift
    
    BDLocationManager.instance()?.initialize(withProjectId: projectId){ error in
         guard error == nil else {
            print("There was an error initializing the Bluedot SDK: \(error.localizedDescription)")
            return
         }
    }

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 didEnterZone(_ enterEvent: BDZoneEntryEvent) {
    // Name the custom event 
    let customEventName = "bluedot_entry"

    // Map the Location and Bluedot Zone attributes into a properties dictionary

    var properties = [
        "zone_id": "\(enterEvent.zone().id!)",
        "zone_name": "\(enterEvent.zone().name!)",
        "latitude": "\(enterEvent.location.latitude)",
        "longitude": "\(enterEvent.location.longitude)",
        "speed": "\(enterEvent.location.speed)",
        "bearing": "\(enterEvent.location.bearing)",
        "timestamp": "\(enterEvent.location.timestamp!)"
    ]

    // Map the Custom Data attributes into properties

    if let customData = enterEvent.zone().customData, !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(_ exitEvent: BDZoneExitEvent) {
    // Name the custom event
    let customEventName = "bluedot_exit"
 
    // Map the Zone attributes into a properties dictionary

    var properties = [
        "zone_id": "\(exitEvent.zone().id!)",
        "zone_name": "\(exitEvent.zone().name!)",
        "timestamp": "\(exitEvent.date)",
        "checkedInDuration": "\(exitEvent.duration)"
    ]

 
    // Map the Custom Data attributes into properties

    if let customData = exitEvent.zone().customData, !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