Skip to main content

init

Function init 

Source
pub fn init(options: impl Into<ClientOptions>) -> ClientGuard
Expand description

Initializes the PostHog client with the given configuration.

Returns a ClientGuard that must be held for the duration of the application. When the guard is dropped, it triggers graceful shutdown of the background worker.

If no API key is provided in the configuration, the client will not be initialized. Event capture calls will be no-ops in this case.

§Panics

Panics if called more than once.

§Examples

let _guard = better_posthog::init(better_posthog::ClientOptions {
  api_key: Some("phc_your_api_key".into()),
  host: better_posthog::Host::EU,
  shutdown_timeout: std::time::Duration::from_secs(5),
});