PostHog / posthog-flutter

PostHog Flutter SDK
https://posthog.com/docs/libraries/flutter
MIT License
55 stars 37 forks source link

Desktop (Windows/Linux) support #51

Open marandaneto opened 1 year ago

marandaneto commented 1 year ago

https://posthog.com/questions/flutter-for-windows-support https://posthoghelp.zendesk.com/agent/tickets/16890

The Flutter SDK depends on the Android and iOS SDK. Ideally, the SDK would also have a pure Dart client that works on Desktop or we should embed a Native SDK for Desktop such as the Rust SDK.

macOS is supported already.

marandaneto commented 1 year ago

A workaround, for now, would be to create a Flutter bridge and call a Native SDK via FFI, eg, Rust SDK

CaptainDario commented 10 months ago

Is there anything planned in regard to this? I would like to switch to this plugin but I need desktop support.

marandaneto commented 10 months ago

@CaptainDario unfortunately not yet, but please upvote for gathering interest.

We'd need to write a pure Dart SDK (not depending on the Native SDKs such as Android and iOS for Desktop) or embed a Native SDK for Desktop, such as the Rust SDK.

However, adding macOS support should be easier since the iOS SDK supports a macOS target.

Which targets do you need? Win/Lin/macOS or all of them?

CaptainDario commented 10 months ago

Thank you for the quick response! I upvoted this issue.

I would need support for all platforms. But I also see quite an opportunity in supporting these platforms for this package. Because firebase does not support desktop, and everybody needing desktop support will look somewhere else (just like me)

marandaneto commented 10 months ago

A quick workaround, for now, is to just call the API directly until we provide first-class support for Flutter Desktop.

CaptainDario commented 10 months ago

I totally missed the direct API access, this seems like a good solution.

CaptainDario commented 10 months ago

@marandaneto How can I overwrite the default timestamp? When I try to set it the events are not registered anymore in the web UI.

This works and the event is registered in the UI

Map response = jsonDecode((await http.post(
    Uri.parse('https://eu.posthog.com/capture/'),
    headers: {
      "Content-Type": "application/json",
    },
    body: jsonEncode({
      "api_key": Env.POSTHOG_API_KEY,
      "event": eventName,
      "properties" : completeProps,
      //"timestamp" : DateTime(2023, 10, 5).toIso8601String(),
    })
  )).body);

this even is not registered.

Map response = jsonDecode((await http.post(
    Uri.parse('https://eu.posthog.com/capture/'),
    headers: {
      "Content-Type": "application/json",
    },
    body: jsonEncode({
      "api_key": Env.POSTHOG_API_KEY,
      "event": eventName,
      "properties" : completeProps,
      "timestamp" : DateTime(2023, 10, 5).toIso8601String(),
    })
  )).body);

However, in both cases, the return value is "{status: 1}". Do you have an idea how to overwrite it?

Edit: It works I had the time filters set to 24h.

CaptainDario commented 10 months ago

For anybody finding this, the current time can be set with (DateTime.now().toUtc()).toIso8601String().

marandaneto commented 10 months ago

For anybody finding this, the current time can be set with (DateTime.now().toUtc()).toIso8601String().

Yes, the docs mention the ISO8601 format.

CaptainDario commented 10 months ago

Yes, the format is mentioned, but they did not mention (or I did not see) that the time needs to be normalized to UTC. When sending my time zone (UTC+1), the server did not return an error, it sent the same response as with UTC but the data was not visible in the dashboard.

If this is obvious, I am sorry to spam this issue, I thought somebody else may have the same problems.

marandaneto commented 10 months ago

macOS support has landed at least https://github.com/PostHog/posthog-flutter/releases/tag/4.0.0-beta.2

stephane-archer commented 6 months ago

I hope to see a Windows version even if it's a quick and dirty version with helpers that call the API directly.

krll-kov commented 2 months ago

Waiting for windows support