npm.io
0.1.2 • Published 4 months ago

@ray-js/track

Licence
MIT
Version
0.1.2
Deps
0
Size
42 kB
Vulns
0
Weekly
0

English | 简体中文

@ray-js/track

latest download

Business exception reporting & SDK usage tracking for MiniApp

Installation

npm install @ray-js/track
# or
yarn add @ray-js/track

Use Cases

  1. SDK usage tracking
  2. Common business exception monitoring via detectors
  3. Custom business exception monitoring

Important Notes

  • External developer integration is not supported at this time; this package is intended for Tuya official developers only
  • No data will be reported if the end user disables Feature Experience Upgrade Plan in the App privacy settings
  • Do not use in child-oriented MiniApps
  • Never report personal data such as phone numbers, emails, or real names through msg, params, or detector extension fields

Quick Start

SDK Usage Tracking (for SDK authors)

Embed in your SDK to track how many MiniApps are using it:

import { UsageTracker } from '@ray-js/track';

// Call once during SDK initialization
UsageTracker.report({
  sdkName: '@ray-js/your-sdk',
  sdkVersion: '1.0.0',
});
Common Exception Monitoring (via detectors)
import { TrackSDK, I18nDetector } from '@ray-js/track';

// Create detectors before any business code runs
const i18nDetector = I18nDetector();

// Initialize SDK
const track = TrackSDK.init();

// Register detectors
track.use([i18nDetector]);
Custom Business Exception Monitoring
import { TrackSDK } from '@ray-js/track';

const track = TrackSDK.init();

track.report({
  msg: 'Device connection timeout',
  level: 'error',
  params: { deviceId: 'xxx' },
});