question

rblaa avatar image
rblaa asked ·

can't load Amazon-Web-App-API in web view

Hi. I am trying to use the AmazonAdvertising api for the getAdvertisingId and getLimitAdTrackingPreference methods to get the user's ad tracking preferences.

I followed the instructions for including the Amazon web api, making a little test page that loads the api and attempts to make a call.

What I am finding is that when I run from the Web App Tester, everything works fine: the api loads, the amazonPlatformReady event fires, i can get the ad id.

However, when I use a WebView in a native app, the api fails to load, the amazonPlatformReady event never fires.

The Amazon web api is supposed to be available to web views as well is it not?

Here is the test page I was using.

<!DOCTYPE html>

<html>

<head>

<title>AmazonAdvertising Test Page</title>

</head>

<body>

<h2 style="padding: 2em">Ad Id: <span id="ad-id">???</span></h2>

<script src="https://resources.amazonwebapps.com/v1/latest/Amazon-Web-App-API.min.js"></script>;

<script>

function onAmazonPlatformReady() {

var AmazonAdvertising = window.AmazonAdvertising;

console.log("amazonPlatformReady: AmazonAdvertising: " + AmazonAdvertising);

AmazonAdvertising.getAdvertisingId(adId => {

console.log('getAdvertisingId: ' + adId);

var display = document.querySelector('#ad-id');

display.innerText = adId;

}, errMsg => {

console.error('getAdvertisingId: ' + errMsg);

});

}


document.addEventListener("amazonPlatformReady" , onAmazonPlatformReady, false);

</script>

</body>

</html>


web apps
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jacek avatar image
Jacek answered ·

Hi @rblaa,

If you check the code that is injected by Amazon-Web-App-API, it is just the JS part of Cordova plugin. Web App Tester (WAT) is loading the native (Java) part of that plugin, plus it is basically a Cordova app. Therefore, when you write your own native app, you are missing both, that Java part of that plugin, and the whole Cordova infrastructure to facilitate Java <-> JS communication (to make that plugin run).

If you check the SDK Downloads page, you will notice that Amazon doesn't provide anymore libs for Cordova. So, that route is also SOL (unless you write your own plugin).

My understanding is that if you need that support and you need to go native, your best bet is to write your own Java <-> JS interface, and use this code to support your JS side.

Although, you may want to check properties of WebView you are getting through WAT vs. the one that you get in your own native app. Amazon doesn't want to disclose (or rather has no technical expertise anymore to read the WAT code) how WAT is initializing WebView.

Best, Jacek

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

rblaa avatar image
rblaa answered ·

I note that when running from the Web App Tester, the user agent is:

Mozilla/5.0 (Linux; Android 5.1.1; AFTT Build/LVY48F; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/70.0.3538.110 Mobile Safari/537.36 cordova-amazon-fireos/3.4.0 AmazonWebAppPlatform/3.4.0;2.0

while when running from the native app's web view, it is:

Mozilla/5.0 (Linux; Android 5.1.1; AFTT Build/LVY48F; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/70.0.3538.110 Mobile Safari/537.36

It looks like the api list is explicitly looking for "AmazonWebAppPlatform" to decide if the platform is enabled.

I was understanding that the native web view on the fire tv is now the Amazon web view? Or is there some sort build or manifest setting that configures this?

Or do I need to build with the cordova framework? Currently my app is a simple bare bones launcher that opens a single web view, the rest of the app is in the HTML/JS code.

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.