Claude AI developed a cookie-based qr code tracker.
Site-Wide Tracking System – Installation Guide
📦 What You Have
Three PHP files for comprehensive visitor tracking:
- track.php – Site-wide visitor tracking (include on every page)
- qr.php – QR code redirect with enhanced tracking
- qr-admin.php – Analytics dashboard with 5 views
🚀 Installation Steps
Step 1: Upload Files
Upload all three PHP files to your scootercam.net web root:
/public_html/track.php
/public_html/qr.php
/public_html/qr-admin.php
Step 2: Set Directory Permissions
Make sure the directory is writable so SQLite can create the database:
chmod 755 /public_html/
Step 3: Add Tracking to Every Page
Add this line at the very top of every PHP page you want to track:
<?php require_once 'track.php'; ?>
<!DOCTYPE html>
<html>
...
For non-PHP pages (HTML), you have two options:
Option A: Rename .html
files to .php
and add the tracking line
Option B: Use .htaccess
to parse HTML as PHP:
AddType application/x-httpd-php .html
Then add <?php require_once 'track.php'; ?>
to your HTML files.
Step 4: Change Admin Password
Edit qr-admin.php line 12:
define('ADMIN_PASSWORD', 'your_secure_password_here');
Change your_secure_password_here
to something secure.
Step 5: Test the System
- Visit any page on your site → sets visitor cookie
- Visit qr-admin.php → login with your password
- Check “Overview” tab → should show 1 visitor, 1 page view
Step 6: Create Your First QR Code
Generate a QR code pointing to:
https://scootercam.net/qr.php?code=TEST&dest=https://scootercam.net/
Scan it with your phone and watch it appear in the admin!
📊 What Gets Tracked
Site-Wide Tracking (track.php)
- ✅ Every page visit
- ✅ Visitor cookie (1-year persistence)
- ✅ First visit timestamp
- ✅ Last visit timestamp
- ✅ Total page views per visitor
- ✅ Referrer information
- ✅ User agent (device/browser)
- ✅ IP address
QR Code Tracking (qr.php)
- ✅ Which QR code was scanned
- ✅ When it was scanned
- ✅ Whether visitor is new or returning
- ✅ Destination URL
- ✅ Links visitor to their site browsing history
Combined Intelligence
The system now knows:
- Did someone browse your site BEFORE scanning a QR?
- Did someone scan a QR THEN browse your site?
- How many visitors came from QR vs organic traffic?
- Full visitor journey from first touch to last activity
📱 Admin Dashboard Views
1. Overview – High-level stats
- Total visitors
- Page views
- QR scans
- Conversion rates
- Visitor source breakdown (QR only / Site only / Both)
2. Visitor Journeys – Track individual visitors
- Entry point (QR code or page URL)
- First and last seen timestamps
- Total page views
- Total QR scans
- Visitor type badge
3. QR Codes – QR performance metrics
- Total scans per code
- Unique visitors per code
- Returning scan counts
- Last scan timestamp
4. Page Views – Popular pages
- Most viewed pages
- Unique visitors per page
- Average views per visitor
5. Recent Activity – Real-time feed
- Last 50 actions (QR scans + page views)
- Timestamp
- Visitor ID
- Device info
🔧 Configuration Options
In track.php (line 9):
define('TRACK_PAGEVIEWS', true);
true
= Log every page view (recommended for low traffic)false
= Only set cookie, don’t log pages (lighter database)
In qr.php (line 11):
define('ALLOWED_DOMAINS', ['scootercam.net', 'www.scootercam.net']);
Add any additional domains you want to allow as QR destinations.
🗄️ Database Structure
The system creates three tables automatically:
visitors – One row per unique visitor
- Aggregated stats (total pageviews, total QR scans)
- First and last seen timestamps
- First QR scan timestamp
page_views – One row per page view
- Full page URL
- Timestamp
- Referrer
- Device info
qr_scans – One row per QR scan
- QR code identifier
- Destination URL
- New vs returning status
- Timestamp
🔒 Security Features
- ✅ SQLite prepared statements (injection-proof)
- ✅ Password-protected admin panel
- ✅ HTTP-only, secure cookies
- ✅ Domain whitelist for QR redirects
- ✅ Admin/tracking scripts excluded from logs
- ✅ Silent failure (tracking errors don’t break pages)
🎯 Usage Example
Scenario: Event poster with QR code
- Print poster with QR code pointing to:
https://scootercam.net/qr.php?code=POSTER_DOWNTOWN&dest=https://scootercam.net/events
- Someone scans it with their phone
- System logs: “New visitor scanned POSTER_DOWNTOWN at 2pm”
- They browse to
/gallery
and/contact
- System logs: “Same visitor viewed 2 more pages”
- Three days later, they scan ANOTHER QR code
- System logs: “Returning visitor scanned STICKER_CITY at 5pm”
In admin, you see:
- This visitor’s complete journey
- Both QR codes they scanned
- All pages they viewed
- Total engagement time span
📞 Troubleshooting
Database not creating?
- Check directory write permissions
- Look for PHP errors:
tail -f /var/log/apache2/error.log
Page views not showing?
- Make sure
track.php
is included BEFORE any HTML output - Check that
TRACK_PAGEVIEWS
istrue
QR scans work but page views don’t?
- Verify
track.php
is included on those pages - Check that pages are parsed as PHP (not static HTML)
Admin shows 0 visitors?
- Try a longer time range (90 days)
- Check that database file exists:
ls -la qr_tracking.db
🚀 Next Steps
- Add tracking to all your pages
- Create QR codes for different campaigns
- Monitor visitor behavior patterns
- Identify which QR codes drive the most engagement
- See which pages visitors love (or leave quickly)
Remember: Change the admin password before going live!