This is a server application built with aiohttp that tracks and displays visitor statistics for websites by embedding a 1x1 tracking pixel. The server records client IP addresses, browser types, and preferred languages, and provides an HTML-based dashboard to view and filter these statistics.
- Tracking Pixel: Embeds a tracking pixel (
pixel.png) in target websites to gather visit data. - Visitor Statistics: Records visitor information such as IP, browser type, and language.
- Date Range Filtering: Allows filtering of visitor statistics by start and end dates.
- Most Common Stats: Displays the most common language, browser, and client for all time or within a specified period.
- Client Persistence: Stores visitor data in
visitor_data.jsonlin JSON lines format for easy appending and reading.
-
Clone this repository:
git clone https://github.com/yourusername/visitor-statistics-server.git
-
Navigate to the project directory:
cd visitor-statistics-server -
Install the required dependencies:
pip install -r requirements.txt
-
Run the server:
python app.py
-
Access the server:
- Open your browser and go to http://localhost:8000 to view the visitor statistics dashboard.
- Embed the tracking pixel on external sites using the URL:
http://localhost:8000/pixel.png.
-
Tracking Pixel Integration: Add the following HTML to any page where you want to track visitors:
<img src="http://localhost:8000/pixel.png?host=example.com" alt="tracking pixel" style="display:none;">
- / - Home page with basic server information.
- /pixel.png - Tracking pixel endpoint; records client visits.
- /stats - Statistics page; displays visitor statistics with filtering options.
- /static/ - Static files served by the server.
- Templates: HTML templates for the server are located in the
templatesfolder. - Static Files: Static assets (e.g., CSS, JS) are stored in the
staticdirectory.
app.py: Main server application file.client.py: Defines theClientclass, used to structure client data.visitor_data.jsonl: JSON lines file where visitor data is stored.
track_pixel: Saves visitor information on accessing the tracking pixel.get_visitor_data: Reads and aggregates visitor data fromvisitor_data.jsonl.get_stats: Generates an HTML response showing visitor statistics.get_browserandget_language: Extracts browser and language information from client headers.
This application includes tests for verifying correct server functionality. To run the tests, use:
pytest