A reusable Django app for tracking user activity on web application. This app logs user actions like url, referer, method, ip, user_agent and timestamp. It’s designed to be reusable, easy to integrate, and can be customized to fit your needs.
- Tracks user activity (e.g., URL visited, HTTP method, referer, ip, user_agent and timestamp).
- Logs activity for authenticated users.
- Easily integrates into any Django project.
- Admin interface for easy viewing and management of activity data.
- Reusable and customizable.
- Python 3.x
- Django 4.0 or later (recommended)
- A PostgreSQL, MySQL, SQLite or any relational database for data storage
You can install the django-user-activity
app in your Django project using one of the following methods.
-
Install the app via
pip
:pip install django-user-activity
-
Install the app via
git
:pip install git+https://github.com/rkpust/django-user-activity
-
Clone the repository or download the package.
-
Navigate to the project directory and install the app locally.
pip install -e /path/to/django-user-activity pip install django-user-activity-0.0.1.tar.gz
Add activity
to your INSTALLED_APPS in your settings.py file:
INSTALLED_APPS = [
...
'activity',
...
]
Add ActivityMiddleware
to your MIDDLEWARE in your settings.py file:
MIDDLEWARE = [
...
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'activity.middleware.ActivityMiddleware',
...
]
Run migrations to set up the necessary database tables:
python manage.py makemigrations
python manage.py migrate
Or, you can run these commands for further clarification.
python manage.py makemigrations activity
python manage.py migrate activity 0001
The Activity
model contains the following fields:
user
: The user who performed the action.
url
: The URL visited by the user.
referer
: The referer tells you which page the user is coming from. If its value is None
, it means the user hits the url directly in the browser.
method
: The HTTP method (e.g., GET, POST).
ip
: The ip of user's device.
user_agent
: The user_agent tells you the information of users browser, os etc information.
timestamp
: The timestamp when the action occurred.
You can view, filter, and search user activity data in the Django Admin Interface by visiting /admin
path. Here, you will see Activities
option in the left side. You will
- see those field as list.
user
,url
,referer
,method
,ip
,user_agent
,timestamp
- filter those field.
method
,timestamp
- search those field by value.
username
,url
,referer
,method
,ip
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! If you'd like to improve, fix bugs or add new features to the reusable django-user-activity
app, feel free to create an issue or submit a pull request on GitHub. Ensure the code adheres to the project’s style.
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Write your code and tests.
- Run the tests to ensure everything is working. (
python manage.py test activity
) - Submit a pull request describing your changes.