Features and Modifications
The Zendrive SDK provides a number of features that you can use to control how and when trips are detected and where you can implement your business logic. For a table of contents, use the navigation menu on the right.
Collision Detection
The Zendrive SDK provides collision detection. By default, collision detection is enabled in the SDK and is active when a drive is in progress. Register your event listener with Zendrive.registerZendriveCallbackEventListener method. When you listener is notified with event of kind on-accident, you can process collision data.
Testing Collision Detection
After setting up the SDK in collision detection mode, you can test your integration using the Zendrive.triggerMockAccident method. This emulates a fake collision and notifies event of kind on-accident on your registered listener.
import Zendrive from 'react-native-zendrive';
// .....
Zendrive.triggerMockAccident('high').then(response => {
if (response.isSuccess) {
console.log('fake accident triggered');
} else {
console.log(response.errorCode);
console.log(response.errorMessage);
}
});To emulate multiple on-potential-accident event, you can use the following snippet
import Zendrive from 'react-native-zendrive';
// .....
Zendrive.triggerMockAccident({
delayBetweenCallbacksSeconds: 15,
finalCallbackConfidence: 'high',
finalCallbackConfidenceNumber: 75,
potentialCallbackConfidence: 'high',
potentialCallbackConfidenceNumber: 85,
}).then(response => {
if (response.isSuccess) {
console.log('fake accident triggered');
} else {
console.log(response.errorCode);
console.log(response.errorMessage);
}
});Both of the trigger accident callbacks requires the SDK to be set up and a trip to be in progress.
Note that for on-potential-accident to be reported, implementsMultipleAccidentCallbacks should be configured during setup and your license key should opt-in for this feature.
Manual Trip Tagging
The Zendrive SDK works in the background and automatically detects trips and tracks driving behaviour. However, some applications, such as taxi-metering apps, already have knowledge of point-to-point trips made by the driver using the application.
If your application has this knowledge, it can explicitly provide it to the Zendrive SDK.
import Zendrive from 'react-native-zendrive';
// ....
// provide a valid tracking id, use Zendrive.isValidInputParameter if needed.
const trackingId = '<tracking-id>';
Zendrive.startDrive(trackingId).then(response => {
if (response.isSuccess) {
console.log('Drive start operation succeeded');
} else {
console.log(response.errorCode);
console.log(response.errorMessage);
}
});Your application can then use the <tracking-id> argument to find Zendrive trips with this ID in the Zendrive Analytics API. See the SDK Reference for more information.
Driving Sessions
Some applications want to track multiple point-to-point trips together as a single entity. For example, a car rental app may want to track all trips made by a user between a rental car pickup and drop-off as a single entity. You can do this using sessions in the Zendrive SDK. Use the following calls to use sessions.
import Zendrive from 'react-native-zendrive';
// ...
// provide a valid session id, use Zendrive.isValidInputParameter if needed.
const sessionId = '<session-id>';
Zendrive.startSession(sessionId).then(response => {
if (response.isSuccess) {
console.log('Start session operation succeeded');
} else {
console.log(response.errorCode);
console.log(response.errorMessage);
}
});
// ...
// sometime later as per your business logic you can stop the session
Zendrive.stopSession();The Zendrive SDK tags all trips within a session with a single session ID. You can then use the session ID to lookup Zendrive trips belonging to this session using the Zendrive Analytics API. See the SDK Reference for more information.
Controlling Automatic Drive Detection
The Zendrive SDK works in the background and automatically detects trips and tracks driving behaviour. If needed, an application can change this behaviour. For example, a ridesharing app may want to automatically track all drives made by a driver only when she is on-duty and not collect any data for off-duty drives.
The application can specify the required behaviour during setup of the Zendrive SDK.
Zendrive.setup({
driverId: '<driver_id>',
sdkKey: '<sdk_key>',
driveDetectionMode: 'auto-off',
}).then(response => {
if (response.isSuccess) {
console.log('sdk setup succeeded');
} else {
console.log('sdk setup failed');
console.log(response.errorCode);
console.log(response.errorMessage);
}
});The application can also temporarily enable Zendrive's automatic drive-detection. This can be done by setting the Zendrive.setZendriveDriveDetectionMode.
// Turn on automatic drive detection in the SDK.
Zendrive.setZendriveDriveDetectionMode('auto-on').then(response => {
if (response.isSuccess) {
console.log('temporarily enabled auto-on drive detection mode');
} else {
console.log('sdk setup failed');
console.log(response.errorCode);
console.log(response.errorMessage);
}
});
// Turn off automatic drive detection in the SDK.
Zendrive.setZendriveDriveDetectionMode('auto-off').then(response => {
if (response.isSuccess) {
console.log('temporarily enabled auto-off drive detection mode');
} else {
console.log('sdk setup failed');
console.log(response.errorCode);
console.log(response.errorMessage);
}
});Vehicle Tagging
Refer Vehicle Tagging to understand complete details of this feature.
- Associate a vehicle
// associate a vehicle
Zendrive.associateVehicle({
vehicleId: '',
bluetoothAddress: '',
}).then(response => {
console.log(response);
});- Dissociate a vehicle
// dissociate a vehicle
Zendrive.dissociateVehicle('vehicle-id').then(response => {
console.log(response);
});- Get list of associated vehicles
// list vehicles
Zendrive.getAssociatedVehicles().then(response => {
console.log(response);
});Response is of the following type
export type ZendriveVehicleTaggingOperationResult = {
isSuccess: boolean;
errorMessage: string;
errorCode: ZendriveVehicleTaggingErrorCode;
};Following error codes are reported in response data if the call fails
export enum ZendriveVehicleTaggingErrorCode {
ASSOCIATED_VEHICLE_CONFLICT = 'associated-vehicle-conflict',
ASSOCIATED_VEHICLES_LIMIT_EXCEEDED = 'associated-vehicle-limit-exceeded',
INVALID_VEHICLE_ID = 'invalid-vehicle-id',
INVALID_ZENDRIVE_VEHICLE_INFO = 'invalid-zendrive-vehicle-info',
SDK_NOT_SETUP = 'sdk-not-setup',
SUCCESS = 'success',
VEHICLE_NOT_ASSOCIATED = 'vehicle-not-associated',
INVALID_ZENDRIVE_VEHICLE_BEACON = 'invalid-zendrive-vehicle-beacon',
BEACON_NOT_ASSOCIATED = 'beacon-not-associated',
ASSOCIATED_VEHICLE_BEACON_CONFLICT = 'associated-vehicle-beacon-conflict',
MULTIPLE_UUID_ASSOCIATION_ERROR = 'multiple-uuid-association-error',
BLE_SCAN_NOT_SUPPORTED = 'ble-scan-not-supported',
BEACON_SCAN_ALREADY_IN_PROGRESS = 'beacon-scan-already-in-progress',
BLUETOOTH_NOT_AVAILABLE = 'bluetooth-not-available',
BLE_SCAN_INTERNAL_ERROR = 'ble-scan-internal-error',
LOCATION_ERROR = 'location-error',
}If a vehicle is associated, tagged vehicle information is part of the event payload received during on-drive-analyzed event. See the following code snippet to retieve tagged vehicle
const tagInfo = driveInfo.tags.find(
tag => tag.key === 'com.zendrive.sdk.vehicleId'
);
console.log(tagInfo);
const vehicleId = tagInfo.value;Pause Auto Trip Tracking
Refer Pause Auto Tracking to understand complete details of the feature.
- Pause auto trip tracking
// eslint-disable-next-line no-undef
Zendrive.pauseAutoDriveTracking(pausedTillTimestamp).then(response =>
console.log(response)
);- Resume auto trip tracking
// eslint-disable-next-line no-undef
Zendrive.resumeAutoDriveTracking().then(response => console.log(response));- Get status of auto tracking.
// eslint-disable-next-line no-undef
Zendrive.isAutoTripTrackingPaused().then(response => console.log(response));Business Hours
Refer Business Hours APIs to understand complete details about the feature.
// eslint-disable-next-line no-undef
Zendrive.refreshBusinessHours().then(response => console.log(response));// eslint-disable-next-line no-undef
Zendrive.autoTrackingPausedReason().then(response => console.log(response));// eslint-disable-next-line no-undef
Zenedrive.logSDKHealth(ZendriveSDKHealthReason);