capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

feat(posthog): accept strings and primitives as super property values

Open djabif opened this issue 6 months ago • 6 comments

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.

djabif avatar Jun 20 '25 14:06 djabif

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.

robingenz avatar Jun 22 '25 10:06 robingenz

Hi @robingenz, sure, as soon as I find a little time I will work on it 🙌🏽

djabif avatar Jun 23 '25 14:06 djabif

@robingenz Can i work on this?

nicogenz avatar Nov 13 '25 20:11 nicogenz

@nicogenz Yesss 🙌🏻

robingenz avatar Nov 13 '25 20:11 robingenz

Ohhh may bad, sorry, I totally forgot about this 🫣🫣🫣

djabif avatar Nov 13 '25 23:11 djabif

@djabif No problem at all! 🙂

robingenz avatar Nov 14 '25 04:11 robingenz