When an Airbridge tracking link opens within your app's WebView environment, the deep linking user experience can be degraded compared to when it opens in another app. This document describes how to resolve this issue by having the Airbridge SDK open the tracking link instead of the WebView when a tracking link is clicked within the WebView environment.
This document will guide you through the following steps to resolve the issue:
An explanation of the Airbridge SDK function that opens tracking links.
Detecting when a tracking link is clicked within the app's WebView.
Configuring the Airbridge SDK to open the tracking link instead.
Attention
If another company's tracking link is opened in your app, and that other company's app is not installed and the tracking link's fallback is set to a web URL, the fallback web page will open in the user's default browser, not the WebView.
The Airbridge SDK provides a function called Placement Click
which allows you to open tracking links from the native part of your application.
You can use this feature with the following code. You can also pass an AirbridgeCallback<Boolean>
as a parameter to Airbridge.click
to receive a callback for the response.
var trackingLink: String = "..."
Airbridge.click(trackingLink)
String trackingLink = "...";
Airbridge.click(trackingLink);
In WebViewClient
, you can implement WebViewClient#shouldOverrideUrlLoading
to detect when a specific URL is being loaded and decide whether to proceed with loading it or to stop it. Follow the steps below to implement the code to detect if the URL is an Airbridge tracking link.
📘WebViewClient Android Developer Documentation
To implement WebViewClient#shouldOverrideUrlLoading
, create a webViewClient
instance and set it to the webView
using webView#setWebViewClient
. The result of WebViewClient#shouldOverrideUrlLoading
returns whether the WebResourceRequest
was handled. Implement WebViewClient#shouldOverrideUrlLoading
to detect which URL is being loaded. The URL being loaded is passed in the form of request.url
from the WebResourceRequest
function argument.
private val webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(
view: WebView?,
request: WebResourceRequest?
): Boolean {
return super.shouldOverrideUrlLoading(view, request)
}
}
private fun initWebview() {
webView.webViewClient = webViewClient
}
private final WebViewClient webViewClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return super.shouldOverrideUrlLoading(view, request);
}
}
private void initWebView() {
webView.setWebViewClient(webViewClient);
}
Among the URLs being loaded, identify the ones that are Airbridge tracking links. An Airbridge tracking link will have a URL host of abr.ge
, YOUR_APP_NAME.deeplink.page
, or a custom domain.
📘 You can find YOUR_APP_NAME
in your dashboard under Settings > Tokens > App Name
.
override fun shouldOverrideUrlLoading(
view: WebView?,
request: WebResourceRequest?
): Boolean {
request?.url?.let {
val airbridgeHosts = arrayOf(
"abr.ge",
"YOUR_APP_NAME.abr.ge",
"YOUR_APP_NAME.deeplink.page"
)
if (airbridgeHosts.contains(it.host)) {
return true
}
}
return false
}
private final WebViewClient webViewClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Uri uri = request == null ? null : request.getUrl();
if (uri != null) {
String host = uri.getHost();
List<String> airbridgeHosts = Arrays.asList(
"abr.ge",
"YOUR_APP_NAME.abr.ge",
"YOUR_APP_NAME.deeplink.page"
);
if (airbridgeHosts.contains(host)) {
return true;
}
}
return false;
}
};
With the steps above, you can now detect when an Airbridge tracking link is loaded in a WebView. When a link is detected, use the Airbridge.click
function and return true
from webView#shouldOverrideUrlLoading
. This will have the Airbridge SDK open the tracking link instead of the WebView.
override fun shouldOverrideUrlLoading(
view: WebView?,
request: WebResourceRequest?
): Boolean {
request?.url?.let {
val airbridgeHosts = arrayOf(
"abr.ge",
"YOUR_APP_NAME.abr.ge",
"YOUR_APP_NAME.deeplink.page"
)
if (airbridgeHosts.contains(it.host)) {
decisionHandler(it)
return true
}
}
return false
}
private fun decisionHandler(uri : Uri) {
Airbridge.click(uri.toString())
}
private final WebViewClient webViewClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Uri uri = request == null ? null : request.getUrl();
if (uri != null) {
String host = uri.getHost();
List<String> airbridgeHosts = Arrays.asList(
"abr.ge",
"YOUR_APP_NAME.abr.ge",
"YOUR_APP_NAME.deeplink.page"
);
if (airbridgeHosts.contains(host)) {
decisionHandler(uri)
return true;
}
}
return false;
}
};
private void decisionHandler(Uri uri) {
Airbridge.click(uri.toString());
}
The implementation is now complete. Below is the full code used in this guide.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout....)
initWebView()
}
private fun initWebView() {
webView.settings.javaScriptEnabled = true
webView.settings.domStorageEnabled = true
webView.webViewClient = webViewClient
}
private val webViewClient = object : WebViewClient() {
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun shouldOverrideUrlLoading(
view: WebView?,
request: WebResourceRequest?
): Boolean {
request?.url?.let {
val airbridgeHosts = arrayOf(
"abr.ge",
"YOUR_APP_NAME.abr.ge",
"YOUR_APP_NAME.deeplink.page"
)
if (airbridgeHosts.contains(it.host)) {
decisionHandler(it)
return true
}
}
return false
}
private fun decisionHandler(uri: Uri) {
Airbridge.click(uri.toString())
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout....);
webView = findViewById(R.id....);
initWebView();
}
private void initWebView() {
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(webViewClient);
}
private final WebViewClient webViewClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Uri uri = request == null ? null : request.getUrl();
if (uri != null) {
String host = uri.getHost();
List<String> airbridgeHosts = Arrays.asList(
"abr.ge",
"YOUR_APP_NAME.abr.ge",
"YOUR_APP_NAME.deeplink.page"
);
if (airbridgeHosts.contains(host)) {
decisionHandler(uri)
return true;
}
}
return false;
}
};
private void decisionHandler(Uri uri) {
Airbridge.click(uri.toString());
}
Was this helpful?