tavp-analytics
Analytics, fraud detection, & user behavior tracking for TAVP — with full GA4 + Matomo + GTM parity.
Version: 1.0.0 (2026-08-29)
Features
Privacy & Compliance (Epic A)
- Consent Mode v2 + TCF 2.2 — banner <300ms, categories:
analytics_storage,ad_storage,functionality,personalization,security - Anonymize IP & DNT/GPC — IPv4
/24, IPv6/64, auto-downgrade on DNT/GPC - Retention & Auto-Purge — raw 395d, aggregated 730d, batch 1000,
php artisan analytics:purge - DSAR (GDPR) — export/delete by user_id/email/session/ip, HMAC signature, audit log 2 years
- Audit Trail — consent & DSAR immutable, exportable CSV
Collection (Epic B)
- Web SDK v2 —
tracker.js7.2KB gzipped,sendBeacon, IndexedDB offline queue, SPA history patch - Server Collect API — batch ≤100, HMAC SHA256, idempotency dedup 24h
- Cookieless — fingerprint daily rotation,
sidmemory, configurable sampling
Tag Manager (Epic C)
- Container & Workspace — CRUD, versioning, publish/rollback, draft/live
- Triggers —
page_view,click,scroll,history_change,timer,custom_event,form_submit,visibility - Tags — Custom HTML/JS, GA4, Meta Pixel, TikTok, Webhook
- Preview/Debug —
?tavp_preview=1panel
Processing & Storage (Epic D)
- Ingest Queue — Redis + file fallback, DLQ after 3 attempts, 10k eps
- Sessionization — 30m timeout, bounce detection,
user_idstitching - Archiving — hourly/daily, re-archive idempotent
Reporting (Epic E)
- Funnels — 2-8 steps, conversion/drop-off/time between steps
- E-commerce —
view_item→purchasepipeline, revenue, currency, ads auto-forward - Realtime ≤60s, Segments, Attribution (last/first/linear/position), Cohort
Integration & Extensibility (Epic F)
- Webhooks Outbound — HMAC SHA256, retry 3x exponential, delivery log
- Ads CAPI — Meta, Google Ads, TikTok, hashed PII, consent-gated
Usage
Web SDK
html
<script src="/js/tracker.js" defer></script>
<script>
window.tavpAnalytics.consent.grant({analytics_storage:'granted'});
window.tavpAnalytics.event('button_click','engagement','signup');
</script>Server-Side
php
use Tavp\Analytics\Facades\Analytics;
Analytics::track('user.registered', [
'user_id' => $user->id,
'method' => 'email',
]);E-commerce
php
use Tavp\Analytics\Facades\Ecommerce;
Ecommerce::viewItem($userId, [
'item_id' => 'SKU-123',
'price' => 29.99,
'currency' => 'IDR',
]);Funnels
php
use Tavp\Analytics\Facades\Funnel;
Funnel::step('checkout', 'view_cart', $userId);
Funnel::step('checkout', 'add_payment', $userId);
Funnel::step('checkout', 'complete', $userId);Fraud Detection
php
use Tavp\Analytics\Facades\FraudDetector;
$score = FraudDetector::analyze($request);
if ($score > 0.8) {
// Block request
}API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/analytics/collect | Batch collect ≤100 |
| POST | /api/analytics/track | Page view |
| POST | /api/analytics/event | Custom event |
| POST | /api/analytics/consent | Grant/deny consent |
| POST | /api/analytics/dsar/export | DSAR export |
| POST | /api/analytics/dsar/delete | DSAR delete |
| POST | /api/analytics/container | Create container |
| POST | /api/analytics/container/{id}/publish | Publish |
| POST | /api/analytics/funnel/{slug}/step | Funnel step |
| POST | /api/analytics/ecommerce/{event} | E-commerce event |
| POST | /api/analytics/webhooks | Register webhook |
| POST | /api/analytics/ads/convert | Ads CAPI |
Configuration
php
// config/analytics.php
return [
'enabled' => true,
'anonymize_ip' => true,
'respect_dnt' => true,
'consent' => [
'enabled' => true,
'default_denied' => true,
'cookie_name' => 'tavp_consent',
'tcf_enabled' => true,
],
'retention' => [
'raw_days' => 395,
'aggregated_days' => 730,
'auto_purge_enabled' => true,
],
'queue' => [
'enabled' => false,
'connection' => 'analytics_redis',
],
'ads' => [
'meta' => ['pixel_id' => env('META_PIXEL_ID'), 'enabled' => false],
],
];Install
bash
composer require tavp/analytics
tavp migrate