PostHogConfig

open class PostHogConfig(val apiKey: String, val host: String = DEFAULT_HOST, var debug: Boolean = false, var sendFeatureFlagEvent: Boolean = true, var preloadFeatureFlags: Boolean = true, var remoteConfig: Boolean = true, var flushAt: Int = DEFAULT_FLUSH_AT, var maxQueueSize: Int = DEFAULT_MAX_QUEUE_SIZE, var maxBatchSize: Int = DEFAULT_MAX_BATCH_SIZE, var flushIntervalSeconds: Int = DEFAULT_FLUSH_INTERVAL_SECONDS, var encryption: PostHogEncryption? = null, var onFeatureFlags: PostHogOnFeatureFlags? = null, var proxy: Proxy? = null, var featureFlagCacheSize: Int = DEFAULT_FEATURE_FLAG_CACHE_SIZE, var featureFlagCacheMaxAgeMs: Int = DEFAULT_FEATURE_FLAG_CACHE_MAX_AGE_MS, var featureFlagCalledCacheSize: Int = DEFAULT_FEATURE_FLAG_CALLED_CACHE_SIZE, var localEvaluation: Boolean = false, var personalApiKey: String? = null, var pollIntervalSeconds: Int = DEFAULT_POLL_INTERVAL_SECONDS, var evaluationContexts: List<String>? = null)

The SDK Config

Constructors

Link copied to clipboard
constructor(apiKey: String, host: String = DEFAULT_HOST, debug: Boolean = false, sendFeatureFlagEvent: Boolean = true, preloadFeatureFlags: Boolean = true, remoteConfig: Boolean = true, flushAt: Int = DEFAULT_FLUSH_AT, maxQueueSize: Int = DEFAULT_MAX_QUEUE_SIZE, maxBatchSize: Int = DEFAULT_MAX_BATCH_SIZE, flushIntervalSeconds: Int = DEFAULT_FLUSH_INTERVAL_SECONDS, encryption: PostHogEncryption? = null, onFeatureFlags: PostHogOnFeatureFlags? = null, proxy: Proxy? = null, featureFlagCacheSize: Int = DEFAULT_FEATURE_FLAG_CACHE_SIZE, featureFlagCacheMaxAgeMs: Int = DEFAULT_FEATURE_FLAG_CACHE_MAX_AGE_MS, featureFlagCalledCacheSize: Int = DEFAULT_FEATURE_FLAG_CALLED_CACHE_SIZE, localEvaluation: Boolean = false, personalApiKey: String? = null, pollIntervalSeconds: Int = DEFAULT_POLL_INTERVAL_SECONDS, evaluationContexts: List<String>? = null)

Types

Link copied to clipboard
class Builder(apiKey: String)
Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The PostHog API Key

Link copied to clipboard

Logs the debug logs to the logger if enabled Defaults to false

Link copied to clipboard
var encryption: PostHogEncryption?

Hook for encrypt and decrypt events Devices are sandbox so likely not needed Defaults to no encryption

Link copied to clipboard

Evaluation contexts for feature flags List of contexts (e.g., "web", "mobile", "checkout") used to filter feature flag evaluations on the server side. Defaults to null

Link copied to clipboard

The maximum age of a feature flag cache record in memory in milliseconds Defaults to 5 minutes

Link copied to clipboard

The maximum size of the feature flag cache in memory Defaults to 1000

Link copied to clipboard

The maximum size of the feature flag called cache in memory. This cache prevents duplicate $feature_flag_called events from being sent by keeping track of per-user feature flag usage. Defaults to 1000

Link copied to clipboard

Number of minimum events before they are sent over the wire Defaults to 20

Link copied to clipboard

Interval in seconds for sending events over the wire The lower the number, most likely more battery is used Defaults to 30s

Link copied to clipboard

The PostHog Host Defaults to https://us.i.posthog.com EU Host: https://eu.i.posthog.com

Link copied to clipboard

Enable local evaluation of feature flags When enabled, the SDK periodically fetches flag definitions and evaluates flags locally without making API calls for each flag check. Falls back to API if evaluation is inconclusive. Requires personalApiKey to be set. Defaults to false

Link copied to clipboard

Number of maximum events in a batch call Defaults to 50

Link copied to clipboard

Number of maximum events in memory and disk, when the maximum is exceed, the oldest event is deleted and the new one takes place Defaults to 1000

Link copied to clipboard
var onFeatureFlags: PostHogOnFeatureFlags?

Hook that is called when feature flag definitions are loaded. This is called immediately if local evaluation is not enabled. Defaults to no callback

Link copied to clipboard

Personal API key for local evaluation Required when localEvaluation is true. Defaults to null

Link copied to clipboard

Interval in seconds for polling feature flag definitions for local evaluation Defaults to 30 seconds

Link copied to clipboard

Preload feature flags automatically Docs https://posthog.com/docs/feature-flags and https://posthog.com/docs/experiments Defaults to true

Link copied to clipboard
var proxy: Proxy?

Hook that allows to sanitize the event properties The hook is called before the event is cached or sent over the wire

Link copied to clipboard

Preload PostHog remote config automatically Defaults to true

Link copied to clipboard

Send a $feature_flag_called event when a feature flag is used automatically Used by experiments

Functions

Link copied to clipboard
fun addBeforeSend(beforeSend: PostHogBeforeSend)
Link copied to clipboard
fun addIntegration(integration: PostHogIntegration)
Link copied to clipboard
fun removeBeforeSend(beforeSend: PostHogBeforeSend)