Integration between Django and Amplitude
Project description
Django Amplitude
Integration between Django and Amplitude.com to help send events via the Amplitude HTTP API (v2)
Quick start
Installation
pip install django-amplitude
Set a Amplitude API key in your Django settings:
# Settings > Projects > <Your project> > General > API Key
AMPLITUDE_API_KEY = '<amplitude-project-api-key>'
# You can also choose if you want to include user and group data
# IF not set will default to False
AMPLITUDE_INCLUDE_USER_DATA = True
AMPLITUDE_INCLUDE_GROUP_DATA = True
Add amplitude
to your INSTALLED_APPS
:
INSTALLED_APPS =(
...
"amplitude",
...
)
Usage
If you want to send an event to Amplitude on every page view you can use the django-amplitude SendPageViewEvent
middleware to your MIDDLEWARE
in your Django settings.
This will automatically create an event base on the url name that was hit and the Django request object.
MIDDLEWARE = [
...
'amplitude.middleware.SendPageViewEvent',
...
]
If you want to send your own events:
from amplitude import Amplitude
amplitude = Amplitude()
amplitude.send_events([event_data]) # https://developers.amplitude.com/docs/http-api-v2
There are also few helper functions to build different parts of the event data:
amplitude.session_id_from_request(request)
amplitude.event_properties_from_request(request)
amplitude.device_data_from_request(request)
amplitude.user_properties_from_request(request)
amplitude.group_from_request(request)
amplitude.location_data_from_ip_address(ip_address)
user_properties_from_request
will return an empty dict isAMPLITUDE_INCLUDE_USER_DATA
isFalse
group_from_request
will return an empty dict isAMPLITUDE_INCLUDE_GROUP_DATA
isFalse
SendPageViewEvent - missing event data keys
The SendPageViewEvent
middleware currently does not record the following keys from UploadRequestBody
:
- event_id
- app_version
- device_id
- carrier
- price
- quantity
- revenue
- productId
- revenueType
- idfa
- idfv
- adid
- android_id
- dma
- insert_id
If you want to record an event in Amplitude with any of these keys you must use amplitude.send_events([event_data])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_amplitude-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c5433f8b50b474db8df94dd0359c9c3861ec6d0715ae4e1b648751b416a206e |
|
MD5 | 496ce734f101fcaadfd8ad0e9b4dd6d2 |
|
BLAKE2b-256 | 7394dfde49feef270f0b51500fff5bf6bc887e829d861d5d447c3caf38f1f9e5 |