{"id":27353624,"url":"https://github.com/posthog/posthog-elixir","last_synced_at":"2025-04-12T21:06:40.040Z","repository":{"id":57535986,"uuid":"270059733","full_name":"PostHog/posthog-elixir","owner":"PostHog","description":"Elixir client for Posthog","archived":false,"fork":false,"pushed_at":"2025-03-31T10:43:29.000Z","size":62,"stargazers_count":31,"open_issues_count":6,"forks_count":16,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T20:37:44.917Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PostHog.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-06-06T17:55:05.000Z","updated_at":"2025-04-09T18:54:44.000Z","dependencies_parsed_at":"2024-11-07T16:02:34.815Z","dependency_job_id":"8b7bb4fe-6fe3-4ec4-a19a-5059e222e6f2","html_url":"https://github.com/PostHog/posthog-elixir","commit_stats":null,"previous_names":["whitepaperclip/posthog","posthog/posthog-elixir","nkezhaya/posthog"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fposthog-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fposthog-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fposthog-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fposthog-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PostHog","download_url":"https://codeload.github.com/PostHog/posthog-elixir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631686,"owners_count":21136555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-12T21:06:39.464Z","updated_at":"2025-04-12T21:06:40.032Z","avatar_url":"https://github.com/PostHog.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostHog Elixir Client\n\n[![Hex.pm](https://img.shields.io/hexpm/v/posthog.svg)](https://hex.pm/packages/posthog)\n[![Documentation](https://img.shields.io/badge/documentation-gray)](https://hexdocs.pm/posthog)\n\nA powerful Elixir client for [PostHog](https://posthog.com), providing seamless integration with PostHog's analytics and feature flag APIs.\n\n## Features\n\n- Event Capture: Track user actions and custom events\n- Feature Flags: Manage feature flags and multivariate tests\n- Batch Processing: Send multiple events efficiently\n- Custom Properties: Support for user, group, and person properties\n- Flexible Configuration: Customizable JSON library and API version\n\n## Installation\n\nAdd `posthog` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:posthog, \"~\u003e 0.3\"}\n  ]\nend\n```\n\n## Configuration\n\nAdd your PostHog configuration to your application's config:\n\n```elixir\n# config/config.exs\nconfig :posthog,\n  api_url: \"https://app.posthog.com\",  # Or your self-hosted PostHog instance URL\n  api_key: \"phc_your_project_api_key\"\n\n# Optional configurations\nconfig :posthog,\n  json_library: Jason,  # Default JSON parser (optional)\n  version: 3           # API version (optional, defaults to 3)\n```\n\n## Usage\n\n### Capturing Events\n\nSimple event capture:\n\n```elixir\n# Basic event\nPosthog.capture(\"page_view\", distinct_id: \"user_123\")\n\n# Event with properties\nPosthog.capture(\"purchase\", [\n  distinct_id: \"user_123\",\n  properties: %{\n    product_id: \"prod_123\",\n    price: 99.99,\n    currency: \"USD\"\n  }\n])\n\n# Event with custom timestamp\nPosthog.capture(\"signup_completed\",\n  [distinct_id: \"user_123\"],\n  DateTime.utc_now()\n)\n\n# Event with custom headers\nPosthog.capture(\"login\",\n  [distinct_id: \"user_123\"],\n  [headers: [{\"x-forwarded-for\", \"127.0.0.1\"}]]\n)\n```\n\n### Batch Processing\n\nSend multiple events in a single request:\n\n```elixir\nevents = [\n  {\"page_view\", [distinct_id: \"user_123\"], nil},\n  {\"button_click\", [distinct_id: \"user_123\", properties: %{button_id: \"signup\"}], nil}\n]\n\nPosthog.batch(events)\n```\n\n### Feature Flags\n\nGet all feature flags for a user:\n\n```elixir\n{:ok, flags} = Posthog.feature_flags(\"user_123\")\n\n# Response format:\n# %{\n#   \"featureFlags\" =\u003e %{\"flag-1\" =\u003e true, \"flag-2\" =\u003e \"variant-b\"},\n#   \"featureFlagPayloads\" =\u003e %{\n#     \"flag-1\" =\u003e true,\n#     \"flag-2\" =\u003e %{\"color\" =\u003e \"blue\", \"size\" =\u003e \"large\"}\n#   }\n# }\n```\n\nCheck specific feature flag:\n\n```elixir\n# Boolean feature flag\n{:ok, flag} = Posthog.feature_flag(\"new-dashboard\", \"user_123\")\n# Returns: %Posthog.FeatureFlag{name: \"new-dashboard\", value: true, enabled: true}\n\n# Multivariate feature flag\n{:ok, flag} = Posthog.feature_flag(\"pricing-test\", \"user_123\")\n# Returns: %Posthog.FeatureFlag{\n#   name: \"pricing-test\",\n#   value: %{\"price\" =\u003e 99, \"period\" =\u003e \"monthly\"},\n#   enabled: \"variant-a\"\n# }\n\n# Quick boolean check\nif Posthog.feature_flag_enabled?(\"new-dashboard\", \"user_123\") do\n  # Show new dashboard\nend\n```\n\nFeature flags with group properties:\n\n```elixir\nPosthog.feature_flags(\"user_123\",\n  groups: %{company: \"company_123\"},\n  group_properties: %{company: %{industry: \"tech\"}},\n  person_properties: %{email: \"user@example.com\"}\n)\n```\n\n## Local Development\n\nWe recommend using `asdf` to manage Elixir and Erlang versions:\n\n```sh\n# Install required versions\nasdf install\n\n# Install dependencies\nmix deps.get\nmix compile\n```\n\n### Troubleshooting\n\nIf you encounter WX library issues during Erlang installation:\n\n```sh\n# Disable WX during installation\nexport KERL_CONFIGURE_OPTIONS=\"--without-wx\"\nasdf install\n```\n\nTo persist this setting, add it to your shell configuration file (`~/.bashrc`, `~/.zshrc`, or `~/.profile`).\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthog%2Fposthog-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthog%2Fposthog-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthog%2Fposthog-elixir/lists"}