Skip to content

Commit f6a5086

Browse files
Merge pull request #54 from martosaur/am-2.0-migration-guide
2 parents 4d900bc + da5d1f6 commit f6a5086

5 files changed

Lines changed: 79 additions & 23 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,21 @@ jobs:
1313
# This is a complicated set of strategies, but Elixir has a complicated set of supported versions.
1414
# See https://hexdocs.pm/elixir/compatibility-and-deprecations.html
1515
# See https://hexdocs.pm/elixir/compatibility-and-deprecations.html#between-elixir-and-erlang-otp
16-
#
17-
# NOTE: We're intentionally not including Elixir 1.14.x + OTP 23.x
18-
# because erlef/setup-beam@v1 doesn't support it.
1916
strategy:
2017
matrix:
21-
elixir: ["1.14.x", "1.15.x", "1.16.x", "1.17.x", "1.18.x"]
18+
elixir: ["1.15.x", "1.16.x", "1.17.x", "1.18.x"]
2219
otp: ["24.x", "25.x", "26.x", "27.x"]
2320
exclude:
2421
# Elixir 1.17 and 1.18 don't support OTP 24
2522
- elixir: "1.17.x"
2623
otp: "24.x"
2724
- elixir: "1.18.x"
2825
otp: "24.x"
29-
# Elixir 1.14, 1.15 and 1.16 don't support OTP 27
26+
# Elixir 1.15 and 1.16 don't support OTP 27
3027
- elixir: "1.15.x"
3128
otp: "27.x"
3229
- elixir: "1.16.x"
3330
otp: "27.x"
34-
- elixir: "1.14.x"
35-
otp: "27.x"
3631

3732
steps:
3833
- uses: actions/checkout@v3

CHANGELOG.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
## 2.0.0 - 2025-09-30
2+
3+
### Major Release
4+
5+
`posthog-elixir` was fully reworked. Check [migration guide](MIGRATION.md#v1-v2)
6+
for some tips on how to upgrade.
7+
8+
Huge thanks to community member [@martosaur](https://github.com/martosaur) for contributing this new version.
9+
10+
### What's new
11+
12+
- Elixir v1.15+ required
13+
- Event capture is now offloaded to background workers with automatic batching
14+
- [Context](README.md#context) mechanism for easier property propagation
15+
- [Error Tracking](README.md#error-tracking) support
16+
- New `PostHog.FeatureFlags` module for working with feature flags
17+
- [Test mode](`PostHog.Test`) for easier testing
18+
- Customizable [HTTP client](`PostHog.API.Client`) with Req as the default
19+
- [Plug integration](`PostHog.Integrations.Plug`) for automatically capturing common HTTP properties
20+
121
## 1.1.0 - 2025-07-01
222

323
- Expose `capture/2` `b077aba849126c63f1c7a82b6ad9d21945871a4a`
@@ -24,7 +44,7 @@
2444

2545
- Elixir v1.14+ is now a requirement
2646
- Feature Flags now return a key called `payload` rather than `value` to better align with the other SDKs
27-
- PostHog now requires you to initialize `PostHog.Application` alongside your supervisor tree. This is required because of our `Cachex` system to properly track your FF usage.
47+
- PostHog now requires you to initialize `Posthog.Application` alongside your supervisor tree. This is required because of our `Cachex` system to properly track your FF usage.
2848
- We'll also include local evaluation in the near term, which will also require a GenServer, therefore, requiring us to use a Supervisor.
2949
- Added `enabled_capture` configuration option to disable PostHog tracking in development/test environments
3050
- `PostHog.capture` now requires `distinct_id` as a required second argument

MIGRATION.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,42 @@ This is a migration guide for all major version bumps
44

55
## v1 -> v2
66

7-
TODO: New library
7+
Version 2.0 is a whole new library, so we encourage you to use this upgrade as
8+
an opportunity to revisit your PostHog usage in your application. Even the root
9+
level module was renamed from `Posthog` to `PostHog`.
10+
11+
### Configuration
12+
13+
Configuration has been completely reworked. We advise you to remove your
14+
existing configuration and follow [Getting Started](README.md#getting-started)
15+
section for setup.
16+
17+
### Event Capture
18+
19+
`PostHog.capture` signature has changed. It now accepts properties only as a
20+
map. `distinct_id` is now included in the properties.
21+
22+
```elixir
23+
PostHog.capture("user_signed_up", %{
24+
distinct_id: "distinct_id_of_the_user",
25+
login_type: "email",
26+
is_free_trial: true
27+
})
28+
```
29+
30+
No additional options can be passed. PostHog now automatically offloads events to a
31+
pool of sender workers that will batch and send your events. This also means
32+
that `Posthog.batch` doesn't exist anymore and you should simply call `capture/2` for each of your events.
33+
34+
### Feature Flags
35+
36+
`Posthog.feature_flag` and `Posthog.feature_flag_enabled` functions were
37+
replaced with `PostHog.FeatureFlags` module. Check its docs for the new usage
38+
guidelines.
839

940
## v0 -> v1
1041

11-
When we stabilized our library, we decided to pull some breaking changes, here are they and how you can migrate:
42+
When we stabilized our library, we decided to pull some breaking changes.
1243

1344
### Minimum Elixir version bumped to v1.14
1445

@@ -19,9 +50,9 @@ The library previously supported Elixir v1.12+. You'll need to migrate to Elixir
1950

2051
### Decide v4 - Feature Flags
2152

22-
PostHog is consistently upgrading our internal data representation so that's better for customers each and every time. We've recently launched a new version of our `/decide` endpoint called `v4`. This endpoint is slightly different, which caused a small change in behavior for our flags.
53+
PostHog is consistently upgrading our internal data representation so that it's better for users each and every time. We've recently launched a new version of our `/decide` endpoint called `v4`. This endpoint is slightly different, which caused a small change in behavior for our flags.
2354

24-
`PostHog.FeatureFlag` previously included a key `value` that to represent the internal structure of a flag. It was renamed to `payload` to:
55+
`PostHog.FeatureFlag` previously included a key `value` to represent the internal structure of a flag. It was renamed to `payload` to:
2556

2657
1. better represent the fact that it can be both an object and a boolean
2758
2. align it more closely with our other SDKs
@@ -43,7 +74,7 @@ def application do
4374
end
4475
```
4576

46-
2. Or, if you're already using an Application, you can add add `PostHog.Application` to your own supervision tree:
77+
2. Or, if you're already using an Application, you can add `Posthog.Application` to your own supervision tree:
4778

4879
```elixir
4980
# lib/my_app/application.ex

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Add `PostHog` to your dependencies:
2121
```elixir
2222
def deps do
2323
[
24-
{:posthog, "~> 0.3"}
24+
{:posthog, "~> 2.0"}
2525
]
2626
end
2727
```
@@ -37,7 +37,14 @@ config :posthog,
3737
in_app_otp_apps: [:my_app]
3838
```
3939

40-
Optionally, enable [Plug integration](`PostHog.Integrations.Plug`) for better Error Tracking
40+
For test environment, you want to enable test_mode:
41+
42+
```elixir
43+
config :posthog,
44+
test_mode: true
45+
```
46+
47+
Optionally, enable [Plug integration](`PostHog.Integrations.Plug`).
4148

4249
You're all set! 🎉 For more information on configuration, check the `PostHog.Config` module
4350
documentation and the [advanced configuration guide](advanced-configuration.md).
@@ -188,14 +195,17 @@ To run integration test suite that sends real events to the API:
188195

189196
1. Create a test PostHog project and obtain an API key.
190197
2. Create `config/integration.exs` config that will be used for integration tests:
191-
```
192-
cp config/integration.example.exs config/integration.exs
193-
```
198+
199+
```
200+
cp config/integration.example.exs config/integration.exs
201+
```
202+
194203
3. Put API key into `config/integration.exs`
195204
4. Run integration tests
196-
```
197-
mix test --only integration
198-
```
205+
206+
```
207+
mix test --only integration
208+
```
199209

200210
If you want to play with PostHog events in IEx, you'll need to create
201211
`config/dev.exs` and configure your dev instance to your liking. Here a
@@ -207,4 +217,4 @@ import Config
207217
config :posthog,
208218
public_url: "https://us.i.posthog.com",
209219
api_key: "phc_XXXX"
210-
```
220+
```

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ defmodule PostHog.MixProject do
5252
Integrations: [PostHog.Integrations.Plug],
5353
Testing: [PostHog.Test]
5454
],
55-
skip_undefined_reference_warnings_on: ["CHANGELOG.md", "MIGRATION.md"]
55+
skip_code_autolink_to: &String.starts_with?(&1, "Posthog")
5656
]
5757
end
5858

0 commit comments

Comments
 (0)