Skip to main content

Email Links

Links in Positive User emails are tracked redirect links on your workspace domain, https://<your-workspace>.user.com/emails/c/<token>/?to=<encoded target>. With the setup below, Android opens your app for these links instead of the browser, and the SDK counts the click and gives you the target the email links to. How email links work on all platforms: Opening App Screens.


Requirements​

  • SDK 2.0.0 or later.
  • Your app's package name and the SHA-256 fingerprints of your app signing certificates. If you use Play App Signing, take the fingerprint of the app signing key from Play Console.

Setup​

  1. Send your app details to Positive User. Send the package name and the SHA-256 fingerprints to Positive User support or your Customer Success Manager. Positive User publishes https://<your-workspace>.user.com/.well-known/assetlinks.json for your app.

  2. Declare the domain in your app. Add an intent filter with android:autoVerify="true" to the activity that should open, usually your launcher activity:

    <intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data
    android:scheme="https"
    android:host="your-workspace.user.com"
    android:pathPrefix="/emails/c/" />
    </intent-filter>

    The pathPrefix keeps unsubscribe links and all other pages of the domain in the browser, so recipients can always unsubscribe.

  3. Pass the link to the SDK. In onCreate and onNewIntent of that activity, pass the URI of a VIEW intent to handleEmailLink, then open the target:

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) handleLink(intent)
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
handleLink(intent)
}

private fun handleLink(intent: Intent) {
val uri = intent.data ?: return
if (intent.action != Intent.ACTION_VIEW) return
lifecycleScope.launch {
val target = UserCom.default?.handleEmailLink(uri)
if (target != null) {
// a screen of your app, or the browser with the target
} else {
// not a link from a Positive User email
}
}
}
Check

https://<your-workspace>.user.com/.well-known/assetlinks.json opens in a browser without a redirect and lists your package name. After installing the app on Android 12 or later, adb shell pm get-app-links <your.package> shows your workspace domain as verified. Then send a test email to yourself and tap a link on a device with the app installed: the app opens on the expected screen, and the click appears in the email campaign statistics.


Handling​

  • For a link that is not from a Positive User email of your workspace, the SDK returns null without a request. Handle that link as usual.
  • Never open the tracking link itself in the browser: that counts a second click. Open the target instead.
  • Without a connection the target still comes from the to parameter of the link. Only the click is lost, and the error goes to UserCom.errorHandler. The SDK waits at most 3 seconds and does not retry the click.
  • The target is returned unchanged, with all its query parameters. One of them, __ca__chat, lets the chat widget on your website recognize the contact when you open the target in the browser. Ignore the parameters you do not use when you route the target in your app.
  • It works before the first ping and after logout.

Which contact gets the click​

The click is recorded on the contact the email was sent to, recognized by the token in the link. It does not depend on the contact in the app, for example an anonymous contact after logout. The SDK does not switch the app to the email's contact, and __ca__chat in the target does not change the identity in the app. This is deliberate: a forwarded email cannot take over someone else's contact.

To keep email clicks and app activity on one contact, call updateContact at login with the same userId the contact has in Positive User.

Domain verification​

Android verifies the domain when the app is installed or updated. If verification fails, for example because assetlinks.json was published later, links open in the browser or in a chooser. Android checks again after the next app update, or you can trigger it on a test device with adb shell pm verify-app-links --re-verify <your.package>.


Methods​

Counts the click on a link from a Positive User email that opened the app, and returns the target of the link. Available with a callback and as a suspend function.

Optional unless marked required

urlUrirequired
The URI that opened the app, intent.data.
callbackEmailLinkCallbackYes, in the callback form
onResult(target: Uri?), called on the main thread.

Returns, or passes to the callback, the target Uri, or null for a link that is not from a Positive User email of your workspace. A click that could not be reported goes to UserCom.errorHandler, never to the result.

// callback form
UserCom.default?.handleEmailLink(uri) { target ->
open(target ?: uri)
}

// suspend form, inside a coroutine
val target: Uri? = UserCom.default?.handleEmailLink(uri)

Common errors​

SymptomCauseFix
The link opens in the browser, not in the appThe domain is not verified: assetlinks.json is missing, lists another fingerprint, or answers with a redirect, or the intent filter has no android:autoVerify="true".Check assetlinks.json and adb shell pm get-app-links <your.package>. With Play App Signing, use the fingerprint of the app signing key from Play Console.
The app opens, but the click is not in the campaign statisticsThe app does not call handleEmailLink, or the device was offline.Call handleEmailLink for every VIEW intent. Offline clicks are lost and reported to UserCom.errorHandler.
Clicks are counted twiceThe app opens the tracking link in the browser after handleEmailLink.Open the target returned by the SDK.
handleEmailLink returns null for an email linkThe link is from another workspace than the baseUrl passed to initialize.Use the same workspace domain in initialize and in the intent filter.