Skip to content

Commit 480b39c

Browse files
Merge pull request #1 from interakt/develop
Taking changes for v1
2 parents 9ec00d7 + 43c4a06 commit 480b39c

File tree

3 files changed

+59
-23
lines changed

3 files changed

+59
-23
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
release:
2+
python3 setup.py clean
23
python3 setup.py sdist bdist_wheel
3-
twine upload dist/*
4+
twine upload --skip-existing dist/*
45

56
install:
67
python3 setup.py sdist bdist_wheel

README.md

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
# Interakt Track Python
2+
SDK : [interakt-track-python](https://pypi.org/project/interakt-track-python/)
23

34
# Getting Started
45

56
Install `interakt-track-python` using pip
67

78
pip install interakt-track-python
89

10+
## Authentication
911
Inside your app, you’ll want to **set your** `write_key` before making any track calls:
12+
```
13+
import track
14+
15+
track.write_key = "YOUR_WRITE_KEY"
16+
```
17+
Interakt Track APIs uses HTTP Basic Auth, which involves a `‘username:password’` that is **base64 encoded** and prepended with the string `‘Basic ‘`.
18+
19+
Your **write_key** is your `username` and `password` is empty. Which means if your **write_key** is `'abcd123'`, a colon is added to it, and then the password field is left empty.
20+
21+
After base64 encoding `'abcd123:'` becomes `'YWJjZDEyMzo='`; and this is passed in the authorization header like so: `'Authorization: Basic YWJjZDEyMzo='`
1022

11-
import track
12-
13-
track.write_key = "YOUR_WRITE_KEY"
1423

1524

1625
## Development Settings
@@ -19,23 +28,28 @@ The default initialization settings are production-ready and queue messages to b
1928

2029
In development you might want to enable some settings to make it easier to spot problems. Enabling `track.debug` will log debugging info to the Python logger. You can also add an `on_error` handler to specifically print out the response you’re seeing from our API.
2130
```
22-
def on_error(error, data):
23-
print("An error occurred:", error)
24-
31+
def on_error(error, queue_msg):
32+
print("An error occurred", error)
33+
print("Queue message", queue_msg)
2534
2635
track.debug = True
2736
track.on_error = on_error
28-
2937
```
30-
31-
# Identify
38+
### All Settings:
39+
|Settings name|Type|Default value|Description|
40+
|--|--|--|--|
41+
|sync_mode|bool|False|When `True`, calls the track API **synchronously**. When `False`, calls the track APIs **asynchronously** using a Queue.|
42+
|debug|bool|False|To turn on debug logging|
43+
|timeout|int|10|Timout for track API calls|
44+
|max_retries|int|3|Number of API retries in case API call fails due to some error|
45+
|max_queue_size|int|10000|Max Queue size|
46+
|on_error|function|None|Callback function which is called whenever an error occurs in **asynchronous** mode
47+
48+
49+
# APIs
50+
## Identify
3251
The `identify` lets you tie a user to their actions and record traits about them. It includes a unique **User ID** or **Phone Number and Country Code** any optional traits you know about them.
3352

34-
Either of the two for user identification is required:
35-
36-
- **user_id**
37-
- **phone_number** with **country_code**
38-
3953
Example `identify` call:
4054
```
4155
track.identify(
@@ -47,15 +61,36 @@ track.identify(
4761
}
4862
)
4963
```
64+
The `identify` call has the following fields:
65+
|Field|Data type|Description|
66+
|--|--|--|
67+
|user_id|str or int|The ID for the user in your database.|
68+
|country_code|str|country code for the phone_number (default value is "+91")|
69+
|phone_number|str|phone_number without country_code (eg: "9876598765")|
70+
|traits|dict|A dict of traits you know about the user. Things like: `email`, `name` or `age`|
71+
72+
**NOTE:** Atleast one of these two is required for user identification :
73+
74+
- **user_id**, OR
75+
- **phone_number** with **country_code**
5076

51-
# Event
52-
`event` lets you record the actions your users perform. Every action triggers what we call an “event”, which can also have associated properties.
77+
78+
79+
80+
## Event
81+
`event` track API lets you record the actions your users perform. Every action triggers what we call an “event”, which can also have associated properties.
5382

5483
Example `event` call:
5584
```
5685
track.event(
57-
user_id="<USER_ID>",
58-
event="Add to Cart",
59-
traits={"amount": 200}
86+
user_id="changu_mangu",
87+
event="Product Added",
88+
traits={"price": 200}
6089
)
6190
```
91+
The `event` call has the following fields:
92+
|Field|Data type|Description|
93+
|--|--|--|
94+
|user_id|str or int|The ID for the user in your database.|
95+
|event|str|Name of the event you want to track, For eg: "Product Added".|
96+
|traits|dict|dictionary of properties for the event. If the event was **Product Added**, it might have properties like `price` or `product_name`.|

track/request.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
def post(write_key, host=None, path=None, body=None, timeout=10):
1515
"""Post the msg to the API"""
16+
auth = HTTPBasicAuth(username=write_key, password="")
1617
headers = {
1718
'Content-Type': 'application/json',
18-
'User-Agent': f'interakt-track-python/{VERSION}',
19-
'Authorization': write_key
19+
'User-Agent': f'interakt-track-python/{VERSION}'
2020
}
2121
url = remove_trailing_slash(host or DEFAULT_HOST) + path
2222
logger.debug(f'Making request: {body}')
2323
response = _session.post(url=url, headers=headers,
24-
json=body, timeout=timeout)
24+
auth=auth, json=body, timeout=timeout)
2525
if response.status_code == 200:
2626
logger.debug("Data uploaded successfully")
2727
return response

0 commit comments

Comments
 (0)