laravel-fulmo maintained by three_oh_eight
Laravel Fulmo
Laravel forwarder for Fulmo, the privacy-first web analytics platform.
What it does
The package receives Fulmo tracker beacons and consent proofs on your own domain, so the browser only ever talks to your origin. It resolves the consent tier of each visitor, and forwards one signed event per delivery to a Fulmo instance. It also ships the consent banner bundle and a Blade component that loads the tracker only after the visitor grants the Analytics category.
Requirements
- PHP 8.5 or higher
- Laravel 13
illuminate/*components (bus,cache,console,contracts,cookie,database,http,queue,routing,support,translation,view) - A queue worker, unless you use the
after_responseorsyncdispatch mode - A cache store (rate limiters and the circuit breaker use it; it must be shared between your web and worker processes)
Install
composer require three_oh_eight/laravel-fulmo
Publish what you need:
php artisan vendor:publish --tag=fulmo-config
php artisan vendor:publish --tag=fulmo-assets
php artisan vendor:publish --tag=fulmo-migrations
php artisan vendor:publish --tag=fulmo-lang
php artisan vendor:publish --tag=fulmo-views
| Tag | Publishes to |
|---|---|
fulmo-config |
config/fulmo-forwarder.php |
fulmo-assets |
public/vendor/fulmo (the consent bundle fulmo-consent.min.js and VERSION) |
fulmo-migrations |
database/migrations (the consent_outbox table) |
fulmo-lang |
lang/vendor/fulmo |
fulmo-views |
resources/views/vendor/fulmo |
Publish fulmo-assets again after each package upgrade so the bundle stays current. The migrations are publish-only and are never loaded automatically: run php artisan migrate after publishing them if you use the outbox consent proof mode (the default).
Set the environment variables:
FULMO_TRACKER_ENABLED=true
FULMO_TRACKER_SITE=example.com
FULMO_CONSENT_URL=https://fulmo.example.com
FULMO_CONSENT_SOURCE_ID=example-site
FULMO_CONSENT_SECRET=your-shared-secret
FULMO_CONSENT_URL is the root of your Fulmo instance without a trailing path. FULMO_CONSENT_SOURCE_ID must match ^[a-z0-9-]{1,32}$ and be known to Fulmo, together with the secret. With any of the three transport values empty, nothing is sent.
Routes
Call Fulmo::routes() from routes/web.php (or any route file) outside the web middleware group. The beacons are sent without credentials, so session and CSRF middleware must not run.
use ThreeOhEight\Fulmo\Facades\Fulmo;
Fulmo::routes();
| Name | Method and URI | Purpose |
|---|---|---|
fulmo.event |
POST {prefix}/e |
Tracker beacon |
fulmo.config |
GET {prefix}/config |
Configuration for track.js and the banner |
fulmo.consent.config |
GET {consent_prefix}/config |
Banner configuration, resolved per visitor geo |
fulmo.consent.log |
POST {consent_prefix}/consent-log |
Consent proof from the banner |
With the defaults these are /fulmo/e, /fulmo/config, /consent/config and /consent/consent-log.
routes.prefixandroutes.consent_prefixchange the URI prefixes.routes.without_middlewareis a list of middleware class names stripped from the two POST routes. Use it when your application applies session, CSRF or similar middleware globally.- Every route runs
EnsureEnabledfirst, which answers 404 while that route's side is off:fulmo.eventwhileenabled(the tracker) is false, the twofulmo.consent.*routes whileconsent.enabledis false, andfulmo.configonly when both are false. The consent routes are served with the tracker off, so a site can show the banner and collect consent proofs without tracking. The two POST routes also runRejectOversizedBodyand a rate limiter.
CSRF exception
If the two POST routes end up behind CSRF verification (for example your app appends the middleware to every route), either list the CSRF middleware class in routes.without_middleware, or add a CSRF exception for them. With the defaults the paths to exempt are:
fulmo/e
consent/consent-log
Adjust them if you changed the prefixes. Register them in bootstrap/app.php:
use Illuminate\Foundation\Configuration\Middleware;
->withMiddleware(function (Middleware $middleware): void {
$middleware->preventRequestForgery(except: [
'fulmo/e',
'consent/consent-log',
]);
})
Consent cookie
The banner bundle writes the fulmo_consent cookie from JavaScript, in plain text. The package registers EncryptCookies::except('fulmo_consent') in its service provider, so you do not need to add this exception yourself.
Config reference
All keys live in config/fulmo-forwarder.php.
Top level
| Key | Default | Meaning |
|---|---|---|
enabled |
env('FULMO_TRACKER_ENABLED', false) |
Tracker switch. Gates the beacon route (404 when off), the inline loader that injects track.js and Fulmo::cspSources(). The consent side has its own switch, consent.enabled. |
site |
env('FULMO_TRACKER_SITE', '') |
Host only, no scheme. The tag's data-site and the only s a beacon or consent proof may carry. |
script_url |
https://fulmo.io/js/track.js |
Fulmo's track.js, injected only after the visitor grants Analytics. |
routes
| Key | Default | Meaning |
|---|---|---|
prefix |
fulmo |
URI prefix of the beacon and config routes. |
consent_prefix |
consent |
URI prefix of the consent banner routes. |
without_middleware |
[] |
Middleware stripped from the two POST routes. |
max_body_bytes |
16384 |
A declared Content-Length above it answers 413; an oversized body without a declared length is silently refused with 204. |
limits
Requests per minute.
| Key | Default | Meaning |
|---|---|---|
tracker_per_ip |
120 |
Beacons per address (an IPv6 /64 counts as one). |
tracker_global |
600 |
Beacons from all visitors together. |
consent_log_per_ip |
20 |
Consent proofs per address. |
consent_log |
100 |
Consent proofs from all visitors together. |
transport
| Key | Default | Meaning |
|---|---|---|
driver |
http |
Reserved. Replace the transport through the contracts, see Custom transports. |
url |
env('FULMO_CONSENT_URL', '') |
Fulmo root. Events go to {url}/webhook/analytics, proofs to {url}/webhook/consent. |
source_id |
env('FULMO_CONSENT_SOURCE_ID', '') |
Sent as X-Consent-Source. |
secret |
env('FULMO_CONSENT_SECRET', '') |
HMAC key shared with Fulmo. |
timeout |
3 |
Request timeout in seconds. |
connect_timeout |
2 |
Connect timeout in seconds. |
circuit_breaker_seconds |
60 |
Sending pauses this long after a connection failure. |
A plain http:// URL is refused outside the local and testing environments, because the bodies carry visitor data and the signature would be readable on the wire.
dispatch
| Key | Default | Meaning |
|---|---|---|
mode |
queue |
queue, after_response or sync. |
connection |
null |
Queue connection, null for the application default. |
queue |
null |
Queue name, null for the application default. |
consent
| Key | Default | Meaning |
|---|---|---|
enabled |
env('FULMO_CONSENT_ENABLED', true) |
Consent switch. Gates the banner bundle tag and the consent/config and consent/consent-log routes (404 when off), independently of the tracker. |
max_tier |
2 |
Highest consent tier a beacon may carry (0 to 2). |
categories |
['a', 'om', 'dl'] |
Optional categories the site offers, a subset of a, sd, om, dl, utm, mk. core is implied. If the value is not an array, all categories but mk apply. |
never_offered |
[] |
Categories never shown, whatever categories says. |
proof |
outbox |
outbox or after_response, see Consent proof. |
outbox_cap |
50000 |
Undelivered outbox rows allowed before the endpoint answers 503. |
batch |
50 |
Rows the forward command takes at a time. |
run_seconds |
45 |
Time budget of one command run. |
retention_days |
30 |
Forwarded or refused rows are pruned after this many days. |
pending_retention_days |
14 |
Never delivered rows are pruned after this many days. |
cookieless_visitor_hash |
env('FULMO_COOKIELESS_VISITOR_HASH', false) |
Off: no event carries the visitor's IP address or user agent, at any tier. On: tier 0 events (no consent) carry ip and ua so Fulmo can derive a daily rotating visitor hash and discard them. That is personal data sent without consent; enable it only with a legal basis and a matching privacy statement. |
trusted_geo_headers |
['country' => 'CF-IPCountry', 'region' => 'CF-Region-Code'] |
Header names carrying the visitor's ISO 3166-1 alpha-2 country and two-letter region. region may be null. Honoured only from a trusted proxy. |
banner
| Key | Default | Meaning |
|---|---|---|
locale |
null |
Banner language, null follows the application locale. |
accent |
null |
Accent colour as #rrggbb. |
privacy_url |
null |
Privacy policy link, null hides it. |
imprint_url |
null |
Imprint link, null hides it. |
forget_url |
null |
Link to a page where visitors can withdraw consent and ask for their data to be deleted, for example https://fulmo.example.com/forget; null hides it. Use an https:// URL or a path starting with a single /. The bundle appends domain (the site) and, when the visitor has a tracker id (from consent tier 1), id, unless the URL already carries them. |
csp_nonce
Default null. See Blade component and CSP nonce.
Dispatch modes
dispatch.mode decides when a beacon is delivered. The beacon endpoint always answers 204, whatever happens.
| Mode | Behaviour | Event serialized? |
|---|---|---|
queue |
ForwardEvent is queued. Needs a worker. |
Yes |
after_response |
The job runs after the response is sent, in the same process. No worker needed. | Yes, through the job machinery |
sync |
ForwardEvent::handle() is called directly inside the request. |
Never |
ForwardEvent and ForwardConsentProof implement ShouldBeEncrypted, so a tier 0 event carrying ip and ua (only with consent.cookieless_visitor_hash on) never sits in plaintext in the queue store or in failed_jobs. The consequence: queued payloads are encrypted with APP_KEY, and jobs queued before a key rotation cannot be decrypted afterwards. Drain the queue before rotating the key. Alternatively list the old key in APP_PREVIOUS_KEYS. Every worker needs the same APP_KEY as the web process, or it cannot decrypt the jobs.
sync is the only mode in which the event is never serialized. Use it with an in-process transport.
Consent proof
The banner posts every visitor choice to POST {consent_prefix}/consent-log. consent.proof decides what happens next.
outbox(default): the record is stored in theconsent_outboxtable and a scheduled command forwards it, so a Fulmo outage loses nothing. Atconsent.outbox_capundelivered rows the endpoint answers 503 and stores nothing; the banner retries. Needs the published migration.after_response: the record is sent once after the response is out. If delivery fails the proof is dropped, so useoutboxwhen you cannot lose proofs.
The endpoint answers 202 when accepted, 204 when silently refused (wrong site, invalid body, or an oversized body without a declared length), 413 when a declared Content-Length is above routes.max_body_bytes, and 503 when not stored.
Scheduler
Add both entries to routes/console.php:
use Illuminate\Support\Facades\Schedule;
use ThreeOhEight\Fulmo\Models\ConsentOutbox;
Schedule::command('fulmo:forward-consent')
->everyMinute()
->withoutOverlapping();
Schedule::command('model:prune', ['--model' => ConsentOutbox::class])
->daily();
fulmo:forward-consent delivers rows in batches of consent.batch until nothing is due or consent.run_seconds have passed. Each row keeps its own delivery id across retries. A 400, 413 or 422 answer is final (the row is marked refused and logged); any other failure is retried with exponential backoff from one minute up to six hours. A connection failure, a 429 or a 5xx ends the run early.
Blade component and CSP nonce
Place the component in the <head> of every visitor layout:
<x-fulmo::tracker />
It renders the consent bundle tag (/vendor/fulmo/fulmo-consent.min.js) and an inline loader that injects track.js only after the visitor grants the Analytics category. The bundle tag renders while consent.enabled is true, whether the tracker is on or not; the loader renders while enabled is true and a site and script URL are set, and without the bundle it never injects track.js. With both switches off nothing renders. Both script tags carry the nonce when one is configured.
CSP nonce
Set csp_nonce to a callable or a class name. It is resolved from the container at render time and must return the nonce string of the current request; an empty answer means no nonce.
// config/fulmo-forwarder.php
'csp_nonce' => App\Support\CspNonce::class,
Fulmo::cspSources() returns the origins your policy must allow for a directive. For script-src it returns the exact track.js URL while the tracker is enabled, and an empty list otherwise or for any other directive:
$scriptSrc = ["'self'", ...Fulmo::cspSources('script-src')];
Beacons go to your own origin, so connect-src 'self' already covers them.
Banner and languages
Forget link on your own pages
window.FulmoConsent.forgetUrl() returns the banner's forget link: banner.forget_url with domain and, when a tracker id exists, id appended. It returns "" when the link is hidden. The URL comes from the consent config, so call it once the bundle has reported a choice, for example on a cookie page:
<a id="forget-me" hidden>Delete my data</a>
<script>
document.addEventListener('DOMContentLoaded', () => FulmoConsent.onConsent(() => {
const url = FulmoConsent.forgetUrl(), link = document.getElementById('forget-me');
link.hidden = url === ''; if (url) link.href = url; }));
</script>
The bundle tag is deferred, so FulmoConsent exists only from DOMContentLoaded on. Add the nonce to that inline script when your CSP requires one.
Banner and languages
Configure the banner through the banner block. The shipped texts are in English (en), Dutch (nl), German (de) and French (fr), in resources/lang/{locale}/consent_banner.php. Publish fulmo-lang to override them. Which banner type a visitor sees follows their geo regime.
Custom transports
Delivery goes through two contracts in ThreeOhEight\Fulmo\Contracts:
interface EventTransport
{
public function send(array $event, string $deliveryId): TransportResult;
}
interface ConsentProofTransport
{
public function sendProof(array $record, string $deliveryId): TransportResult;
}
The default HttpTransport implements both. Replace either with Fulmo::transportUsing(), typically from a service provider's boot(). Each closure receives the container:
use Illuminate\Contracts\Container\Container;
Fulmo::transportUsing(
events: fn (Container $app) => $app->make(MyEventTransport::class),
proofs: fn (Container $app) => $app->make(MyProofTransport::class),
);
Both arguments are optional. A plain container binding of EventTransport or ConsentProofTransport in your app does the same.
Return a ThreeOhEight\Fulmo\Transport\TransportResult:
| Factory | Use when |
|---|---|
TransportResult::delivered() |
The event was taken (counts as status 200). |
TransportResult::response(int $status, string $retryAfter = '', string $error = '') |
The receiver answered with this status. |
TransportResult::unreachable(string $error = '') |
The receiver could not be reached. |
TransportResult::skipped(string $reason) |
Nothing was attempted. Reasons: SKIPPED_NOT_CONFIGURED, SKIPPED_INSECURE, SKIPPED_CIRCUIT_OPEN. |
Rules for implementations:
- Do not throw on an unreachable or refusing receiver; return a result.
erroris a short reason and must never contain the payload. - The delivery id is identical on every retry of the same item. Store at most once per id.
- An in-process transport must not let exceptions carry the event out. A thrown exception can reach the exception handler, a failed job record or an error tracker with the event, including
ipanduaat tier 0 whenconsent.cookieless_visitor_hashis on, attached. Catch everything and return a result. - Pair an in-process event transport with
dispatch.mode = syncso the event is never queued.
Wire contract
The default transport posts to {url}/webhook/analytics (events) and {url}/webhook/consent (proofs) with these headers:
| Header | Value |
|---|---|
X-Consent-Source |
transport.source_id |
X-Webhook-Id |
The delivery id. Identical on every retry of the same item. |
X-Webhook-Timestamp |
Unix seconds at send time (Fulmo accepts a 300 second window). |
X-Webhook-Signature |
sha256= followed by hex(HMAC-SHA256(secret, "{timestamp}.{body}")) over the exact bytes posted |
The body is {"events":[event]} with exactly one event per delivery. Redirects are never followed.
Delivery of events (ForwardEvent):
- 4 tries, with waits of 30, 120 and 600 seconds between them.
- A 5xx, an unreachable Fulmo or an open circuit breaker is retried; after the fourth attempt the event is dropped and logged.
- A 429 is retried after at least 120 seconds, longer when
Retry-After(seconds or an HTTP date) asks for it, at most 3600 seconds. - 400, 401, 403, 413, 422 and 3xx answers are final and only logged. 401 and 403 are logged as an error at most once a day, because they mean the source configuration is wrong.
- Consent proofs sent with
after_responseget one attempt. Outbox proofs follow the backoff described under Scheduler.
Circuit breaker: a connection failure sets a cache flag for transport.circuit_breaker_seconds. While it is set nothing is sent, so an unreachable Fulmo does not cost one timeout per item. Timeouts are transport.timeout (3 s) and transport.connect_timeout (2 s).
Performance monitoring
The package can forward page speed measurements (Core Web Vitals) as type: "perf" events. It is off by default.
FULMO_PERFORMANCE_ENABLED=true
Turn it on after you have updated your privacy statement. The switch is performance.enabled (FULMO_PERFORMANCE_ENABLED, default false). Both config routes, GET {prefix}/config (read by track.js) and GET {consent_prefix}/config (read by the banner), are answered by the same controller and report collect.perf: true only while the switch is on and the visitor's consent grants the Analytics category, false otherwise.
Performance module. Fulmo's measuring code is a separate file, public/fulmo-perf.min.js (vendored unmodified, recorded in public/VERSION). The package serves it on GET {prefix}/perf.js (route name fulmo.perf, Cache-Control: public, max-age=3600, no cookie). The route answers 404 while the switch or the tracker (enabled) is off. While the switch is on, <x-fulmo::tracker /> sets data-perf="/{prefix}/perf.js" on the track.js tag its loader injects; with the switch off the output is unchanged and track.js never requests the module. track.js loads it only at consent tier 1 or higher, with collect.perf true, for a visitor that is not a bot, and only when the Analytics grant was already stored before the page started loading (FulmoConsent.grantedAtLoad()): on the page where the visitor gives consent nothing is measured; measuring starts on the next page view. The module is same-origin and gets the loader's nonce, so a CSP needs no extra source for it. It writes no cookie, localStorage or sessionStorage.
Gate. A performance event is forwarded only when the switch is on and the visitor's consent tier is 1 or higher (Analytics category granted). The gate runs before anything else: at tier 0, or with the switch off, the beacon is answered with 204 and nothing is forwarded. It is not turned into a load event.
Never forwarded. A performance event carries no sid, no tid, no ip, no ua and no visitor hash, also with consent.cookieless_visitor_hash on. Besides the fields below it holds endpoint, s, tier, type, ts, path, received_at, country, region, consent_flags and, when the visitor sent a Global Privacy Control signal, gpc.
Performance wire contract
Every field is checked on its own. An invalid, out of range or unknown value is dropped, never clamped, because a clamped value would distort percentiles. A part (a ttfb_*, lcp_* timing or inp_* timing field) is also dropped when its metric is absent or when it is larger than its metric. An event without any of ttfb, fcp, lcp, inp or cls is dropped as a whole. Times are integer milliseconds from 0 to 60000.
| Field | Type | Range or allowed values |
|---|---|---|
v |
integer | 1 |
tpl |
string | ^[a-z0-9][a-z0-9_./-]{0,63}$ |
browser, os, device |
string | ^[A-Za-z0-9][A-Za-z0-9 ._-]{0,31}$ |
nav |
string | navigate, reload, back_forward, bfcache, prerender, restore |
pvt |
string | first, next, return |
proto |
string | ^[a-z0-9][a-z0-9./-]{0,15}$ |
st |
integer | 100 to 599 |
tsz |
integer | 0 to 2147483647 (bytes) |
ect |
string | slow-2g, 2g, 3g, 4g |
mem |
number | 0.25, 0.5, 1, 2, 4, 8 |
vw |
string | xs, sm, md, lg, xl |
ttfb, fcp, lcp, inp |
integer | 0 to 60000 ms |
cls |
number | 0 to 10, rounded to 4 decimals |
ttfb_wait, ttfb_cache, ttfb_dns, ttfb_conn, ttfb_req |
integer | 0 to 60000 ms, at most ttfb |
lcp_ttfb, lcp_delay, lcp_load, lcp_render |
integer | 0 to 60000 ms, at most lcp |
inp_input, inp_proc, inp_pres |
integer | 0 to 60000 ms, at most inp |
lcp_el, inp_el, cls_el |
string | Selector built by the tracker: SELECTOR_PATTERN, at most 120 characters, and no #id or .class token matching SELECTOR_DENY_TOKEN |
lcp_type |
string | image, text, video, bg |
lcp_ft |
string | LCP_FILE_TYPES: avif, webp, jpg, jpeg, png, gif, svg, jxl, bmp, ico, mp4, webm, ogv, mov |
lcp_lazy |
boolean | true, false |
lcp_prio |
string | high, low, auto |
lcp_host |
string | A lower case hostname, at most 253 characters |
inp_evt |
string | INP_EVENT_TYPES: pointerdown, pointerup, pointercancel, mousedown, mouseup, click, dblclick, auxclick, contextmenu, touchstart, touchend, touchcancel, keydown, keyup, keypress, beforeinput, input, compositionstart, compositionupdate, compositionend |
loaf |
list | 1 to 3 script entries; more than 3 drops the field. An entry with an invalid sub-field is dropped, except for path, which is dropped on its own. |
SELECTOR_PATTERN is ^[a-z][a-z0-9-]{0,31}(?:#[a-z][a-z-]{1,30})?(?:\.[a-z][a-z-]{1,30}){0,3}(?: > [a-z][a-z0-9-]{0,31}(?:#[a-z][a-z-]{1,30})?(?:\.[a-z][a-z-]{1,30}){0,3}){0,4}$: the element and at most four ancestors joined by >, each a tag with an optional id and up to three classes made of lower case letters and dashes. Text content, attribute values and URLs are never part of a selector. SELECTOR_DENY_TOKEN is (^|-)(author|user|byuser|member|profile|customer|account|name)(-|$), tested against each #id and .class token: a token that may name a person (comment-author-jansen, user-pietje) drops the whole selector. The deny word must be a whole dash-separated part, so username-field is kept.
Each loaf entry:
| Key | Type | Range or allowed values |
|---|---|---|
dur |
integer | 0 to 60000 ms, required |
host |
string | A lower case hostname, at most 253 characters |
path |
string | Kept only when fp is true, the path differs from the page path and matches LOAF_PATH_PATTERN (^/(?:[A-Za-z0-9._-]{1,40}/){0,6}[A-Za-z0-9._-]{1,64}\.m?js$), at most 160 characters; otherwise only path is dropped and the entry stays. Digit-only segments (a build hash or version) are accepted. |
fn |
string | ^[A-Za-z0-9_$.<>]{1,64}$ |
inv |
string | LOAF_INVOKER_TYPES: user-callback, event-listener, resolve-promise, reject-promise, classic-script, module-script |
fp |
boolean | true when the script is first party |
Envelope keys type, ts, path and s follow the other event types and are not part of this table.
Privacy and security notes
- By default no event carries the visitor's IP address or user agent, at any tier, so a tier 0 event (no consent) holds nothing that identifies the visitor and Fulmo derives no visitor hash. Only with
consent.cookieless_visitor_hashon doipandualeave the forwarder, at consent tier 0 only, in transit, for Fulmo to truncate, hash into a daily rotating visitor id and discard. That is personal data sent without consent: enable it only with a legal basis and a privacy statement that says so. They are never sent at tier 1 or higher, and the package never logs them. Log context carries only the status and the delivery id. - Consent records contain no IP address and no user agent.
- Laravel Telescope records HTTP client requests and queued jobs, which would capture
ipanduawhenconsent.cookieless_visitor_hashis on, and the rest of each event in any case. Exclude your Fulmo host from the HTTP client watcher andThreeOhEight\Fulmo\Jobs\ForwardEventandForwardConsentProoffrom the job watcher (for example with aTelescope::filtercallback). Apply the same idea to any other request recorder. - Trusted proxies. Configure trusted proxies with explicit CIDRs, never
'*'. The geo headers inconsent.trusted_geo_headersare honoured only when the request comes from a trusted proxy. An untrusted request has unknown geo and fails closed to the strictest consent regime. Trusting every proxy would let any client choose its own regime. - Rate limits. The beacon route has a per-address and a global bucket (
limits.tracker_per_ip,limits.tracker_global). The consent-log route haslimits.consent_log_per_ipand a globallimits.consent_log. The global buckets cap total load when many addresses act together. The consent config routes are limited to 120 requests per minute per address. - The
enabledswitch turns the tracker off: the beacon route answers 404 and no loader renders, sotrack.jsis never injected. The consent banner and its routes stay on unlessconsent.enabledis false. - Anyone can post a consent proof for a site id they can see. That only weakens the proof trail; a forged row cannot grant consent, because the browser decides from its own
fulmo_consentcookie.
Testing
composer test
composer test:types
composer lint:test
test runs Pest, test:types runs Larastan, lint:test checks code style with Pint.
Security
See SECURITY.md for the responsible disclosure process.
License
MIT, see LICENSE.