PostHog / posthog-js

Send usage data from your web app or site to PostHog, with autocapture.
https://posthog.com/docs/libraries/js
Other
265 stars 108 forks source link

using the API before posthog.init() is called #1121

Open aroman opened 4 months ago

aroman commented 4 months ago

is it safe to call posthog methods (e.g. posthog.capture) before posthog.init() has been called? will they be queued and flushed when (and if) the posthog client is eventually initialized?

I ask because we are considering moving to an architecture where we lazily initialize posthog once some async initial data is fetched (e.g. an initial distinctID for providing to posthog.initialize({bootstrap: distinctId})

aroman commented 4 months ago

from a quick skim of the source, it looks like the answer to my question is "no, don't do that"

however, I'd love for someone on the posthog team to chime in here as to the recommended best practice when a user's distinct ID is not known immediately