Install SDK for Ionic
Add Hypertrack Plugin to project
Ionic Native
Ionic HyperTrack plugin is available for Android platform. To use it add it to your project. If you have Ionic v5.34 or later just execute:
$ npm install @ionic-native/hyper-track
Otherwise you need to install it locally, as your Ionic contains obsolete plugin version. To do it run from the project root directory:
$ curl -SLo hypertrack-plugin.zip https://github.com/hypertrack/ionic-native/releases/download/v5.34.0/hypertrack-v3-0.0.2.zip && \
unzip hypertrack-plugin.zip -d "/app/node_modules/@ionic-native/" && \
rm -f hypertrack-plugin.zip
Cordova plugin
Since Ionic plugin uses Cordova plugin under the hood, you need to install Cordova dependency as well.
$ npx ionic cordova plugin add cordova-plugin-hypertrack-v3
Import HyperTrack class
Add HyperTrack
class to local namespace.
import {HyperTrack} from '@ionic-native/hyper-track';
Get sdk instance.
Get sdk instance passing your publishable key as a parameter:
function initializeHyperTrack() {
console.log("Initializing HyperTrack")
HyperTrack.enableDebugLogging()
HyperTrack.initialize('YOUR-PUBLISHABLE-KEY')
.then( onSdkInstanceReceived )
.catch((err) => console.error("HyperTrack init failed with error " + err));
}
function onSdkInstanceReceived(sdkInstance: HyperTrack) {
console.log("HyperTrack succesfully initialized");
}
Set up silent push notifications
The SDK has a bi-directional communication model with the server. This enables the SDK to run on a variable frequency model, which balances the fine trade-off between low latency tracking and battery efficiency, and improves robustness. This also enables HyperTrack Trips to start and stop tracking automatically when trip starts and ends. For this purpose, the iOS SDK uses APNs silent remote notifications and Android SDK uses FCM silent notifications.
Identify your device
We use internal unique identifiers to manage the devices, so in order to be able to distinguish between users you need to get this device id and pass it to your backend to establish user to deviceId mapping.
onSdkInstanceReceived(sdkInstance: HyperTrack) {}
sdkInstance.getDeviceId()
.then((id) => {
console.log("Got device id " + id)
document.getElementById('device_id').textContent = id
})
.catch((err) => console.error("Got error in HyperTrack " + err))
}
Give your device a name
You can set device name that will show up in your Dashboard and attach metadata. You might wish to look at this guide on how to use it.
hyperTrackInstance.setDeviceName("Jon Hyperseed"))
.then(() => console.log("Device name was changed"))
.then(() => hyperTrackInstance.setDeviceMetadata({platform: "Ionic Android"}))
.then(() => console.log("Device metadata was changed"))
Request permissions
HyperTrack needs access to device's geolocation and motion sensors to detect its position. Although you can use third party libraries to present the dialog, sdk has convenience method for it.
sdkInstance.requestPermissionsIfNecessary()
Resolve tracking blockers
In order for tracking to work reliably, SDK requires the user to grant it certain permissions and enable some features in settings. You can use dedicated SDK API to figure out if all the requirements are met:
HyperTrack.getBlockers()
.then( blockers =>
{
blockers.forEach( blocker => {
console.log(`Blocker ${ blocker.userActionTitle } with CTA ${ blocker.userActionCTA } details ${ blocker.userActionExplanation }`);
// `blocker.resolve()` invocation navigates the user
// to the appropriate menu section
});
}
)
.catch( err => console.error("Got error, while retrieving blockers " + err));
Each blocker has a name, a description, CTA name, and an action that is performed when blocker.resolve()
is invoked. E.g. if user disabled geolocation on aforementioned invocation opens the dedicated Settings menu.
Prepare for App Store and Play Market submission
Read the Prepare for App Store submission section of iOS SDK guide and Get approved for the background location access section of Android SDK guide.
You are all set
Once your app is running, go to the Dashboard where you can see a list of all your devices and their live location with ongoing activity on the map.
SDK integration examples
To learn more about SDK integration examples, you may visit these resources:
Frequently Asked Questions
Support
Join our Slack community for instant responses. You can also email us at help@hypertrack.com.