Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's the 'AdjustExample-WebView.html' ?? #411

Closed
jsungh88 opened this issue Dec 30, 2019 · 13 comments
Closed

What's the 'AdjustExample-WebView.html' ?? #411

jsungh88 opened this issue Dec 30, 2019 · 13 comments

Comments

@jsungh88
Copy link

jsungh88 commented Dec 30, 2019

Hi,
I am applying sdk to webview.

I saw 'example-app-webbridge'.. so I have a question.
What's the 'AdjustExample-WebView.html' ??

I already have a url which is loading in 'main activity'. By the way, [ webview.loadUrl (file: ///AdjustExample-Webview.html); ].... Where should I declare the existing url?
How should I integrate with my existing web url....?!?

The code below is my AdjustExample-Webview.html. Please check if there is something wrong.


<!doctype html>

<style type='text/css'> html { font-family:Helvetica; color:#222; } h1 { color:steelblue; font-size:24px; margin-top:24px; } button { margin:0 3px 10px; font-size:12px; } .logLine { border-bottom:1px solid #ccc; padding:4px 2px; font-family:courier; font-size:11px; }
</style>
<script type="text/javascript" src="adjust_event.js"></script>
<script type="text/javascript" src="adjust_config.js"></script>
<script type="text/javascript" src="adjust.js"></script>
<script language="javascript"> window.onerror = function(err) { }
        let yourAppToken = 'app_token';
        let environment = AdjustConfig.EnvironmentSandbox;
        // let environment = AdjustConfig.EnvironmentProduction;
        let adjustConfig = new AdjustConfig(yourAppToken, environment);

        Adjust.onCreate(adjustConfig);

        window.onload = function() {
            // var adjustConfig = new AdjustConfig('app_token', AdjustConfig.EnvironmentSandbox);
            // adjustConfig.setLogLevel(AdjustConfig.LogLevelVerbose);
            // adjustConfig.setOpenDeferredDeeplink(true);
            // adjustConfig.setSendInBackground(true);
            // adjustConfig.setEventBufferingEnabled(false);

            // Adjust.onCreate(adjustConfig);

            var btnTrackSettleEvent = document.getElementById('adjust_settle_done')
            btnTrackSettleEvent.addEventListener("click", function(e){
                e.preventDefault()
                var adjustEvent = new AdjustEvent('code');
                Adjust.trackEvent(adjustEvent);
            });

            var btnTrackReviewEvent = document.getElementById('adjust_review_done')
            btnTrackReviewEvent.addEventListener("click", function(e){
                e.preventDefault()
                var adjustEvent = new AdjustEvent('code');
                Adjust.trackEvent(adjustEvent);
            });

      
        }
</script>

@uerceg
Copy link
Contributor

uerceg commented Dec 30, 2019

@jsungh88

Example app we have in repository which shows how web bridge SDK works is loading AdjustExample-WebView.html which is locally made HTML page placed inside of assets folder in that example app. In case you have your web page somewhere remotely already, then simply instead of loading some local resource like we do, make sure you load your URL inside of the web view.

Cheers

@uerceg
Copy link
Contributor

uerceg commented Jan 3, 2020

@jsungh88 Any update on this one?

@uerceg
Copy link
Contributor

uerceg commented Feb 27, 2020

In case you are still facing this issue, feel free to reopen the issue and ping us in here.

Cheers

@uerceg uerceg closed this as completed Feb 27, 2020
@bahcetepe
Copy link

bahcetepe commented Aug 25, 2022

@uerceg hi, do we have to include following lines in HTML document for webview cases on both IOS and Android? Or they injected by native app's webview container?

<script type="text/javascript" src="adjust_event.js"></script> <script type="text/javascript" src="adjust_config.js"></script> <script type="text/javascript" src="adjust.js"></script>

@uerceg
Copy link
Contributor

uerceg commented Sep 29, 2022

Hey @bahcetepe,

Sorry for delay in replying. You do need to add those scripts in case of Android (iOS is handling this under the hood). In addition to that (with current state of Android web bridge) you'd need to make sure to copy those .js files inside of your Android app's assets folder. But from next release on, we'll start to ship web bridge as an AAR where we will be bundling those .js files so that you don't need to do the manual import.

For usage example, you can inspect source code of our example web app we're using in our web bridge examples: https://adjustweb.neocities.org. There you can see how one can build a web app so that it works with our web bridges once loaded in web views on iOS and Android.

In case you have any further questions, feel free to ping.

Cheers

@bahcetepe
Copy link

bahcetepe commented Oct 10, 2022

@uerceg thank you for your invaluable response. Just another question: is there any way to test html that contains adjust js codes within web browser. When i tried your example link, it throws following exception:

Uncaught ReferenceError: AdjustBridge is not defined
    at Object.onCreate (adjust.js:7:9)
    at setupAdjustBridge ((index):165:24)
    at window.onload ((index):98:17)

I just don't want to try it inside a webview to see it runs or not. I initially want to test it say on Chrome with any android/ios user agent setting. Hope there is a way.

Regards,

@uerceg
Copy link
Contributor

uerceg commented Oct 10, 2022

Hey @bahcetepe,

No, unfortunately there's no way to do that. Our Javascript abstractions were built just to streamline usage of native Adjust SDK under the hood and make API between Javascript and Java / Kotlin more similar. But those wrappers are there just for that and their purpose is to pass data down to the native world to be processed and executed by the native Android SDK. So in order to test if things work as expected, you need to have everything set up -> native SDK and web bridge added, things hooked inside of your native Android app and web page which uses our Javascript wrappers properly loaded inside of the web view.

@bahcetepe
Copy link

@uerceg thank you for your response dude. it would be nice to have a simulated mock responses from 'bridge' to js side. So this might make front end side test isolated and fail fast style.

@uerceg
Copy link
Contributor

uerceg commented Oct 10, 2022

That's an interesting thing for us to know, thanks. I'd be curious to know how would you exactly expect this to look like? If you can maybe share a small example with some pseudo code involved, that should be enough - just to gain basic understanding.

@bahcetepe
Copy link

I mean that instead of following error
Uncaught ReferenceError: AdjustBridge is not defined

If you have an additional js file which initialize AdjustBridge as a mock object, then at least i will be sure that i did remaining adjust js development as expected. I might see the alerts, console.logs etc. Assume you have an integration with a backend rest service and assume this rest service returns http 404 right now. It would be enough to have a mocked http 200 with some data for front end development right?

@uerceg
Copy link
Contributor

uerceg commented Oct 10, 2022

In theory, that'd require quite a lot development effort on our end to build. Here's the rationale, lemme know if something sounds wrong to you.

Uncaught reference error which you see is coming because lack of native setup (as we already mentioned). If you would expect some way to verify way of usage of our Javascript wrappers inside of your web app, I see two possible ways how we can do that:

  1. Build a solid Javascript layer which is going to fake actual outcome of actions you take (meaning you will never see an actual answer from Adjust backend on any action taken because we would not be pinging it), but it might provide you back with some infos about whether you are using API properly or not (meaning us re-implementing some of the core native SDK data validations inside of JS so that you know for example whether your event token you are using for instantiating AdjustEvent is good, is revenue you're attaching valid or not, etc). Problems with this approach are numerous, of course: we would need a mechanism to provide you back with mocked answers to happy and unhappy paths, there's no real communication to Adjust backend, etc.
  2. What you suggested and which includes talking to Adjust backend. This sounds like approach which makes more sense in comparison to 1. from above, but it's way more complex to implement. And implementing this would pretty much mean that we need to practically re-implement SDK inside of the Javascript world (same as with scenario 1 - we would need to reimplement tons of this in that mock system from our actual native SDK).

Our native SDK is not just a layer which is transforming user input into direct HTTP requests and is letting you know back what the HTTP responses were. It has a lot of inner logic (packaging user input, queueing mechanisms, features such as offline mode, event buffering, inner states like disabled / enabled, GDPR forgotten which all depend on storage, etc) which one can't just mock and expect that usage of the API in web app is something which you can know with 100% certainty that is good and that the only missing part is to hook the native part.

@bahcetepe
Copy link

@uerceg Yeah the options and your opinions are pretty reasonable. So, thank you again :)

@juswes
Copy link

juswes commented Nov 22, 2023

Hey @bahcetepe,

Sorry for delay in replying. You do need to add those scripts in case of Android (iOS is handling this under the hood). In addition to that (with current state of Android web bridge) you'd need to make sure to copy those .js files inside of your Android app's assets folder. But from next release on, we'll start to ship web bridge as an AAR where we will be bundling those .js files so that you don't need to do the manual import.

For usage example, you can inspect source code of our example web app we're using in our web bridge examples: https://adjustweb.neocities.org. There you can see how one can build a web app so that it works with our web bridges once loaded in web views on iOS and Android.

In case you have any further questions, feel free to ping.

Cheers

Hi @uerceg,

You mentioned that you'll start shipping web bridge as an AAR and will be bundeling the .js files so that you don't need to import them manually anymore. Are those changes live in the current (stable) SDK packages?

And might you have an example of how to use those .js files inside of an hybrid Android app. In particular if a hybrid Android app loads an external public facing website into a webview. How should the .js files be linked, if the HTML page is hosted on an external server? Or should those .js files be hosted on that same external server?

uerceg pushed a commit that referenced this issue May 31, 2024
Commented galaxyapps_sdk_referrer dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants