Skip to content

PurpleCat404/Meeting_counter

Repository files navigation

Visitor Statistics Server

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.

Features

  • 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.jsonl in JSON lines format for easy appending and reading.

Installation

  1. Clone this repository:

    git clone https://github.com/yourusername/visitor-statistics-server.git
  2. Navigate to the project directory:

    cd visitor-statistics-server
  3. Install the required dependencies:

    pip install -r requirements.txt

Usage

  1. Run the server:

    python app.py
  2. 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.
  3. 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;">

API Endpoints

  • / - 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.

Configuration

  • Templates: HTML templates for the server are located in the templates folder.
  • Static Files: Static assets (e.g., CSS, JS) are stored in the static directory.

Code Overview

Main Modules

  • app.py: Main server application file.
  • client.py: Defines the Client class, used to structure client data.
  • visitor_data.jsonl: JSON lines file where visitor data is stored.

Key Functions

  • track_pixel: Saves visitor information on accessing the tracking pixel.
  • get_visitor_data: Reads and aggregates visitor data from visitor_data.jsonl.
  • get_stats: Generates an HTML response showing visitor statistics.
  • get_browser and get_language: Extracts browser and language information from client headers.

Testing

This application includes tests for verifying correct server functionality. To run the tests, use:

pytest

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published