A comprehensive, password-protected QR code generator with click tracking and analytics, built with Streamlit and AWS.
- Rounded edges for a modern, soft look (scan-compatible)
- Custom logo overlay in the center of QR codes
- Customizable colors for QR code and background
- Adjustable size and error correction levels
- High-resolution export (PNG format)
- Real-time click tracking via AWS Lambda
- Visitor information capture:
- IP address (hashed for privacy)
- Geographic location (country, region, city)
- Device type (mobile, tablet, desktop)
- Browser and OS information
- Referrer URL
- UTM parameters (source, medium, campaign, etc.)
- Analytics dashboard with charts and metrics
- Historical data with customizable date ranges
- Password protection via Streamlit secrets
- IAM-based access control for AWS resources
- IP address hashing for visitor privacy
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β User scans ββββββΆβ API Gateway ββββββΆβ Lambda β
β QR Code β β (HTTP API) β β (Redirect) β
βββββββββββββββββββ βββββββββββββββββββ ββββββββββ¬βββββββββ
β
ββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β DynamoDB β β DynamoDB β β Target URL β
β (QR Codes) β β (Clicks) β β (Redirect) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β² β²
β β
ββββββββββββββββββ¬ββββββββββββββββ
β
βββββββββββββββββββ
β Streamlit β
β App β
βββββββββββββββββββ
- Python 3.9+
- AWS Account with CLI configured
- AWS CLI v2
- jq (for JSON parsing in shell scripts)
# Navigate to the project directory
cd qr-tracker# Make scripts executable
chmod +x aws/*.sh
# Run the setup script
cd aws
./setup_aws.shThe script will:
- Create DynamoDB tables for QR codes and clicks
- Create a Lambda function for redirect handling
- Set up API Gateway with HTTP endpoint
- Create IAM roles and policies
- Generate access credentials for the Streamlit app
Save the output! It contains the configuration values you'll need.
# Create secrets directory
mkdir -p .streamlit
# Copy and edit the example secrets file
cp .streamlit/secrets.toml.example .streamlit/secrets.toml
# Edit with your values from the setup script output
nano .streamlit/secrets.toml# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtstreamlit run app.pyThe app will be available at http://localhost:8501
qr-tracker/
βββ app.py # Main Streamlit application
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ .streamlit/
β βββ secrets.toml.example # Example secrets file
β βββ secrets.toml # Your secrets (git-ignored)
βββ aws/
βββ lambda_function.py # Lambda function code
βββ setup_aws.sh # AWS infrastructure setup
βββ teardown_aws.sh # AWS infrastructure cleanup
βββ update_lambda.sh # Update Lambda function code
| Key | Description | Example |
|---|---|---|
app_password |
Password to access the app | "my-secure-password" |
aws_region |
AWS region | "us-east-1" |
aws_access_key_id |
AWS access key | "AKIA..." |
aws_secret_access_key |
AWS secret key | "..." |
dynamodb_qr_table |
QR codes table name | "qr-tracker-qr-codes" |
dynamodb_clicks_table |
Clicks table name | "qr-tracker-clicks" |
redirect_base_url |
API Gateway URL | "https://xxx.execute-api..." |
You can also configure the AWS setup scripts with environment variables:
export AWS_REGION="us-west-2"
export PROJECT_NAME="my-qr-tracker"
./setup_aws.shThe following data is captured for each QR code scan:
| Field | Description |
|---|---|
timestamp |
When the scan occurred |
ip_hash |
Hashed IP for unique visitor counting |
country |
Visitor's country |
region |
Visitor's region/state |
city |
Visitor's city |
device_type |
mobile, tablet, or desktop |
browser |
Chrome, Safari, Firefox, etc. |
os |
Operating system |
referrer |
Where the visitor came from |
utm_* |
UTM campaign parameters |
After modifying aws/lambda_function.py:
cd aws
./update_lambda.shaws logs tail /aws/lambda/qr-tracker-redirect --followcd aws
./teardown_aws.sh- Push code to GitHub
- Connect to Streamlit Cloud
- Add secrets in the Streamlit Cloud dashboard
- Deploy!
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY app.py .
COPY .streamlit .streamlit
EXPOSE 8501
CMD ["streamlit", "run", "app.py", "--server.port=8501"]See the Streamlit deployment documentation for detailed instructions.
- Never commit secrets: The
.streamlit/secrets.tomlfile should be in.gitignore - Use strong passwords: Generate secure passwords for app access
- Rotate credentials: Periodically rotate AWS access keys
- Limit IAM permissions: The setup script creates minimal required permissions
- IP hashing: Visitor IPs are hashed before storage for privacy
- HTTPS only: API Gateway uses HTTPS by default
- Ensure
.streamlit/secrets.tomlexists and has correct values - Verify AWS credentials are valid:
aws sts get-caller-identity
- Check API Gateway is deployed: Look for
/prod/rendpoint - Verify Lambda permissions in AWS Console
- Check CloudWatch logs for Lambda errors
- Ensure tables exist:
aws dynamodb list-tables - Verify IAM permissions include DynamoDB access
- Use PNG format with transparent background
- Keep logo size under 25% of QR code
- Use "H" (High) error correction for best results
MIT License - feel free to use for personal or commercial projects.
Contributions welcome! Please feel free to submit issues and pull requests.