0.0.13 • Published 8 months ago
@strukt-io/analytics v0.0.13
@strukt-io/analytics
A lightweight, privacy-focused analytics package for React web applications.
Features
- Privacy-focused with configurable data collection
- Built-in support for page views and custom events
- TypeScript support
- Automatic path tracking
- Customizable endpoint support
Install
npm install @strukt-io/analytics
or
yarn add @strukt-io/analytics
Usage
Import and initialize the analytics hook in your application:
<Analytics pathname="/" options={{
server: 'https://api.example.com/analytics',
projectId: 'proj_123abc',
detailed: false,
ignoreLocalhost: true,
ignoreOwnVisits: true,
recordPath: '/api/event/record',
actionPath: '/api/event/action',
}} />
or
useAnalytics('/', {
server: 'https://api.example.com/analytics',
projectId: 'proj_123abc',
detailed: false,
ignoreLocalhost: true,
ignoreOwnVisits: true,
recordPath: '/api/event/record',
actionPath: '/api/event/action',
})
The analytics hook will automatically track page views when the path changes. An undefined or empty path will be skipped.
This hook is safe to use during server-side rendering and will only activate on the client.
API
Parameters
pathname
{?String}
Current path to trackconfig
{Object}
Configuration object containing:endpoint
{String}
Analytics API endpointprojectId
{String}
Your project identifierapiKey
{?String}
Optional API key for authentication
options
{?Object}
Optional configuration:detailed
{Boolean}
Enable detailed event trackingignoreLocalhost
{Boolean}
Skip tracking on localhostignoreOwnVisits
{Boolean}
Skip tracking your own visitscustomDimensions
{Object}
Additional data to track
Privacy
This package is designed with privacy in mind:
- No cookies by default
- Configurable data collection
- IP anonymization
- Respects Do Not Track
- GDPR compliant
- No third-party requests
License
MIT © Strukt