PostHog / posthog-flutter

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

Add an explanation about config.debug and Posthog().debug() #121

Closed jakobhec closed 1 week ago

jakobhec commented 1 week ago

Problem Statement

It would be really helpful if the com.posthog.posthog.DEBUG parameter, config.debug and Posthog().debug() had an explanation, ideally directly in the code.

  1. What does config.debug do in this example from the documentation? https://github.com/PostHog/posthog-flutter

    Future<void> main() async {
        // init WidgetsFlutterBinding if not yet
        WidgetsFlutterBinding.ensureInitialized();
        final config = PostHogConfig('YOUR_API_KEY_GOES_HERE');
        config.debug = true;  // <=== this here
        config.captureApplicationLifecycleEvents = true;
        // or EU Host: 'https://eu.i.posthog.com'
        config.host = 'https://us.i.posthog.com';
        await Posthog().setup(config);
        runApp(MyApp());
    }
  2. Does it do the same as Posthog().debug(true)?

    Or does this code do the same as the code from the example above? I set it to false initially but then use .debug(true)?

    Future<void> main() async {
        // init WidgetsFlutterBinding if not yet
        WidgetsFlutterBinding.ensureInitialized();
        final config = PostHogConfig('YOUR_API_KEY_GOES_HERE');
        config.debug = false; // <=== this has changed
        config.captureApplicationLifecycleEvents = true;
        // or EU Host: 'https://eu.i.posthog.com'
        config.host = 'https://us.i.posthog.com';
        await Posthog().setup(config);
    
        Posthog().debug(true); // <=== this has changed
    
        runApp(MyApp());
    }
  3. Why is this always set to true in the examples? Does it make sense to set it to true only if we’re debugging the app? Does it make a difference?

    import 'package:flutter/foundation.dart';
    
    Posthog().debug(kDebugMode);

Solution Brainstorm

No response

marandaneto commented 1 week ago

Hello,

config.debug = true is just a shortcut for Posthog().debug(true), so the SDK already starts in debug mode and logs things in the console. Calling Posthog().debug(kDebugMode); at runtime will enable and disable logging based on your needs.

marandaneto commented 1 week ago

Somehow a dupe of https://github.com/PostHog/posthog-flutter/issues/88 that we can address in this other ssue

jakobhec commented 1 week ago

So, this is just about printing to the console? It doesn’t affect the functionality or the events being sent at all?

marandaneto commented 1 week ago

So, this is just about printing to the console? It doesn’t affect the functionality or the events being sent at all?

Correct. https://posthog.com/docs/libraries/android#all-configuration-options

// Logs the SDK messages into Logcat. (off/false by default)

Same goes for iOS.