Links
A link to a place in your app opens the app on a phone that has it, and a web page or the app 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.
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>, which needs nothing but the settings below; 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 (an owner or admin):
- Name: your app’s part of PurrCRM‘s host (
northwind), or a host of its own. A host of your own needs a DNS record (a CNAME to PurrCRM‘s host); PurrCRM then sets up the host and its certificate. Check what phones read shows when it is ready. - iOS apps:
<Apple team id>.<bundle id>, such asABCDE12345.com.northwind.app. - Android package and Android signing SHA-256: your
applicationId, and the SHA-256 of every certificate the app is signed with (from Play Console › App integrity, plus your upload and debug keys:keytool -list -v -keystore <file>). - Optionally a web page for a phone without the app (
{path}in it is the link’s path), and your App Store and Google Play pages. Without them, a phone without the app gets a page in your brand with “Open in Northwind” and the stores. - Use these links in emails, once most phones run a build with step 2.
- Keep links through an iPhone’s install, once the app reads them (see Links through an install).
PurrCRM then serves the files phones read to trust your app with the links (/.well-known/apple-app-site-association and /.well-known/assetlinks.json). Check what phones read fetches both as a phone does. The tab also shows the snippets below, filled in for your app.
2. In the app
Section titled “2. In the app”Android, in the activity that opens links (AndroidManifest.xml):
<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>Use your PurrCRM host as android:host (or your own host, with no pathPrefix). On iOS, add the Associated Domains capability (Runner.entitlements):
<key>com.apple.developer.associated-domains</key><array> <string>applinks:crm.example.com</string></array>A debug build may write applinks:crm.example.com?mode=developer, with developer mode on in the phone’s settings, so iOS reads the file afresh. Associated Domains needs a paid Apple team.
3. Hand the facade every link
Section titled “3. Hand the facade every link”Before your own handling, give the facade every link the phone hands you. handleLink answers whether the link was PurrCRM‘s; it then goes where it names once a user is signed in and ready, as a tapped push does. With the app_links package:
final appLinks = AppLinks();
Future<void> openLink(Uri link) async { if (await crm.handleLink(link)) return; // Your own links (a product, a referral...), as before.}
final initial = await appLinks.getInitialLink();if (initial != null) unawaited(openLink(initial));appLinks.uriLinkStream.listen(openLink);An email’s link the app opened counts as the email’s click, and every link is recorded as a link_opened event 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 (saved), so a segment or a workflow can ask for it.
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) { final coupon = link.data['coupon']; if (coupon != null) wallet.offer(coupon); }, // followable, openInApp…)link.saved, link.campaign and link.channel say which saved link it was; all are 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 the store. With the parts 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 link leaves a one-time claim, kept for a day, which only the app that installed from it can make.
Android. The link sends the phone to Google Play with the claim in its install referrer. Read the referrer with a plugin, such as play_install_referrer, and hand it in:
CrmHost( installReferrer: () async => Platform.isAndroid ? (await PlayInstallReferrer.installReferrer).installReferrer : null, // linkOpened, followable, openInApp…)It is read only on the first run after an install.
iPhone. iOS hands an app nothing from the App Store, so the claim travels on the clipboard. Turn on Keep links through an iPhone’s install on Links › Setup: a link then shows your landing page, whose Get the app copies the claim before opening the App Store. In the app, turn it on as well:
CrmHost(deferredLinksFromClipboard: true)On the first run the app reads the clipboard once, and only if something is on it. iOS asks the user to allow the paste. The app takes nothing but PurrCRM‘s claim, and clears it from the clipboard. Leave both off if you would rather not ask: an iPhone then opens the app at its start after an install, as before.
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 on Android 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 (FlutterSharedPreferences.xml, shared with your app’s ownshared_preferences) out of the backup in your backup rules, or turn backup off. - The first update that adds the SDK is a first run for every user who already had the app. With
deferredLinksFromClipboardon, iOS asks those with something on their clipboard to allow the paste, once. Turn it on in a later release if you would rather not ask them.
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:
final link = await crm.createLink( '/recipes/42', data: {'shared_by': user.id}, channel: 'whatsapp',);if (link != null) Share.share(link.shortUrl);shortUrl is the one to share (<link base>/go/<slug>). Whoever opens it gets the app at the path, data 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:
final link = await crm.referralLink();if (link != null) Share.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 or the app has no programme.
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) => link.startsWith('/offers') || link == '/wallet' ? link : null, openInApp: router.go, links: const [ 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'), ],)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. The app sends the list once per build, 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. With go_router:
router.routerDelegate.addListener(() { final name = screenNameOf(router.routerDelegate.currentConfiguration.uri.path); if (name != null) crm.screen(name);});