1.0.1 • Published 27 days ago

ci-trap-capacitor v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
27 days ago

ci-trap-capacitor

Capacitor plugin wrapper over the Android and IOS Trap libraries.

Install

npm install ci-trap-capacitor
npx cap sync

Example

With the following code snippets you are able to configure, start, manage and stop the data collection.

Platform specific notes

  • Android: There is no need for additional config or user permission to capture data with the specified config (see below).

  • IOS: The only requirement is to have the bundle record NSMotionUsageDescription defined and filled in to collect Accelerometer, Gravity, Gyroscope and Magnetometer data.

Please note that enabling Bluetooth, GPS and WiFi related features might need additional permissions.

Sample code

// Initialze Trap with the specified config. This should be called only once
const config = new TrapConfig();
config.reporter.url = "https://[SERVER_URL]/api/1/submit/{sessionId}/{streamId}"
config.defaultDataCollection.collectors = [
  CollectorTypes.Accelerometer,
  CollectorTypes.Battery,
  CollectorTypes.Gravity,
  CollectorTypes.Gyroscope,
  CollectorTypes.Magnetometer,
  CollectorTypes.Metadata,
  CollectorTypes.Pointer,
  CollectorTypes.Stylus,
  CollectorTypes.Touch,
];
// Use the same config in every scenario
config.lowBatteryDataCollection = config.defaultDataCollection;
config.lowDataDataCollection = config.defaultDataCollection;
await CapacitorTrap.configure({config});

// Specify the userId as custom metadata. It will be active until it is removed
// explicitly or a new value is set.
await CapacitorTrap.addCustomMetadata(
  { key: "userId", value: { type: "email", value: "example@example.hu"}});

// Starts the data collection
await CapacitorTrap.start();

// Add any custom event, that will be added to the event stream once,
// immediately when the method is called
await CapacitorTrap.addCustomEvent({ event: {
  action: 'gameStarted',
  game: 'memory'
}});

// Removes the userId as custom metadata (e.g. user logged out)
await CapacitorTrap.removeCustomMetadata({ key: "userId" });

// Stops the data collection
await CapacitorTrap.stop();

API

addCustomEvent(...)

addCustomEvent(options: { event: any; }) => Promise<void>

Add custom event

ParamType
options{ event: any; }

addCustomMetadata(...)

addCustomMetadata(options: { key: string; value: any; }) => Promise<void>

Add custom metadata

ParamType
options{ key: string; value: any; }

checkPermission(...)

checkPermission(options: { collector: CollectorTypes; }) => Promise<PermissionResult>

Checks permission for the specific collector. Returns true if the collector has the required permission.

ParamType
options{ collector: CollectorTypes; }

Returns: Promise<PermissionResult>


configure(...)

configure(options: { config: TrapConfigurationType; }) => Promise<void>

Initialize the plugin

ParamType
options{ config: TrapConfigurationType; }

cleanUp()

cleanUp() => Promise<void>

Cleans up the plugin


removeCustomMetadata(...)

removeCustomMetadata(options: { key: string; }) => Promise<void>

Remove custom metadata

ParamType
options{ key: string; }

requestPermission(...)

requestPermission(options: { collector: CollectorTypes; }) => Promise<void>

Request permission for the specific collector.

ParamType
options{ collector: CollectorTypes; }

start()

start() => Promise<void>

Start data collection


stop()

stop() => Promise<void>

Stop data collection


Interfaces

PermissionResult

PropType
resultboolean

TrapConfigurationType

PropTypeDescription
defaultDataCollectionDataCollectionConfigurationTypeDefault data collection options.
lowBatteryDataCollectionDataCollectionConfigurationTypeLimited data collection in case of low battery
lowDataDataCollectionDataCollectionConfigurationTypeLimited data collection in case of low battery
lowBatteryThresholdnumberBattery charge threshold for low battery status
queueSizenumberThe size of the circular data queue.
reporterReporterConfigurationTypeThe configuration for the reporter task.
sessionIdFilterstringSessionId filter, if specified the data collection is only enabled if sessionId <= sessionIdFilter

DataCollectionConfigurationType

PropTypeDescription
accelerationMaxReportLatencyMsnumberHow long the sensor can cache reported events.
accelerationSamplingPeriodMsnumberHow frequent the sampling of the given sensor should be.
collectCoalescedPointerEventsbooleanCollect coalesced pointer events
collectCoalescedStylusEventsbooleanCollect coalesced stylus events
collectCoalescedTouchEventsbooleanCollect coalesced touch events
collectorsCollectorTypes[]The list of collectors to start at initialization.
gravityMaxReportLatencyMsnumberHow long the sensor can cache reported events.
gravitySamplingPeriodMsnumberHow frequent the sampling of the given sensor should be.
gyroscopeMaxReportLatencyMsnumberHow long the sensor can cache reported events.
gyroscopeSamplingPeriodMsnumberHow frequent the sampling of the given sensor should be.
magnetometerMaxReportLatencyMsnumberHow long the sensor can cache reported events.
magnetometerSamplingPeriodMsnumberHow frequent the sampling of the given sensor should be.
maxNumberOfLogMessagesPerMinutenumberMaximum number of log messages per collector if the collector uses log throttling
metadataSubmissionIntervalnumberThe time interval metadata events are reported.
useGestureRecognizerbooleanUse gesture recognizer for touch event collection

ReporterConfigurationType

PropTypeDescription
apiKeyNamestringName of the api key sent in the HTTP header
apiKeyValuestringValue of the api key sent in the HTTP header
bufferSizeLimitnumber | nullDefault maximum buffer size in number of events (in web collector)
bufferTimeoutnumber | nullDefault timeout for sending the buffer automatically in milliseconds (in the web collector)
cachedTransportbooleanWhether to cache data packets on the device when connection to the remote server cannot be established.
compressbooleanWhether to compress the data sent to the server. If true GZIP compression is used.
connectTimeoutnumberThe connect timeout for the HTTP transport in milliseconds.
idleTimeoutnumber | nullDefault idle timeout in milliseconds (in the web collector).
intervalnumberThe time interval the reporter task runs with.
maxFileCacheSizenumberAbout how much space on the device can be used to store unsent data packets. The lib might use a little more space than this value in case the data packet size exceeds the remaining space.
readTimeoutnumberThe read timeout for the HTTP transport in milliseconds.
sessionIdstringThe persistent session id to send in the header frame. Must be set manually with a custom config class!
urlstringThe URL to send the data packets to.

Enums

CollectorTypes

MembersValue
Accelerometer'Accelerometer'
Battery'Battery'
Bluetooth'Bluetooth'
CoarseLocation'CoarseLocation'
Gravity'Gravity'
Gyroscope'Gyroscope'
Magnetometer'Magnetometer'
Metadata'Metadata'
Pointer'Pointer'
PreciseLocation'PreciseLocation'
Stylus'Stylus'
Touch'Touch'
WiFi'WiFi'
1.0.1

27 days ago

1.0.0

2 months ago