Overview
The QR Codes API provides functionality to generate QR codes for tenant landing pages and track when they are scanned. Each tenant has a unique QR code that redirects to their landing page while recording analytics.QR Code Flow
- Generate: Admin dashboard generates a QR code for the tenant
- Scan: User scans the QR code with their phone
- Track: System records a
qr_scanevent in analytics - Redirect: User is redirected to the tenant’s landing page
Download QR Code
Download the QR code as a PNG image file. This endpoint requires authentication.Path Parameters
The ID of the tenant
Query Parameters
Size of the QR code in pixels (optional)
Response
Returns a PNG image file with appropriate headers for download. Headers:Content-Type: image/pngContent-Disposition: attachment; filename="{subdomain}_qr.png"
Example
Filename Pattern
The downloaded file is named after the tenant’s subdomain:- Tenant subdomain:
mi-negocio - Downloaded file:
mi-negocio_qr.png
QR Code Target URL
Shortlink Format
This is the URL encoded in the QR code. When scanned, it:- Verifies the code is valid for the tenant
- Records a
qr_scananalytics event - Redirects to the tenant’s landing page
Path Parameters
The ID of the tenant
The unique verification code generated for the tenant
Response
Returns a302 Redirect to the tenant’s landing page:
Error Responses
Example URL
Analytics Tracking
Automatic Event Recording
When a QR code is scanned, the system automatically creates an analytics event: Event Type:qr_scan
Recorded Data:
tenant_id: The tenant’s IDevent_type:'qr_scan'user_ip: SHA-256 hash of IP address (first 45 chars)user_agent: Browser/device user agent stringreferer: HTTP referer header (if available)event_date: Date of scan (Y-m-d format)event_hour: Hour of scan (0-23)
Privacy Protection
IP addresses are never stored in plain text:Viewing QR Scan Data
QR scans can be viewed through the Analytics API:QR Code Generation
QRService
QR codes are generated using theQRService class, which:
- Generates a unique verification code for the tenant
- Creates a shortlink URL:
/t/{tenantId}/{code} - Encodes the URL in a QR code image
- Returns PNG binary data
Code Verification
TheQRService::verifyUniqueCode() method ensures:
- The code matches the tenant’s stored code
- The code has not been revoked or expired
- The tenant exists and is active
Customization Options
Size:Implementation Notes
Error Handling
If analytics tracking fails during a QR scan, the error is logged but the redirect still happens:Subdomain Resolution
The redirect uses the tenant’ssubdomain field:
Database Schema
QR codes use thetenants table:
| Column | Type | Description |
|---|---|---|
subdomain | string | Unique subdomain for the tenant |
qr_code | string | Unique verification code |
status | enum | 'active', 'inactive', etc. |
Use Cases
Physical Marketing
- Print QR codes on business cards
- Display on restaurant table tents
- Include in printed catalogs
- Add to store windows
Event Tracking
- Track which marketing materials are most effective
- Monitor QR scans by date and time
- Compare QR traffic vs. direct visits