@suucha/analytics-sensors
v0.1.0
Published
Sensors Data (神策) reporter for Suucha Web SDK
Readme
@suucha/analytics-sensors
Sensors Data (神策数据) reporter for Suucha Web SDK. Sends events via navigator.sendBeacon / fetch with optional batching.
Install
pnpm add @suucha/core @suucha/analytics-sensorsUsage
import { suucha } from '@suucha/core';
import { SensorsReporter } from '@suucha/analytics-sensors';
const sensors = new SensorsReporter({
serverUrl: 'https://sensor.example.com/sa',
projectId: 'production',
sendType: 'beacon',
batchSize: 5,
sendInterval: 5000,
});
suucha.addReporter(sensors);
// Optional: link suucha identity to Sensors
suucha.region.router((ctx) => (ctx.host.endsWith('.cn') ? 'cn' : 'global'));
suucha.region.reporters({ cn: [sensors] });Identity
Sync the Suucha anonymous_id and identified user_id to Sensors:
sensors.setAnonymousId(suucha.getAnonymousId());
suucha.identify('user_123');
sensors.login('user_123');Options
| Option | Default | Description |
|---|---|---|
| serverUrl | (required) | Sensors receiver endpoint |
| projectId | - | Project field |
| sendType | 'beacon' | 'beacon' / 'image' / 'ajax' |
| batchSize | 5 | Batch events to reduce request count |
| sendInterval | 5000 | Auto-flush interval (ms) |
Send Strategies
beacon(default): Usesnavigator.sendBeacon. Survives page unload. Best for tracking.image: Sends via 1×1 image pixel. Works cross-origin without CORS.ajax: Usesfetchwithkeepalive: true. Most flexible, slightly less reliable on unload.
License
MIT © Suucha Studio
