-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* expose trackVerified() * update verify call * fix location parsing * add desktop app error * remove config fallback * address feedback * include port in desktop app check
- Loading branch information
1 parent
029a6c7
commit a21c72a
Showing
7 changed files
with
240 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<div class="content flex-grow-1 p-4"> | ||
<h1 class="mb-4">Track verified</h1> | ||
<div id="error-alert" class="alert alert-danger fade show" role="alert" style="display: none;"> | ||
<strong>Error:</strong> <span id="error-text">Something went wrong. Check the developer console for details.</span> | ||
</div> | ||
|
||
<p>Use the Radar Verify app to verify the user's current location.</p> | ||
|
||
<div class="mt-5 mb-3 form-row"> | ||
<label for="user-id" class="col-form-label" style="width: 128px;">User ID</label> | ||
<div> | ||
<input type="text" class="form-control" id="user-id" value="test-user-id" style="width: 250px;"> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<button id="track-verified" type="button" class="btn btn-primary" disabled>Call track verified</button> | ||
</div> | ||
|
||
<div id="loader" class="spinner-border text-primary mt-4" role="status" style="display: none;"> | ||
</div> | ||
|
||
<div> | ||
<div id="map" class="mt-4" style="width: 100%; height: 500px; display: none;"></div> | ||
</div> | ||
|
||
<div id="response-details" style="display: none;"> | ||
<h6 class="mt-4">Location</h6> | ||
<div class="mt-2"> | ||
<pre><code id="location" class="code-sample language-json"></code><pre> | ||
</div> | ||
|
||
<h6 class="mt-2">User</h6> | ||
<div class="mt-2"> | ||
<pre><code id="user" class="code-sample language-json"></code><pre> | ||
</div> | ||
|
||
<h6 class="mt-2">Events</h6> | ||
<div class="mt-2"> | ||
<pre><code id="events" class="code-sample language-json"></code><pre> | ||
</div> | ||
</div> | ||
|
||
<div class="mt-4"> | ||
<pre><code class="code-sample language-html"><!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /> | ||
<link href="https://js.radar.com/v{{sdk_version}}/radar.css" rel="stylesheet"> | ||
<script src="https://js.radar.com/v{{sdk_version}}/radar.min.js"></script> | ||
</head> | ||
|
||
<body> | ||
<div id="map" style="width: 100%; height: 500px;" /> | ||
|
||
<script> | ||
$('#track-verified').click(() => { | ||
Radar.initialize('<RADAR_PUBLISHABLE_KEY>'); | ||
|
||
Radar.trackVerified({ userId: 'test-user-id' }) | ||
.then(({ location, user, events }) => { | ||
console.log(location); | ||
console.log(user); | ||
console.log(events); | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html></code> | ||
</pre> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
$('#publishableKey').on('change', () => { | ||
const publishableKey = $('#publishableKey').val(); | ||
if (publishableKey) { | ||
$('#track-verified').prop('disabled', false); | ||
} | ||
}); | ||
let map; | ||
$('#track-verified').click(() => { | ||
$('#error-alert').hide(); | ||
$('#response-details').hide(); | ||
const publishableKey = $('#publishableKey').val(); | ||
Radar.initialize(publishableKey, { debug: true }); | ||
$('#loader').show(); | ||
const userId = $('#user-id').val(); | ||
Radar.trackVerified({ userId }) | ||
.then(({ location, user, events }) => { | ||
console.log('TRACK RESPONSE', { location, user, events }); | ||
$('#loader').hide(); | ||
console.log(location); | ||
console.log(user); | ||
console.log(events); | ||
$('#map').show(); | ||
if (!map) { | ||
map = Radar.ui.map({ | ||
container: 'map', | ||
}); | ||
} | ||
map.setCenter([location.longitude, location.latitude]); | ||
if (map.getZoom() < 14) { | ||
map.setZoom(14); | ||
} | ||
const html = ` | ||
<p>${user.userId}</p> | ||
<p>${location.latitude},${location.longitude}</p> | ||
`.trim(); | ||
const marker = Radar.ui.marker({ html }) | ||
.setLngLat([location.longitude, location.latitude]) | ||
.addTo(map); | ||
$('#response-details').show(); | ||
$('#location').html(JSON.stringify(location, null, 2)); | ||
$('#user').html(JSON.stringify(user, null, 2)); | ||
$('#events').html(JSON.stringify(events, null, 2)); | ||
hljs.highlightAll(); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
$('#loader').hide(); | ||
$('#error-alert').show(); | ||
$('#error-text').html(err.message); | ||
}); | ||
}); | ||
</script> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import SDK_VERSION from '../version'; | ||
import Config from '../config'; | ||
import Device from '../device'; | ||
import Http from '../http'; | ||
import Logger from '../logger'; | ||
import Session from '../session'; | ||
import Storage from '../storage'; | ||
|
||
import type { RadarTrackParams, RadarTrackResponse } from '../types'; | ||
|
||
class VerifyAPI { | ||
static async trackVerified(params: RadarTrackParams) { | ||
const options = Config.get(); | ||
|
||
// user indentification fields | ||
const userId = params.userId || Storage.getItem(Storage.USER_ID); | ||
const deviceId = params.deviceId || Device.getDeviceId(); | ||
const installId = params.installId || Device.getInstallId(); | ||
const sessionId = Session.getSessionId(); | ||
const description = params.description || Storage.getItem(Storage.DESCRIPTION); | ||
|
||
// save userId | ||
if (!userId) { | ||
Logger.warn('userId not provided for trackVerified.'); | ||
} else { | ||
Storage.setItem(Storage.USER_ID, userId); | ||
} | ||
|
||
// other info | ||
const metadata = params.metadata || Storage.getJSON(Storage.METADATA); | ||
|
||
const body = { | ||
...params, | ||
description, | ||
deviceId, | ||
foreground: true, | ||
installId, | ||
sessionId, | ||
metadata, | ||
sdkVersion: SDK_VERSION, | ||
stopped: true, | ||
userId, | ||
}; | ||
|
||
const response: any = await Http.request({ | ||
method: 'GET', | ||
path: 'verify', | ||
data: body, | ||
host: 'http://localhost:52516', | ||
}); | ||
|
||
const { user, events } = response; | ||
let location; | ||
if (user.location && user.location.coordinates && user.locationAccuracy) { | ||
location = { | ||
latitude: user.location.coordinates[1], | ||
longitude: user.location.coordinates[0], | ||
accuracy: user.locationAccuracy, | ||
}; | ||
} | ||
|
||
const trackRes = { | ||
user, | ||
events, | ||
location, | ||
} as RadarTrackResponse; | ||
|
||
if (options.debug) { | ||
trackRes.response = response; | ||
} | ||
|
||
return trackRes; | ||
} | ||
} | ||
|
||
export default VerifyAPI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters