Capture motion in Capacitor apps

Forward shakes and accelerometer samples already observed by a Capacitor app into its Ansight session.

Motion capture is opt-in on iOS and Android through @ansight/capacitor. The bridge forwards motion your app already observes; it does not register a native sensor listener or request motion permissions. This guide is for Capacitor 8, not classic Apache Cordova.

Enable capture

Add withMotionCapture() to the options in your development-build bootstrap:

import Ansight from "@ansight/capacitor";

const options = Ansight.createOptionsBuilder()
  .withAnsightDefaults()
  .withMotionCapture()
  .build();

await Ansight.initializeAndActivate(options);

Initialize once after the Capacitor runtime is available, as described in Capacitor Setup.

Forward observations

Call these methods from the handlers your app already owns:

await Ansight.recordShake();
await Ansight.recordAccelerometer(x, y, z); // m/s²

Android accelerometer values are already in metres per second squared. Convert Apple accelerometer values from g by multiplying each axis by 9.80665 before forwarding. The bridge does not begin sampling on its own.

Both event types are enabled by default within withMotionCapture(). Pass { captureShake, captureAccelerometer, minimumSampleIntervalMilliseconds } to narrow capture or change the sample interval. The interval defaults to 20 ms and is clamped to 10–1000 ms.

The host stores app-observed motion in motion/events.json and the session’s motion timeline. For host-injected device motion and the shared evidence contract, see Motion Capture.