Skip to content

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 places are in the same space, such as <link base>/messages/tickets/<id>. The SDK reads the link base as it starts (crm.publicApp.value?.linkBase); the setup check’s Link host row shows it.

The SDK decides whether a link is PurrCRM‘s, records it, and asks PurrCRM about saved links. What a link opens is drawn by you: one of PurrCRM‘s places through your navigate hook, or one of yours through followable and openInApp (Initialise).

On Links › Setup (an owner or admin), in the Link domain card:

  • Name: your app’s part of PurrCRM‘s host (northwind), or Host of its own (optional). 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: one a line, <Apple team id>.<bundle id>, such as ABCDE12345.com.northwind.app. The team id is in your Apple developer account, under Membership; the bundle id is your target’s Bundle Identifier in Xcode (General). List each app that opens the links, such as a staging build with its own bundle id.
  • Keep links through an iPhone’s install, once the app reads them (see Links through an install).
  • Let the app make links for its users to share, if it does (Links your users share).

Press Turn links on (or Save). PurrCRM then serves the file iPhones read to trust your app with the links, /.well-known/apple-app-site-association. Check what phones read fetches it as a phone does.

In your target’s Signing & Capabilities, add Associated Domains, with your link host. The In the app card on Links › Setup shows the entry, filled in; it names the Flutter target’s Runner.entitlements, and in your app it goes in your own target’s .entitlements file:

Northwind.entitlements
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:crm.example.com</string>
</array>

Use your link host: PurrCRM‘s host, or your own. 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 rather than from Apple’s cache. Associated Domains needs a paid Apple team.

Before your own handling, give the SDK 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 a scene delegate:

SceneDelegate.swift
func scene(
_ scene: UIScene, willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
// … your window …
// A link that launched the app.
for activity in connectionOptions.userActivities { open(activity) }
}
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
open(userActivity)
}
private func open(_ activity: NSUserActivity) {
guard activity.activityType == NSUserActivityTypeBrowsingWeb,
let url = activity.webpageURL
else { return }
Task {
if await crm.handleLink(url) { return }
// Your own links (a product, a referral…), as before.
}
}

An app without scenes gets them in its app delegate, application(_:continue:restorationHandler:), and does the same with userActivity.webpageURL. With the SwiftUI app life cycle (iOS 14), .onOpenURL { url in Task { await crm.handleLink(url) } } receives Universal Links too.

handleLink also takes a link as text: a QR code your app scans, for example. On a cold start, before PurrCRM has answered with your link base, it waits up to 3 seconds for it, since only that says whether a host of your own is PurrCRM‘s.

What happens to a link of PurrCRM‘s:

  • An email’s link the app opened counts as the email’s click.
  • Every link is recorded as a link_opened event (link, from, and saved for a saved link) for segments and goals.
  • One of PurrCRM‘s places (/messages/<id>, /help/<slug>…) opens through navigate; a link to an in-app message (/messages/show/<id>) shows that message; any other path goes to followable, then openInApp.

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.

A saved link may carry data for the app (a coupon, a referrer). Hear of it, and of every link, before it is followed:

crm.host.linkOpened = { link in
if let coupon = link.data["coupon"] { Wallet.shared.offer(coupon) }
}

CrmLinkContext has path, from (link, email or deferred), saved, data, campaign and channel; the last four 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.

A link tapped on an iPhone without the app sends it to the App Store. iOS hands an app nothing from the App Store, so the link’s one-time claim travels on the clipboard:

  1. 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 (crm-claim:…) before opening the App Store.

  2. In the app, turn it on as well:

    CrmHost(deferredLinksFromClipboard: true)

On the first run, the SDK asks iOS whether there is text on the clipboard (hasStrings, which asks the user nothing), and reads it only if there is: iOS then asks the user to allow the paste. It takes nothing but PurrCRM‘s claim, and once the claim is kept takes it off the clipboard, only if nothing was copied since: what the user copied is left alone. The app 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.

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 still made (so the install is counted) but not followed. A first run the user leaves before signing in keeps the claim on the phone, and a later start makes it while it is still valid.

The first run is the first start with none of the SDK’s data in UserDefaults, which is not always a fresh install:

  • A reinstall is a first run: deleting the app deletes its data.
  • A phone restored from a backup brings the app’s data back, so it is not a first run.
  • The first update that adds the SDK is a first run for every user who already had the app. With deferredLinksFromClipboard on, iOS asks those with text on their clipboard to allow the paste, once. Turn it on in a later release if you would rather not ask them.

CrmHost.installReferrer is Android’s way to the same claim; an iOS app leaves it out.

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:

if let link = await crm.createLink(
"/recipes/42", data: ["shared_by": user.id], channel: "messages")
{
let share = UIActivityViewController(activityItems: [link.shortUrl], applicationActivities: nil)
present(share, animated: true)
}

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 nil 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.

With a referral programme on Links › Referrals, every user has a link of their own to invite others:

if let link = await crm.referralLink() {
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 nil when nobody is signed in or the app has no programme.

Declare the places a link may go, so your team picks them in PurrCRM‘s link picker instead of typing paths:

CrmHost(
followable: { path in
path.hasPrefix("/offers") || path == "/wallet" ? path : nil
},
openInApp: { location in AppRouter.open(location) },
links: [
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 SDK sends the list when PurrCRM asks for it, once a run for each change, and your team finds it under Links › Destinations. Declaring a place opens nothing: followable still decides.

Call crm.screen("wallet") as each screen shows (the same name every time; never a path or an id), in viewDidAppear or SwiftUI’s onAppear. Your team can then show an in-app message only on some screens (In-app messages).

The setup check’s Links rows fetch the apple-app-site-association file and say whether it names your bundle id, and, in a development build, whether your Associated Domains entitlement has the link host. Its Test links button opens a link of PurrCRM‘s through the SDK, through iOS as a Universal Link, or shares it, so you can tap it from another app (The setup check).