                 typealias shareInstanceFunc = @convention(c) (AnyObject, Selector) -> AnyObject?
                 let curriedImplementation = unsafeBitCast(appBoyShareInstanceIMP, to: shareInstanceFunc.self)
                 if let instance = curriedImplementation(brazeClass.self, shareInstanceSel) {
+                    if let deviceId = instance.perform(NSSelectorFromString("getDeviceId"))?.takeUnretainedValue() as? String {
+                        if deviceId != self.savedDeviceId {
+                            self.mixpanel?.createAlias(deviceId, distinctId: (self.mixpanel?.distinctId)!)
+                            self.mixpanel?.people.set(property: "$braze_device_id", to: deviceId)
+                            self.savedDeviceId = deviceId
+                        }
+                    }
                     if let user = instance.perform(NSSelectorFromString("user"))?.takeUnretainedValue() {
                         if let userId = user.perform(NSSelectorFromString("userID"))?.takeUnretainedValue() as? String {
-                            self.mixpanel?.createAlias(userId, distinctId: (self.mixpanel?.distinctId)!)
-                            self.mixpanel?.people.set(property: "$braze_external_id", to: userId)
-                            self.savedBrazeID = userId
+                            if userId != self.savedBrazeID {
+                                self.mixpanel?.createAlias(userId, distinctId: (self.mixpanel?.distinctId)!)
+                                self.mixpanel?.people.set(property: "$braze_external_id", to: userId)
+                                self.savedBrazeID = userId
+                            }
                         }
                     }
                 }

    open func reset() {
        self.savedUrbanAirshipChannelID = nil
        self.savedBrazeID = nil
        self.urbanAirshipRetries = 0
    }
}

    var urbanAirshipRetries = 0
    var savedUrbanAirshipChannelID: String?
    var savedBrazeID: String?
    var savedDeviceId: String?

    open func setupIntegrations(_ integrations:[String]) {
        if integrations.contains("urbanairship") {
