Skip to content

BrickMMO/stats-v1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BrickMMO Stats Application

A comprehensive web analytics application built with PHP and W3.CSS for tracking page views, user behavior, and website statistics.

Features

  • Page view tracking with browser and OS detection
  • Admin panel with asset management and statistics
  • Real-time analytics dashboard with filtering
  • CSV export functionality
  • User management with role-based access
  • Responsive design with W3.CSS framework

Installation

Requirements

  • PHP 7.4+
  • MySQL 5.7+
  • Web server (Apache/Nginx)

Setup

  1. Create MySQL database brickmmo_stats
  2. Import setup.sql
  3. Configure database in includes/config.php
  4. Access via web browser

Default Login

  • Username: admin
  • Password: password

Usage

Asset Creation

  1. Login to admin panel
  2. Create new asset
  3. Copy tracking code snippet
  4. Add to your website

Tracking Code

<script src="tracker.js" data-asset-id="1"></script>

File Structure

admin/              # Admin panel
includes/           # Core PHP files  
demo/              # Demo website 1
demo2/             # Demo website 2
tracker.js         # Tracking script
track.php          # Tracking endpoint
setup.sql          # Database setup

Database Schema

  • assets - Website tracking configurations
  • stats - Page view tracking data
  • users - Admin user accounts

API

POST /track.php

{
  "asset_id": 1,
  "url": "https://example.com",
  "browser": "Chrome",
  "os": "Windows 10",
  "referrer": "https://google.com"
}

Developer

Tarun Shokeen - HTTP 5310 Capstone Project DB_HOST=localhost DB_USERNAME=root DB_PASSWORD=your_password DB_DATABASE=brickmmo_stats


4. **Access the Application**
- Open `http://localhost/BrickMMO_stats-v1/` in your browser
- Login to admin panel: `http://localhost/BrickMMO_stats-v1/admin/`
- Default credentials: `admin` / `password` (change immediately!)

## πŸ“Š Usage

### Creating a New Asset

1. Login to the admin panel
2. Navigate to "Assets" β†’ "New Asset"
3. Enter asset name and description
4. Copy the generated tracking code
5. Paste into your website's HTML

### Tracking Code Integration

#### Method 1: Basic Script Tag
```html
<script src="/BrickMMO_stats-v1/tracker.js" data-asset-id="1"></script>

Method 2: Global Variable

<script>window.BRICKMMO_ASSET_ID = 1;</script>
<script src="/BrickMMO_stats-v1/tracker.js"></script>

Method 3: CDN Integration

<script src="https://cdn.brickmmo.com/stats/tracker.js" data-asset-id="1"></script>

Viewing Statistics

  1. Access the admin panel
  2. Navigate to "Stats" to view all analytics
  3. Filter by specific assets using the dropdown
  4. View detailed breakdowns by browser, OS, and referrers
  5. Export data for further analysis

πŸ”§ Technical Details

File Structure

BrickMMO_stats-v1/
β”œβ”€β”€ admin/                  # Admin panel files
β”‚   β”œβ”€β”€ index.php          # Dashboard
β”‚   β”œβ”€β”€ login.php          # Authentication
β”‚   β”œβ”€β”€ assets.php         # Asset management
β”‚   β”œβ”€β”€ stats.php          # Statistics viewer
β”‚   β”œβ”€β”€ users.php          # User management
β”‚   └── auth.php           # Authentication functions
β”œβ”€β”€ includes/              # Core PHP files
β”‚   β”œβ”€β”€ config.php         # Configuration
β”‚   β”œβ”€β”€ connect.php        # Database connection
β”‚   β”œβ”€β”€ functions.php      # Utility functions
β”‚   β”œβ”€β”€ header.php         # HTML header
β”‚   └── footer.php         # HTML footer
β”œβ”€β”€ tracker.js             # JavaScript tracking script
β”œβ”€β”€ track.php              # Tracking endpoint
β”œβ”€β”€ index.php              # Main landing page
β”œβ”€β”€ setup.sql              # Database setup script
β”œβ”€β”€ .env                   # Environment variables
└── README.md              # This file

Database Schema

Assets Table

  • id: Unique asset identifier
  • name: Asset display name
  • description: Optional description
  • snippet: Generated tracking code
  • created_at: Creation timestamp

Stats Table

  • id: Unique tracking record ID
  • asset_id: References assets table
  • url: Tracked page URL
  • ip_address: Visitor IP address
  • browser: Detected browser
  • os: Detected operating system
  • user_agent: Full user agent string
  • referrer: Referring URL
  • viewed_at: Tracking timestamp

Users Table

  • id: Unique user ID
  • username: Login username
  • password: Hashed password
  • role: User role (admin/user)
  • created_at: Account creation date

API Endpoints

POST /track.php

Receives tracking data from JavaScript and stores in database.

Request Body:

{
  "asset_id": 1,
  "url": "https://example.com/page",
  "browser": "Chrome",
  "os": "Windows 10",
  "referrer": "https://google.com",
  "screen_width": 1920,
  "screen_height": 1080,
  "viewport_width": 1200,
  "viewport_height": 800,
  "timezone": "America/New_York",
  "language": "en-US"
}

Response:

{
  "status": "success",
  "message": "Tracking data saved successfully",
  "insert_id": 123,
  "asset_id": 1
}

πŸ”’ Security Features

  • Password Hashing: All passwords stored with PHP password_hash()
  • SQL Injection Protection: Prepared statements throughout
  • CSRF Protection: Session-based authentication
  • Role-based Access: Admin/User permission levels
  • Input Sanitization: All user input properly escaped

🌐 CDN Integration

For production deployment:

  1. Upload tracker.js to your CDN
  2. Update tracking snippets to use CDN URL
  3. Configure CORS headers if needed
  4. Consider caching strategies for optimal performance

πŸ§ͺ Testing

Local Testing

  1. Create a test HTML file with tracking code
  2. Open in browser and verify data appears in admin panel
  3. Test different browsers and devices
  4. Verify statistics accuracy

Debug Mode

Enable debug mode by adding to tracking code:

<script>window.BRICKMMO_DEBUG = true;</script>

πŸ“ˆ Performance Considerations

  • Lightweight Tracking: Minimal JavaScript footprint
  • Asynchronous Loading: Non-blocking script execution
  • Database Indexing: Optimized queries for large datasets
  • Efficient Queries: Pagination and filtering for large data sets

🀝 Contributing

This project is part of the BrickMMO ecosystem. For contributions:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

πŸ“„ License

This project is part of BrickMMO and follows the same licensing terms.

πŸ‘¨β€πŸ’» Developer

Tarun Shokeen

  • Course: HTTP 5310 Capstone
  • Professor: Adam Thomas (codeadamca)
  • Institution: Humber College

πŸ”— Related Projects

πŸ“ž Support

For technical support or questions:

  • Create an issue in this repository
  • Contact the development team through BrickMMO channels
  • Refer to the BrickMMO documentation

Note: Remember to change default passwords and review security settings before deploying to production!

About

Stats

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •