Skip to content

Commit

Permalink
fix alias
Browse files Browse the repository at this point in the history
  • Loading branch information
lharries committed Jan 24, 2023
1 parent ae8817b commit 33ccc37
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

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(
Expand Down
19 changes: 13 additions & 6 deletions posthog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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', '[email protected]')
```
"""
_proxy(
"alias",
previous_id=previous_id,
distinct_id=distinct_id,
previous_id=previous_id,
context=context,
timestamp=timestamp,
uuid=uuid,
Expand Down
8 changes: 4 additions & 4 deletions posthog/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,21 @@ def group_identify(self, group_type=None, group_key=None, properties=None, conte

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)
require("distinct_id", distinct_id, ID_TYPES)

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)
Expand Down

0 comments on commit 33ccc37

Please sign in to comment.