Gathering detailed insights and metrics for sdk-sa-node
Gathering detailed insights and metrics for sdk-sa-node
Gathering detailed insights and metrics for sdk-sa-node
Gathering detailed insights and metrics for sdk-sa-node
npm install sdk-sa-node
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
8 Commits
1 Branches
1 Contributors
Updated on Jul 28, 2016
Latest Version
1.0.12
Package Id
sdk-sa-node@1.0.12
Unpacked Size
49.01 kB
Size
12.16 kB
File Count
16
NPM Version
3.10.9
Node Version
6.9.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
17
32
This is the home-brewed version of Node SDK for Sensors Analytics.
Install using npm.
$ npm install sa-sdk-node --save
1import SensorsAnalytics from 'sa-sdk-node'
2
3const sa = new SensorsAnalytics()
4
5sa.submitTo('http://xxx.cloud.sensorsdata.cn:8006/sa?token=xxx')
6
7// Super Properties that assigned to every event tracking
8sa.registerSuperProperties({ $appVersion: '1.0.0', env: 'production' })
9
10// Track event
11sa.track('user-id', 'userHappy')
12
13// Track event with custom properties
14sa.track('user-id', 'newOrder', { orderId: '12323' })
15
16// Track Signup
17sa.trackSignup('user-id', 'anonymous-id/device-id')
18
19// Track Signup with custom properties
20sa.trackSignup('user-id', 'anonymous-id/device-id', { userType: 'administrator' })
21
22// Manipuate user project
23sa.profileSet('user-id', { age: 18 })
24sa.profileSetOnce('user-id', { registerTime: new Date().valueOf() })
25sa.profileIncrement('user-id', { scoreCount: 100, issueCount: -1 })
26sa.profileAppend('user-id', { tags: ['student', 'developer'] })
27sa.profileUnset('user-id', ['temporaryTag'])
28
For more detailed information about each api, checkout Sensors Analytics manual
By default, the library uses current time as the time when event occurs,
but the behavior can be overrode by $time
property.
track
and trackSignup
support this feature.$time
can be Date
, number
, string
, Moment
instance1import moment from 'moment' 2 3sa.track('user-id', 'newOrder', { orderId: '12323', $time: new Date(2016,7,30) }) 4sa.track('user-id', 'newOrder', { orderId: '12323', $time: '2016-07-30T00:00:00+08:00' }) 5sa.track('user-id', 'newOrder', { orderId: '12323', $time: 1469808000000 }) 6sa.track('user-id', 'newOrder', { orderId: '12323', $time: moment() }) 7 8sa.trackSignup('user-id', 'anonymous-id/device-id', { $time: new Date(2016,7,30) }) 9sa.trackSignup('user-id', 'anonymous-id/device-id', { $time: '2016-07-30T00:00:00+08:00' }) 10sa.trackSignup('user-id', 'anonymous-id/device-id', { $time: 1469808000000 }) 11sa.trackSignup('user-id', 'anonymous-id/device-id', { $time: moment() })
SensorsData support parsing user geo location from IP address.
track
and trackSignup
support this feature.1router.post('/api/new-order', (req, res) => { 2 sa.track(req.session.userId, 'newOrder', { $ip: req.ip }) 3 4 // ... 5})
Node SDK supports parsing client OS
, OS version
, Browser
, Browser version
, Browser Engine
, Model
from client's User Agent
track
and trackSignup
support this feature.1router.post('/api/new-order', (req, res) => { 2 sa.track(req.session.userId, 'newOrder', { $userAgent: req.get('user-agent') }) 3 // ... 4})
By default, submitter can be created with server url
1import SensorsAnalytics from 'sa-sdk-node' 2 3const url = 'http://xxx.cloud.sensorsdata.cn:8006/sa?token=xxx' 4 5const sa = new SensorsAnalytics() 6 7const submitter = sa.submitTo(url)
But it also can be created with explicit config
1import SensorsAnalytics from 'sa-sdk-node' 2 3const url = 'http://xxx.cloud.sensorsdata.cn:8006/sa?token=xxx' 4 5const sa = new SensorsAnalytics() 6 7const submitter = sa.submitTo({ url, gzip: true, mode: 'track', timeout: 10 * 1000 }) 8// gzip: whether enable gzip, default to true 9// mode: could be 'track' (production use), 'debug' (diagnosis data), 'dryRun' (diagnosis with no data recorded), 10// also supports the values that aligned to other SDKs: debug_off, debug_and_track and debug_only, 11// default to track 12// mode: 13// timeout: Http timeout in ms, default to 10s
Submitter can be create manually and attach to SensorsAnalytics
manually
Created with url with default config
1import SensorsAnalytics, { Submitter } from 'sa-sdk-node' 2 3const url = 'http://xxx.cloud.sensorsdata.cn:8006/sa?token=xxx' 4 5const sa = new SensorsAnalytics() 6 7const submitter = new Submitter(url) 8 9sa.subscribe(submitter)
Or with explicit config
1import SensorsAnalytics, { Submitter } from 'sa-sdk-node' 2 3const url = 'http://xxx.cloud.sensorsdata.cn:8006/sa?token=xxx' 4 5const sa = new SensorsAnalytics() 6 7const submitter = new Submitter({ url, gzip: true, mode: 'track', timeout: 10 * 1000 }) 8 9sa.subscribe(submitter)
Network error handling
1submitter.catch((err) => console.error(err))
WARN Batch submit is not supported by debug
or dryRun
mode. It causes 400 bad-request error
Suppose
1import SensorsAnalytics, { Submitter } from 'sa-sdk-node' 2 3const url = 'http://xxx.cloud.sensorsdata.cn:8006/sa?token=xxx' 4 5const sa = new SensorsAnalytics()
1// Submit when 20 events are tracked
2sa.submitTo(url, { count: 20 })
1// Submit when every 5 seconds
2sa.submitTo(url, { timeSpan: 5 * 1000 })
1// Submit every 5 seconds, but also submit immediately if 20 events tracked
2sa.submitTo(url, { count: 20, timeSpan: 5 * 1000 })
Batch
can be created manually if needed, which can be subscribed with submitter
later
1const batch = sa.inBatch({ count: 20, timeSpan: 5 * 1000 })
2
3batch.subscribe(new Submitter(url))
This library is powered by Microsoft's RxJS.
SensorsAnalytics
is an Observable, which yields tracking data.
Submitter
is an Observer, which consume the tracking data.
Submitter
is also an Observable, which yields next when submitted succeeded, and yields Error
when network errors.
Ideally, you can use all RxJS tricks with this library
1// All the event that raised by debug build app won't be submitted 2sa.filter((event) => event.properties.releaseType !== 'debug') 3 .subscribe(submitter)
1// Useful while tracking user input or other case 2// The event won't be tracked unless user has stopped typing for 500ms 3sa.debounce(500) 4 .subscribe(submitter) 5 6textInput.onChange((text) => sa.track(userId, 'userType', { text }))
For more detail, checkout Microsoft's Rx documentation
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More