Links
A link to a place in your app opens the app on a phone that has it, and a web page or the store on one that does not: from an email, a QR code on a table, a text message. Each app has its own links, and its test app its own again.
What you draw: nothing for the link itself. The SDK reads it and takes the user to the place it names, through your hooks: one of PurrCRM‘s pages through navigate, a place in your app through followable and openInApp. Your screens are what opens. For links your users share, you draw the button and call Android’s share sheet.
A link is your app’s path under its link base:
- on PurrCRM‘s own host:
https://app.purrcrm.com/l/<your app's link name>/<path>; or - on a host of your own, such as
https://go.northwind.example/<path>, whose DNS points at PurrCRM.
/offers/42 in your app is then <link base>/offers/42. PurrCRM‘s own pages are in the same space, such as <link base>/messages/tickets/<id>.
1. Settings
Section titled “1. Settings”On Links › Setup, in the Link domain card (an owner or admin):
- Name: your app’s part of PurrCRM‘s host (
northwind), and Host of its own (optional). A host of your own needs a DNS record (a CNAME to PurrCRM‘s host). - Android package: your
applicationId. - Android signing SHA-256: one a line, the SHA-256 fingerprint of every certificate your app is signed with. Android opens a link in the app only when the certificate of the build installed is listed.
- Press Turn links on, or Save.
Which fingerprints to list:
-
The app signing key, which Google Play signs what it delivers with: Play Console › Test and release › App integrity › App signing.
-
Your upload key, if you install builds signed with it (internal tests outside Play):
keytool -list -v -keystore upload.jks -alias upload. -
Your debug key, to try links on your own phone from Android Studio:
Terminal window keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass androidor
./gradlew signingReport, which prints each variant’sSHA-256.
The setup check shows the fingerprint of the build on the phone, and says when it is not listed.
PurrCRM then serves the file Android reads to trust your app with the links, /.well-known/assetlinks.json on the link host. Check what phones read fetches it as a phone does. The In the app card shows the intent filter below, filled in for your app.
2. The intent filter
Section titled “2. The intent filter”In the Activity that opens links, add an intent filter with android:autoVerify="true", so that Android checks your link host’s assetlinks.json when the app is installed and opens the links in your app without asking:
<activity android:name=".HomeActivity" android:exported="true" android:launchMode="singleTop"> <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="crm.example.com" android:pathPrefix="/l/northwind/" /> </intent-filter></activity>Use your PurrCRM host as android:host, with your link name in pathPrefix (or your own host, with no pathPrefix). singleTop (or singleTask) brings a link to the Activity already open, through onNewIntent.
To see what Android made of it on Android 12 and later:
adb shell pm verify-app-links --re-verify com.northwind.appadb shell pm get-app-links com.northwind.app # "verified" beside your hostAndroid verifies at install. A host that answers late, or a fingerprint missing from the settings, leaves links opening in the browser until the next install or re-verify.
3. Hand the SDK every link
Section titled “3. Hand the SDK every link”Before your own handling, give the SDK every link the phone hands you, in onCreate and onNewIntent. handleLink answers whether the link was PurrCRM‘s; it then goes where it names once a user is signed in and you have called setReady(true), as a tapped push does.
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (savedInstanceState == null) openLink(intent)}
override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) openLink(intent)}
private fun openLink(intent: Intent) { val link = intent.data ?: return lifecycleScope.launch { if (crm.handleLink(link)) return@launch // Your own links (a product, a referral...), as before. }}handleLink is a suspend call. On the very first start, before PurrCRM has ever told the SDK your link domain, it waits up to 3 seconds for it, since a link on your own host can only be recognised by it. Where you cannot suspend, crm.handleLinkNow(link.toString()) answers at once with what the SDK knows, so on that very first start a link on your own host is not recognised.
The SDK reads the link as it was written (its escapes kept), counts an email’s click when the link came from one, and records link_opened for segments and goals.
Saved links
Section titled “Saved links”Links your team saves in Links (a campaign, a QR code on a table) open the app the same way, with nothing more to do: handleLink takes the saved link’s short form (…/go/summer24) and its full form (…/offers/42?crm_l=summer24), asks PurrCRM where the short form goes, and records which saved link it was on link_opened.
A saved link may carry data for the app (a coupon, a referrer). Hear of it, and of every link, before it is followed:
CrmHost( linkOpened = { link -> link.data["coupon"]?.let { wallet.offer(it) } }, // navigate, followable, openInApp…)CrmLinkContext has the path it goes to (with its query), from (link, email, or deferred for a link through an install), and the saved link’s saved slug, data, campaign and channel, all empty for a link nobody saved. A short form PurrCRM does not know (archived, expired or never saved) opens nothing; a full form still opens its own path, without data.
Links through an install
Section titled “Links through an install”A link tapped on a phone without the app sends it to Google Play, with a one-time claim in the install referrer. With the hook below, the app’s first run then opens where the link went, saved link, data and all, once a user is signed in and ready. link.from is deferred, and PurrCRM records the install on the user as installed_from_link. There is no fingerprinting: the claim is kept for a day, and only the app that installed from it can make it.
Add Play’s Install Referrer library (the SDK takes no dependency on it):
dependencies { implementation("com.android.installreferrer:installreferrer:<version>")}and read the referrer in CrmHost.installReferrer, in the host you pass when you make the Crm:
host = CrmHost( installReferrer = { suspendCancellableCoroutine { done -> val client = InstallReferrerClient.newBuilder(this).build() client.startConnection(object : InstallReferrerStateListener { override fun onInstallReferrerSetupFinished(code: Int) { val referrer = if (code == InstallReferrerClient.InstallReferrerResponse.OK) { client.installReferrer.installReferrer } else { null } client.endConnection() if (done.isActive) done.resume(referrer) }
override fun onInstallReferrerServiceDisconnected() { if (done.isActive) done.resume(null) } }) } }, // navigate, linkOpened, followable, openInApp…)The SDK asks it once, on the first run, as start() runs, and waits 5 seconds at most (a hook given later through crm.host is not asked, and the setup check says so); a referrer that does not answer in time is asked again at the next start. A link the user opens during the first run goes ahead of the claim, which is then dropped. A first run the user leaves before signing in keeps the claim on the phone, and a later start makes it while the claim is still valid.
The first run is the first start with none of the SDK’s data on the phone, which is not always a fresh install. A reinstall brings the app’s data back when Android’s Auto Backup is on (android:allowBackup, on by default), so it is not a first run and its link is not claimed. To keep deferred links on reinstalls, leave the SDK’s preferences file out of the backup, in both rule files:
<full-backup-content> <exclude domain="sharedpref" path="crm.crm.xml" /></full-backup-content><data-extraction-rules> <cloud-backup> <exclude domain="sharedpref" path="crm.crm.xml" /> </cloud-backup> <device-transfer> <exclude domain="sharedpref" path="crm.crm.xml" /> </device-transfer></data-extraction-rules>named in the manifest as android:fullBackupContent="@xml/backup_rules" and android:dataExtractionRules="@xml/data_extraction_rules". The file is <storagePrefix>.crm.xml: crm.crm.xml unless you set CrmConfig.storagePrefix.
Links your users share
Section titled “Links your users share”Let your users share a place in the app with a link of their own: a recipe, an offer, a profile. Turn on Let the app make links for its users to share on Links › Setup, then:
lifecycleScope.launch { val link = crm.createLink( "/recipes/42", data = mapOf("shared_by" to user.id), channel = "whatsapp", ) ?: return@launch val send = Intent(Intent.ACTION_SEND) .setType("text/plain") .putExtra(Intent.EXTRA_TEXT, link.shortUrl) startActivity(Intent.createChooser(send, null))}shortUrl is the one to share (<link base>/go/<slug>); the CrmSharedLink also has its slug and its full url. Whoever opens it gets the app at the path, data (at most 10 keys) and all, through an install too; its clicks, opens and installs are counted under Links, under Made by: Users, sharing. createLink answers null when nobody is signed in, the app does not let its users make links, the user has made 50 today, or there is no connection.
Referrals
Section titled “Referrals”With a referral programme on Links › Referrals, every user has a link of their own to invite others:
val link = crm.referralLink() // CrmReferralLink: slug, shortUrl, urlif (link != null) share("Join me: ${link.shortUrl}")It is the same link every time. A user new to the app who arrives by it, opening it in the app or installing from it, is credited to who shared it: referred on them, referral_joined on the referrer. When they do the programme’s reward event within its window, the referrer gets referral_converted, which a workflow can reward. referralLink answers null when nobody is signed in, the app has no programme, or PurrCRM could not be asked.
4. Declare your places
Section titled “4. Declare your places”Declare the places a link may go, so your team picks them in PurrCRM‘s link picker instead of typing paths:
CrmHost( followable = { link -> if (link.startsWith("/offers") || link == "/wallet") link else null }, openInApp = { location -> router.open(location) }, links = listOf( CrmLink(name = "Offer page", path = "/offers/{offer_id}", screen = "offer"), CrmLink(name = "All offers", path = "/offers?category={category}"), CrmLink(name = "Wallet", path = "/wallet", screen = "wallet"), ), // navigate…)A part in braces is filled in by whoever writes the link: a value, or an attribute such as {{first_name}}. webUrl is the place’s page on the web, and screen its name as you tell it to crm.screen. The app sends the list once per build, when a check-in asks for it, and your team finds it under Links › Destinations. Declaring a place opens nothing: followable still decides.
5. Name your screens
Section titled “5. Name your screens”Call crm.screen("wallet") as each screen shows (the same name every time; never a path or an id). Your team can then show an in-app message only on some screens (In-app messages).
On a laptop
Section titled “On a laptop”App Links need https, so a PurrCRM on your laptop cannot serve them, and the setup check skips that row. handleLink takes an http link only when your apiBase is http too, so you can still hand it links yourself: the setup check’s Test links makes one and hands it in with Open here.