Links
Enable and track Android App Links and iOS Universal Links in your app using the MAUI SDK
Android App Links and iOS Universal Links allow the links you send through Engagement to open directly in your mobile application without any redirects that would hinder your users' experience.
For details on how App Links and Universal Links work and how they can improve your users' experience, refer to the Universal Links section in the Campaigns documentation.
This page describes the steps required to support and track incoming App Links and Universal Links in your app using the Maui SDK.
Android
Enable Android App Links
To enable your app to handle App Links, you must add an intent filter to your Android manifest and host a Digital Asset Link JSON file on your domain.
Refer to Android app links in the MAUI documentation for details.
Add an intent filter to Android manifest
Since the AndroidManifest.xml
file is auto-generated in Maui, you must make these changes in your MainActivity
instead.
It's important to set AutoVerify = true
so that the Android system can check your Digital Asset Link JSON and automatically handle App Links.
Example:
[Activity(Label = "MauiExample"]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "https",
DataHost = "www.your-domain.name",
DataPathPattern = "/yourpath/.*",
AutoVerify = true
)]
public class MainActivity : MauiAppCompatActivity
...
Add Digital Asset Links JSON to your domain
Refer to Verify App Links in the official Google documentation for detailed instructions.
The resulting file should be hosted at https://your-domain.name/.well-known/assetlinks.json
.
Example:
[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "your.package.name",
"sha256_cert_fingerprints":["SHA256 fingerprint of your app’s signing certificate"]
}
}]
To get the SHA256 certificate fingerprint, you can use
keytool -list -v -keystore my-release-key.keystore
.
Track Android App Links
The SDK can automatically decide whether the Intent that opened your application is an App Link. All you need to do is call Bloomreach.BloomreachSDK.HandleCampaignClick(new Uri(campaignUrl))
.
To track session events with App Link parameters, call HandleCampaignClick
before your Activity
's onResume
method is called. Ideally, make the call in your MainActivity
's OnCreate
method.
Example:
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var campaignUrl = Intent?.Data?.ToString();
if (campaignUrl != null)
{
Bloomreach.BloomreachSDK.HandleCampaignClick(new Uri(campaignUrl));
}
}
}
iOS
Enable Universal Links
To support universal links in your app, you must create a two-way association between your app and your website and specify the URLs that your app handles.
Follow the instructions in Apple universal links in the MAUI documentation.
- Ensure you have added the Associated Domains Entitlement to your app, for example:
applinks:example.com webcredentials:example.com
- Ensure you have set up the
apple-app-site-association
file on your website and that it lists the app identifiers for your domain in theapplinks
service. For example:
The file must be available on a URL matching the following format.{ "applinks": { "apps": [], "details": [ { "appID": "ABCDE12345.com.example.ExampleApp", "paths": [ "/engagement/*", "/*" ] } ] } }
https://<fully qualified domain>/.well-known/apple-app-site-association
Once the above items are in place, opening universal links should open your app.
The easiest way to test the integration is to send yourself an email containing a universal link and open it in your email client in a web browser. Universal links work correctly when a user taps or clicks a link to a different domain. Copy-pasting the URL into Safari doesn't work, neither does following a link to the current domain, or opening the URL with Javascript.
Track Universal Links
When the system opens your app after a user taps or clicks on a universal link, your app receives an NSUserActivity
object with an activityType
value of NSUserActivityTypeBrowsingWeb
. You must update your app delegate to respond and track the link to the Engagement platform when it receives the NSUserActivity
object.
The activity object’s webpageURL
property contains the URL you need to pass on to the SDK’s HandleCampaignClick
method.
The code example below shows how to respond to a universal link and track it:
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
{
var campaignUrl = userActivity.WebPageUrl?.ToString();
if (userActivity.ActivityType == "NSUserActivityTypeBrowsingWeb" && campaignUrl != null)
{
BloomreachSDK.HandleCampaignClick(new Uri(campaignUrl));
return userActivity.WebPageUrl.Host == "yourdomain.com";
}
return false;
}
public override bool OpenUrl(UIApplication application, NSUrl url, NSDictionary options)
{
BloomreachSDK.HandleCampaignClick(url);
return url.Host == "yourdomain.com";
}
When an iOS app is opened from a Universal Link, you can override the ContinueUserActivity
in AppDelegate.cs
to get the URL passed. From here, you can move around in your app as needed.
If your app is not running, the OpenUrl
method will be called instead.
The SDK might not be initialized when
HandleCampaignClick
is called. In this case, the event will be sent to Bloomreach servers after the SDK is initialized.
Updated 2 months ago