Skip to content

Commit 818edc2

Browse files
authored
feat: we should capture which properties were added as tags (#304)
1 parent 0507435 commit 818edc2

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 6.5.0 - 2025-08-08
2+
3+
- feat: Add `$context_tags` to an event to know which properties were included as tags
4+
15
# 6.4.1 - 2025-08-06
26

37
- fix: Always pass project API key in `remote_config` requests for deterministic project routing

posthog/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def add_context_tags(properties):
8787
current_context = _get_current_context()
8888
if current_context:
8989
context_tags = current_context.collect_tags()
90+
properties["$context_tags"] = set(context_tags.keys())
9091
# We want explicitly passed properties to override context tags
9192
context_tags.update(properties)
9293
properties = context_tags

posthog/test/test_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from posthog.test.test_utils import FAKE_TEST_API_KEY
1414
from posthog.types import FeatureFlag, LegacyFlagMetadata
1515
from posthog.version import VERSION
16+
from posthog.contexts import tag
1617

1718

1819
class TestClient(unittest.TestCase):
@@ -2354,3 +2355,15 @@ def test_get_all_flags_and_payloads_with_empty_string(self, patch_batch_post):
23542355
self.assertEqual(
23552356
result["featureFlagPayloads"]["normal-payload-flag"], "normal payload"
23562357
)
2358+
2359+
def test_context_tags_added(self):
2360+
with mock.patch("posthog.client.batch_post") as mock_post:
2361+
client = Client(FAKE_TEST_API_KEY, on_error=self.set_fail, sync_mode=True)
2362+
2363+
with new_context():
2364+
tag("random_tag", 12345)
2365+
client.capture("python test event", distinct_id="distinct_id")
2366+
2367+
batch_data = mock_post.call_args[1]["batch"]
2368+
msg = batch_data[0]
2369+
self.assertEqual(msg["properties"]["$context_tags"], ["random_tag"])

posthog/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "6.4.1"
1+
VERSION = "6.5.0"
22

33
if __name__ == "__main__":
44
print(VERSION, end="") # noqa: T201

0 commit comments

Comments
 (0)