Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d747bcea20 | ||
|
|
364760b83d | ||
|
|
33ccc37d4a |
+2
-2
@@ -41,9 +41,9 @@ print(posthog.feature_enabled("beta-feature-groups", "distinct_id", groups={"com
|
||||
|
||||
print(posthog.feature_enabled("beta-feature", "distinct_id"))
|
||||
|
||||
# # Alias a previous distinct id with a new one
|
||||
# Add an alias_id to a distinct_id
|
||||
|
||||
posthog.alias("distinct_id", "new_distinct_id")
|
||||
posthog.alias("distinct_id", "alias_id")
|
||||
|
||||
posthog.capture("new_distinct_id", "event2", {"property1": "value", "property2": "value"})
|
||||
posthog.capture(
|
||||
|
||||
+13
-6
@@ -199,8 +199,8 @@ def group_identify(
|
||||
|
||||
|
||||
def alias(
|
||||
previous_id, # type: str,
|
||||
distinct_id, # type: str,
|
||||
distinct_id, # type: str
|
||||
previous_id, # type: str
|
||||
context=None, # type: Optional[Dict]
|
||||
timestamp=None, # type: Optional[datetime.datetime]
|
||||
uuid=None, # type: Optional[str]
|
||||
@@ -214,18 +214,25 @@ def alias(
|
||||
The same concept applies for when a user logs in.
|
||||
|
||||
An `alias` call requires
|
||||
- `previous distinct id` the unique ID of the user before
|
||||
- `distinct id` the current unique id
|
||||
- `distinct id` the current unique id of the user (normally the id in your database)
|
||||
- `alias distinct id` the alias id you want to attach to the user, such as the anonymous session id or another ID like their email
|
||||
|
||||
|
||||
For example:
|
||||
```python
|
||||
posthog.alias('anonymous session id', 'distinct id')
|
||||
posthog.alias('distinct id', 'anonymous session id')
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```python
|
||||
posthog.alias('distinct id', 'users-email@posthog.com')
|
||||
```
|
||||
"""
|
||||
_proxy(
|
||||
"alias",
|
||||
previous_id=previous_id,
|
||||
distinct_id=distinct_id,
|
||||
previous_id=previous_id,
|
||||
context=context,
|
||||
timestamp=timestamp,
|
||||
uuid=uuid,
|
||||
|
||||
+4
-4
@@ -241,7 +241,7 @@ class Client(object):
|
||||
|
||||
return self._enqueue(msg)
|
||||
|
||||
def alias(self, previous_id=None, distinct_id=None, context=None, timestamp=None, uuid=None):
|
||||
def alias(self, distinct_id=None, previous_id=None, context=None, timestamp=None, uuid=None):
|
||||
context = context or {}
|
||||
|
||||
require("previous_id", previous_id, ID_TYPES)
|
||||
@@ -249,13 +249,13 @@ class Client(object):
|
||||
|
||||
msg = {
|
||||
"properties": {
|
||||
"distinct_id": previous_id,
|
||||
"alias": distinct_id,
|
||||
"distinct_id": distinct_id,
|
||||
"alias": previous_id,
|
||||
},
|
||||
"timestamp": timestamp,
|
||||
"context": context,
|
||||
"event": "$create_alias",
|
||||
"distinct_id": previous_id,
|
||||
"distinct_id": distinct_id,
|
||||
}
|
||||
|
||||
return self._enqueue(msg)
|
||||
|
||||
@@ -447,3 +447,21 @@ class TestClient(unittest.TestCase):
|
||||
client.feature_flags = [{"key": "example", "is_simple_flag": False}]
|
||||
|
||||
self.assertFalse(client.feature_enabled("example", "distinct_id"))
|
||||
|
||||
def test_alias_doesnt_regress_positional_args(self):
|
||||
client = self.client
|
||||
success, msg = client.alias("distinct_id", "alias_id")
|
||||
client.flush()
|
||||
self.assertTrue(success)
|
||||
self.assertFalse(self.failed)
|
||||
self.assertEqual(msg["properties"]["distinct_id"], "distinct_id")
|
||||
self.assertEqual(msg["properties"]["alias"], "alias_id")
|
||||
|
||||
def test_alias_doesnt_regress_named_args(self):
|
||||
client = self.client
|
||||
success, msg = client.alias(distinct_id="distinct_id", previous_id="alias_id")
|
||||
client.flush()
|
||||
self.assertTrue(success)
|
||||
self.assertFalse(self.failed)
|
||||
self.assertEqual(msg["properties"]["distinct_id"], "distinct_id")
|
||||
self.assertEqual(msg["properties"]["alias"], "alias_id")
|
||||
|
||||
Reference in New Issue
Block a user