Skip to main content

3rd Party Landing Page

This page contains an example to add the following functionality to a 3rd party landing page:

  • Prompt user to share location
  • Update scan location to user's location

The scan ID will usually be passed as a query parameter in the URL like this:

https://some-website-url.com?scan_id=90ee96a4-f7ef-46fb-a3d9-181f66ae590d

To obtain your api-key:

portal > campaign > settings > redirect

access_key

Other parameters that can be added to this redirect URL include

ParameterDescription
{qr}Qr code ID
{id}Scan ID
{sku}Product SKU - Release ETA 20 OKT 2022
{lat}Location Latitude
{lng}Location Longitude
{utid}User Tracking ID
{region}Region Key
{api_key}Campaign Api Key
{install_id}App Install ID
{app_compat}App Compatibility
{product_url}Product URL
{brand_url}Brand URL
{company_url}Company URL
{scm:param}SCM Parameter (param interchangable with actual SCM key)

index.html

<html>
<head>
<script src="./scantrust_stc_sdk.js" type="text/javascript"></script>
<script src="./script.js" type="text/javascript"></script>
</head>
<body></body>
</html>

scantrust_stc_sdk.js

function ScanTrustConsumerSDK(apiKey) {
var apiKey = apiKey;
var scanId = "";

// User accepted to share his position and a GPS location was retrieved
// The pos object contains the position coordinates.
// pos.coords.lat -> Latitude
// pos.coords.lng -> Longitude
var success = function (pos) {
fetch("https://api.scantrust.com/api/v2/consumer/scan/<uuid>/geotag/", {
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json",
"X-ScanTrust-Consumer-Api-Key": apiKey,
},
body: JSON.stringify({
lat: pos.coords.latitude,
lng: pos.coords.longitude,
}),
})
.then(function (response) {
if (response.ok) {
return response;
} else {
throw new Error();
}
})
.then(function () {
console.log("Scantrust Consumer SDK: Scan Location successfully updated");
})
.catch(function (err) {
console.error("Scantrust Consumer SDK Error: " + err);
});
};

// User didn't accept to share his position or the browser was unable to retrieve a GPS location
// Reason for failure is inside the positionError object.
// positionError.code == 1 PERMISSION_DENIED, The acquisition of the geolocation information failed because the page didn't have the permission to do it.
// positionError.code == 2 POSITION_UNAVAILABLE The acquisition of the geolocation failed because at least one internal source of position returned an internal error.
// positionError.code == 3 TIMEOUT The time allowed to acquire the geolocation, defined by positionOptions.timeout information was reached before the information was obtained.
var error = function (positionError) {
console.log(
"Scantrust Consumer SDK : Can't retrieve position. Code: " +
positionError.code +
" message: " +
positionError.message
);
};

this.updateScanLocation = function (id) {
if (!id) {
console.error("Scantrust Consumer SDK Error: Scan ID Not provided");
return;
}

scanId = id;

var positionOptions = {
enableHighAccuracy: false,
timeout: 5000,
};

navigator.geolocation.getCurrentPosition(success, error, positionOptions);
};
}

script.js

var API_KEY = "replace-with-you-api-key";
// The scan ID will usually be passed as a query parameter in the URL. Example: https://some-website-url.com?scan_id=90ee96a4-f7ef-46fb-a3d9-181f66ae590d
var scanId = "90ee96a4-f7ef-44fb-a3d9-181f62ae590d";

var sdk = new ScanTrustConsumerSDK(API_KEY);
sdk.updateScanLocation(scanId);