feat(posthog): accept strings and primitives as super property values
Plugin(s)
- [ ] Android Battery Optimization
- [ ] Android Dark Mode Support
- [ ] Android Edge-to-Edge Support
- [ ] Android Foreground Service
- [ ] App Review
- [ ] App Shortcuts
- [ ] App Update
- [ ] Asset Manager
- [ ] Audio Recorder
- [ ] Background Task
- [ ] Badge
- [ ] Bluetooth Low Energy
- [ ] Cloudinary
- [ ] Contacts
- [ ] Datetime Picker
- [ ] File Compressor
- [ ] File Opener
- [ ] File Picker
- [ ] Live Update
- [ ] Managed Configurations
- [ ] NFC
- [ ] Photo Editor
- [x] Posthog
- [ ] Printer
- [ ] Screen Orientation
- [ ] Screenshot
- [ ] Speech Recognition
- [ ] Speech Synthesis
- [ ] Torch
- [ ] Zip
Current problem
I would like to be able to register super properties with a primitive value like: test_user: true .
With the current implementation this is not possible because the register function expects a value of type object.
Preferred solution
Make register(_:) function flexible enough to accept either a simple value (like String, Int, etc.) or an object.
Something like this could work:
@objc func register(_ call: CAPPluginCall) {
guard let key = call.getString("key") else {
call.reject(CustomError.keyMissing.localizedDescription)
return
}
guard let rawValue = call.getAny("value") else {
call.reject(CustomError.valueMissing.localizedDescription)
return
}
// Wrap the value in AnyObject for compatibility with existing RegisterOptions
let value: AnyObject
if let object = rawValue as? [String: Any] {
value = object as AnyObject
} else if let string = rawValue as? String {
value = string as AnyObject
} else if let number = rawValue as? NSNumber {
value = number
} else {
call.reject("Unsupported value type for 'value'")
return
}
let options = RegisterOptions(key: key, value: value)
implementation?.register(options)
call.resolve()
}
Alternative options
No response
Additional context
No response
Before submitting
- [x] I have read and followed the feature request guidelines.
- [x] I have attached links to possibly related issues and discussions.
Hi @djabif, thank your for reprting that. That should actually be a bug. Would you be willing to create a PR? Otherwise, i would take a look but there is no ETA.
Hi @robingenz, sure, as soon as I find a little time I will work on it 🙌🏽
@robingenz Can i work on this?
@nicogenz Yesss 🙌🏻
Ohhh may bad, sorry, I totally forgot about this 🫣🫣🫣
@djabif No problem at all! 🙂