posthog-flutter icon indicating copy to clipboard operation
posthog-flutter copied to clipboard

Desktop (Windows/Linux) support

Open marandaneto opened this issue 1 year ago • 13 comments

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 avatar Oct 09 '23 06:10 marandaneto

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

marandaneto avatar Oct 09 '23 06:10 marandaneto

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

CaptainDario avatar Jan 14 '24 18:01 CaptainDario

@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?

marandaneto avatar Jan 15 '24 07:01 marandaneto

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)

CaptainDario avatar Jan 15 '24 09:01 CaptainDario

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

marandaneto avatar Jan 15 '24 11:01 marandaneto

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

CaptainDario avatar Jan 15 '24 13:01 CaptainDario

@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 avatar Jan 15 '24 15:01 CaptainDario

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

CaptainDario avatar Jan 15 '24 17:01 CaptainDario

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

Yes, the docs mention the ISO8601 format.

marandaneto avatar Jan 15 '24 17:01 marandaneto

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.

CaptainDario avatar Jan 15 '24 17:01 CaptainDario

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

marandaneto avatar Jan 17 '24 07:01 marandaneto

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

stephane-archer avatar May 15 '24 18:05 stephane-archer

Waiting for windows support

krll-kov avatar Sep 09 '24 13:09 krll-kov