Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b923116a9e | ||
|
|
1670901156 | ||
|
|
ab65f8f0f8 | ||
|
|
133e1a991c | ||
|
|
34e92615c2 | ||
|
|
cf09644d4f | ||
|
|
0cfce57d0e | ||
|
|
e9862cf671 | ||
|
|
7a93a99541 |
@@ -1,5 +1,7 @@
|
||||
Copyright (c) 2020 PostHog (part of Hiberly Inc)
|
||||
|
||||
Copyright (c) 2013 Segment Inc. friends@segment.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
|
||||
@@ -53,7 +53,7 @@ An `identify` call requires
|
||||
|
||||
For example:
|
||||
```python
|
||||
posthog.capture('distinct id', {
|
||||
posthog.identify('distinct id', {
|
||||
'email': 'dwayne@gmail.com',
|
||||
'name': 'Dwayne Johnson'
|
||||
})
|
||||
@@ -69,6 +69,8 @@ In a purely back-end implementation, this means whenever an anonymous user does
|
||||
|
||||
The same concept applies for when a user logs in.
|
||||
|
||||
If you're using PostHog in the front-end and back-end, doing the `identify` call in the frontend will be enough.
|
||||
|
||||
An `alias` call requires
|
||||
- `previous distinct id` the unique ID of the user before
|
||||
- `distinct id` the current unique id
|
||||
@@ -115,4 +117,4 @@ As our open source project [PostHog](https://github.com/PostHog/posthog) shares
|
||||
|
||||
## Thank you
|
||||
|
||||
This library is largely based on the `analytics-python` package.
|
||||
This library is largely based on the `analytics-python` package.
|
||||
|
||||
+34
-11
@@ -6,18 +6,26 @@ from typing import Optional, Dict, Callable
|
||||
__version__ = VERSION
|
||||
|
||||
"""Settings."""
|
||||
api_key: str = None
|
||||
host: str = None
|
||||
on_error: Callable = None
|
||||
debug: bool = False
|
||||
send: bool = True
|
||||
sync_mode:bool = False
|
||||
api_key = None # type: str
|
||||
host = None # type: str
|
||||
on_error = None # type: Callable
|
||||
debug = False # type: bool
|
||||
send = True # type: bool
|
||||
sync_mode = False # type: bool
|
||||
disabled = False # type: bool
|
||||
|
||||
default_client = None
|
||||
|
||||
|
||||
def capture(distinct_id: str, event: str, properties: Optional[Dict]=None, context: Optional[Dict]=None,
|
||||
timestamp: Optional[str]=None, message_id: Optional[str]=None) -> None:
|
||||
def capture(
|
||||
distinct_id, # type: str,
|
||||
event, # type: str,
|
||||
properties=None, # type: Optional[Dict]
|
||||
context=None, # type: Optional[Dict]
|
||||
timestamp=None, # type: Optional[str]
|
||||
message_id=None, # type: Optional[str]
|
||||
):
|
||||
# type: (...) -> None
|
||||
"""
|
||||
Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up.
|
||||
|
||||
@@ -36,8 +44,14 @@ def capture(distinct_id: str, event: str, properties: Optional[Dict]=None, conte
|
||||
"""
|
||||
_proxy('capture', distinct_id=distinct_id, event=event, properties=properties, context=context, timestamp=timestamp, message_id=message_id)
|
||||
|
||||
def identify(distinct_id: str, properties: Optional[Dict]=None, context: Optional[Dict]=None, timestamp: Optional[str]=None,
|
||||
message_id=None) -> None:
|
||||
def identify(
|
||||
distinct_id, # type: str,
|
||||
properties=None, # type: Optional[Dict]
|
||||
context=None, # type: Optional[Dict]
|
||||
timestamp=None, # type: Optional[str]
|
||||
message_id=None, # type: Optional[str]
|
||||
):
|
||||
# type: (...) -> None
|
||||
"""
|
||||
Identify lets you add metadata on your users so you can more easily identify who they are in PostHog, and even do things like segment users by these properties.
|
||||
|
||||
@@ -60,7 +74,14 @@ def group(*args, **kwargs):
|
||||
_proxy('group', *args, **kwargs)
|
||||
|
||||
|
||||
def alias(previous_id: str, distinct_id: str, context: Optional[Dict]=None, timestamp: Optional[str]=None, message_id: Optional[str]=None) -> None:
|
||||
def alias(
|
||||
previous_id, # type: str,
|
||||
distinct_id, # type: str,
|
||||
context=None, # type: Optional[Dict]
|
||||
timestamp=None, # type: Optional[str]
|
||||
message_id=None, # type: Optional[str]
|
||||
):
|
||||
# type: (...) -> None
|
||||
"""
|
||||
To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like "Which marketing channels leads to users churning after a month?" or "What do users do on our website before signing up?"
|
||||
|
||||
@@ -109,6 +130,8 @@ def shutdown():
|
||||
def _proxy(method, *args, **kwargs):
|
||||
"""Create an analytics client if one doesn't exist and send to it."""
|
||||
global default_client
|
||||
if disabled:
|
||||
return None
|
||||
if not default_client:
|
||||
default_client = Client(api_key, host=host, debug=debug,
|
||||
on_error=on_error, send=send,
|
||||
|
||||
@@ -218,6 +218,8 @@ class Client(object):
|
||||
timestamp = guess_timezone(timestamp)
|
||||
msg['timestamp'] = timestamp.isoformat()
|
||||
msg['messageId'] = stringify_id(message_id)
|
||||
if not msg.get('properties'):
|
||||
msg['properties'] = {}
|
||||
msg['properties']['$lib'] = 'posthog-python'
|
||||
msg['properties']['$lib_version'] = VERSION
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
VERSION = '1.0.7'
|
||||
VERSION = '1.0.10'
|
||||
|
||||
Reference in New Issue
Block a user