Skip to content

Commit 33ccc37

Browse files
committed
fix alias
1 parent ae8817b commit 33ccc37

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141

4242
print(posthog.feature_enabled("beta-feature", "distinct_id"))
4343

44-
# # Alias a previous distinct id with a new one
44+
# Add an alias_id to a distinct_id
4545

46-
posthog.alias("distinct_id", "new_distinct_id")
46+
posthog.alias("distinct_id", "alias_id")
4747

4848
posthog.capture("new_distinct_id", "event2", {"property1": "value", "property2": "value"})
4949
posthog.capture(

posthog/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ def group_identify(
199199

200200

201201
def alias(
202-
previous_id, # type: str,
203-
distinct_id, # type: str,
202+
distinct_id, # type: str
203+
previous_id, # type: str
204204
context=None, # type: Optional[Dict]
205205
timestamp=None, # type: Optional[datetime.datetime]
206206
uuid=None, # type: Optional[str]
@@ -214,18 +214,25 @@ def alias(
214214
The same concept applies for when a user logs in.
215215
216216
An `alias` call requires
217-
- `previous distinct id` the unique ID of the user before
218-
- `distinct id` the current unique id
217+
- `distinct id` the current unique id of the user (normally the id in your database)
218+
- `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
219+
219220
220221
For example:
221222
```python
222-
posthog.alias('anonymous session id', 'distinct id')
223+
posthog.alias('distinct id', 'anonymous session id')
224+
```
225+
226+
or
227+
228+
```python
229+
posthog.alias('distinct id', 'users-email@posthog.com')
223230
```
224231
"""
225232
_proxy(
226233
"alias",
227-
previous_id=previous_id,
228234
distinct_id=distinct_id,
235+
previous_id=previous_id,
229236
context=context,
230237
timestamp=timestamp,
231238
uuid=uuid,

posthog/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,21 +241,21 @@ def group_identify(self, group_type=None, group_key=None, properties=None, conte
241241

242242
return self._enqueue(msg)
243243

244-
def alias(self, previous_id=None, distinct_id=None, context=None, timestamp=None, uuid=None):
244+
def alias(self, distinct_id=None, previous_id=None, context=None, timestamp=None, uuid=None):
245245
context = context or {}
246246

247247
require("previous_id", previous_id, ID_TYPES)
248248
require("distinct_id", distinct_id, ID_TYPES)
249249

250250
msg = {
251251
"properties": {
252-
"distinct_id": previous_id,
253-
"alias": distinct_id,
252+
"distinct_id": distinct_id,
253+
"alias": previous_id,
254254
},
255255
"timestamp": timestamp,
256256
"context": context,
257257
"event": "$create_alias",
258-
"distinct_id": previous_id,
258+
"distinct_id": distinct_id,
259259
}
260260

261261
return self._enqueue(msg)

0 commit comments

Comments
 (0)