Created
August 9, 2021 15:00
-
-
Save ohld/668c1ab290e0a19d12c5d80c17d810be to your computer and use it in GitHub Desktop.
How to send Amplitude events with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
AMPLITUDE_API_KEY = "your-secret-amplitude-key" | |
AMPLITUDE_ENDPOINT = "https://api.amplitude.com/2/httpapi" | |
amp_event = { | |
"user_id": 123123123, # unique user identifier | |
"event_type": event_name, # the name of event | |
"platform": 'Telegram', # useless if you have only Telegram users | |
"user_properties": { | |
# set any user-related info you want to tract and filter in Amplitude web UI | |
}, | |
"event_properties": { | |
# set any additional information about this action | |
}, | |
} | |
# somehow we need to have json.dumps to make it works | |
_ = requests.post(AMPLITUDE_ENDPOINT, data=json.dumps({ | |
'api_key': AMPLITUDE_API_KEY, | |
'events': [amp_event], | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment