Skip to content

fix: Define PostHog.init at gem load time#118

Open
304 wants to merge 1 commit intoPostHog:mainfrom
304:fix/init-not-available-in-initializers
Open

fix: Define PostHog.init at gem load time#118
304 wants to merge 1 commit intoPostHog:mainfrom
304:fix/init-not-available-in-initializers

Conversation

@304
Copy link
Copy Markdown

@304 304 commented Apr 13, 2026

Closes #106

PostHog.init was defined inside a Rails
initializer (posthog.set_configs), so it wasn't available until that initializer ran. In some Rails boot sequences,
config/initializers/posthog.rb loaded first, causing NoMethodError: undefined method 'init' for module PostHog.

This moves PostHog.init and delegated methods (capture, identify, etc.) to posthog/rails.rb so they're available immediately when the gem is required - before any initializers run.

PostHog.init was defined inside a Rails
initializer (`posthog.set_configs`), so it wasn't available until that
initializer ran. In some Rails boot sequences,
`config/initializers/posthog.rb` loaded first, causing `NoMethodError:
undefined method 'init' for module PostHog`.

This moves PostHog.init and delegated methods (capture, identify, etc.)
to `posthog/rails.rb` so they're available immediately when the gem
is required - before any initializers run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

undefined method `init' for module PostHog (NoMethodError)

1 participant