particle-academy/fancy-heuristics 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

particle-academy/fancy-heuristics

Composer 安装命令:

composer require particle-academy/fancy-heuristics

包简介

End-user optimization, not search-engine optimization — human + agent interaction analytics for Laravel hosts. Ingests collector events, aggregates focus heatmaps, rolls up sessions by actor, and re-polls sites to verify the embedded Fancy Pixel stays visible.

README 文档

README

Fancified

End-user optimization, not search-engine optimization. Understand and improve what real humans and agents actually do on the page — clicks, focus heatmaps, sessions, and the human-vs-agent split GA can't see — instead of chasing rankings.

particle-academy/fancy-heuristics is the PHP/Laravel ingestion + storage + query backend for human + agent interaction analytics and Fancy UI pixel verification. It is the server half of the Fancy Pixel / Fancy Heuristics trio (paired with the @particle-academy/fancy-pixel badge embed and the @particle-academy/fancy-heuristics-js browser collector).

  • Zero third-party runtime depsilluminate/* only.
  • Namespace FancyHeuristics\, facade Heuristics, config config/heuristics.php.

Install

composer require particle-academy/fancy-heuristics
php artisan vendor:publish --tag=heuristics-config      # optional
php artisan vendor:publish --tag=heuristics-migrations  # optional (auto-loaded otherwise)
php artisan migrate

The wire contract

Browser/agent clients flush JSON via navigator.sendBeacon:

POST /heuristics/collect    { siteKey, sessionId, events: [ Event, ... ], context? }
POST /heuristics/pixel      { siteKey, style, mode, visible, path, ts }

Event = {
  kind: "pageview"|"click"|"scroll"|"pointer"|"dwell",
  actor: "human"|"agent",
  path, ts,
  x?, y?, vw?, vh?, scrollPct?, dwellMs?, targetId?, label?, meta?
}

// Once-per-session acquisition/audience context — sent on the FIRST batch only.
context? = {
  referrer?, utm?: { source?, medium?, campaign?, term?, content? },
  lang?, tz?, screenW?, screenH?, dpr?
}

On collect, the package upserts a derived session row per (siteKey, sessionId): acquisition (referrer/referrer_host + utm_*), audience (device/os/browser classified from the request User-Agent with a self-contained regex — no third-party UA parser — plus lang/tz/screen_*), and engagement (pageviews, events, landing_path/exit_path, duration_ms, is_bounce). The raw User-Agent is truncated and stored; the IP is never stored raw (pixel pings hash it).

Cross-origin clients: these endpoints are posted from browsers on other origins (every site that embeds the Fancy Pixel). They run on the stateless api group (no CSRF 419) and, by default, ship CORS headers + answer the OPTIONS preflight via the bundled HandleHeuristicsCors middleware — so a fresh install works cross-origin with no extra setup. Restrict who may beacon with heuristics.routes.cors.allowed_origins, or set heuristics.routes.cors.enabled (env HEURISTICS_ROUTE_CORS) to false to manage CORS yourself (e.g. Laravel's config/cors.php). Don't do both — two layers would emit a duplicate Access-Control-Allow-Origin.

Facade

use FancyHeuristics\Facades\Heuristics;

Heuristics::record($event);                 // persist one event
Heuristics::collect($payload, $ua);         // persist a batch + upsert its session
Heuristics::ping($ping);                    // persist a pixel liveness beacon
Heuristics::heatmap($siteKey, $path);       // normalised grid of pointer/click hits
Heuristics::events($siteKey, [...]);        // raw events, filtered
Heuristics::sessionStats($siteKey);         // sessions + counts by actor & kind

GA-parity reports

Each takes a $site, a date $range, and an optional $actor filter ('human', 'agent', or null = all). $range is either an int (last N days) or ['from' => Carbon|string, 'to' => Carbon|string] — both compared against the session's started_at. All return primitive, JSON-friendly arrays.

Heuristics::acquisition($site, 30);                  // referrer hosts, utm, direct vs referral
Heuristics::audience($site, 30);                     // device / browser / os / language
Heuristics::timeseries($site, 30, 'day', false);     // sessions+pageviews per bucket (day|week|month)
Heuristics::sessionsSummary($site, 30);              // totals, avg duration, bounce rate, pages/session
Heuristics::topPages($site, 30);                     // top paths by pageviews
Heuristics::entryPages($site, 30);                   // landing pages by session
Heuristics::exitPages($site, 30);                    // exit pages by session
Heuristics::topElements($site, 30);                  // most-clicked target_id / label
Heuristics::realtime($site);                         // sessions active in the last 5 minutes

timeseries(..., $splitActor: true) adds human_sessions / agent_sessions to every bucket.

Pixel verification

heuristics_sites registers each site to re-poll. The verifier fetches the URL server-side and runs the shared detection — the stable data-fancy-badge marker or the literal "Powered by Fancy UI" wordmark (the exact same two signals the showcase's ScanShowcaseSubmission scanner uses, kept in one place in HeuristicsPixelDetector). It updates visible / pixel_status / last_verified_at and fires PixelVerificationPassed / PixelVerificationFailed for the host to toggle a listing.

Run twice daily:

// bootstrap/app.php
use Illuminate\Console\Scheduling\Schedule;

->withSchedule(function (Schedule $schedule) {
    $schedule->command('heuristics:verify-pixels')
        ->cron(config('heuristics.verify.cron')); // default 03:00 & 15:00
})
php artisan heuristics:verify-pixels            # all sites
php artisan heuristics:verify-pixels --site=KEY # one site

Tests

composer install
vendor/bin/pest

⭐ Star Fancy UI

If this package is useful to you, a quick ⭐ on the repo really helps us build a better kit. Thank you!

particle-academy/fancy-heuristics 适用场景与选型建议

particle-academy/fancy-heuristics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 165 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「analytics」 「laravel」 「verification」 「heatmap」 「pixel」 「particle-academy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 particle-academy/fancy-heuristics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 particle-academy/fancy-heuristics 我们能提供哪些服务?
定制开发 / 二次开发

基于 particle-academy/fancy-heuristics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 165
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 42
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-05