@straitlink/capacitor 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Package.swift CHANGED
@@ -10,7 +10,7 @@ let package = Package(
10
10
  ],
11
11
  dependencies: [
12
12
  .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
13
- .package(url: "https://github.com/strait-link/strait-sdk-swift.git", from: "0.9.4"),
13
+ .package(url: "https://github.com/strait-link/strait-sdk-swift.git", from: "0.11.0"), // setEnabled + F7 + B6a/B13a/C1 (StraitSDK 0.11.0)
14
14
  ],
15
15
  targets: [
16
16
  .target(
package/README.md CHANGED
@@ -33,12 +33,23 @@ link-open analytics. It wraps the Strait [Android](https://github.com/strait-lin
33
33
  and [iOS](https://github.com/strait-link/strait-sdk-swift) SDKs, and its API matches
34
34
  [`@straitlink/react-native`](https://github.com/strait-link/strait-sdk-react-native).
35
35
 
36
+ ## Guided setup
37
+
38
+ There's no `strait init` for Capacitor yet: the three steps below are the whole setup. Or let your AI coding tool do it: connect the [Strait MCP server](https://straitlink.in/docs/mcp/) and run its `get_started` prompt with platform `capacitor`; it pastes the exact setup from the docs. Then check that your link domain lists your app:
39
+
40
+ ```sh
41
+ npx @straitlink/cli doctor --host <your-handle>.strait.link --android <your.package> --ios <your.bundle.id>
42
+ ```
43
+
36
44
  ## Quick start (60 seconds)
37
45
 
38
46
  You need: a Capacitor 8 app with `android/` and/or `ios/` added, and from
39
47
  **Dashboard → Get started** your publishable key (`st_pub_live_…`) and link domain
40
48
  (`https://<your-handle>.strait.link`).
41
49
 
50
+ Android builds of a Capacitor 8 app need JDK 21 (Capacitor's own requirement; with JDK 17 the
51
+ Gradle build fails). Android Studio's bundled JDK is 21; on the command line check `java -version`.
52
+
42
53
  **1. Install and sync**
43
54
 
44
55
  ```sh
@@ -105,6 +116,11 @@ for (const f of report.findings) console.log(f.severity, f.id, f.title, f.fix);
105
116
  `error` comes with the fix, for example `cert.missing`: "Add AB:CD:… in Dashboard → Apps & stores.
106
117
  Debug, release and Play App Signing keys each have their own fingerprint."
107
118
 
119
+ ## User consent / opt-out
120
+
121
+ If your app asks for consent first (for example under India's DPDP Act or a GDPR consent flow in the EU), call `await strait.setEnabled(false)` until the person agrees: Strait then sends no open reports or events, does no install matching, and deletes reports waiting on the device. The choice is kept across launches on the phone; `setEnabled(true)` turns it back on (default: on) and `isEnabled()` reads it. It works before `start()`, so a first-launch consent screen can call it first; `setEnabled(true)` then runs the deferred check.
122
+ Links that carry their own destination still open your screens. A Strait short link is looked up through the engine's `/v1/lookup`, which records nothing (no tap, no open, no tap id), so it still opens the right screen; only if that lookup fails (offline) does it come back `matched: false, reason: 'disabled'`. Whether you need consent, and for what, is a question for your own legal advice.
123
+
108
124
  ## Platform features
109
125
 
110
126
  | Feature | Status | Notes |
@@ -128,10 +144,11 @@ Debug, release and Play App Signing keys each have their own fingerprint."
128
144
  | `onLink(cb)` | Every link event, including ones from before you subscribed. Returns an unsubscribe. |
129
145
  | `onLinkStart(cb)` | A link just arrived and is being resolved: show a loading state. |
130
146
  | `checkDeferred()` | Asks for the deferred link again (settings or debug screens). Doesn't add an install. |
131
- | `trackEvent(name, { value, currency, linkId, clickId })` | Conversion or revenue event, placed on the tap of the last attributed open (7 days). Resolves `true` when accepted. |
132
- | `pendingOpenReports()` / `flushOpenReports()` | Open reports saved while offline (sent again on start and resume). |
147
+ | `trackEvent(name, { value, currency, linkId, clickId, eventId })` | Conversion or revenue event, placed on the tap of the last attributed open (7 days). `eventId` = your order id, stored once (left out, the SDK makes one). Resolves `true` when accepted; an event that can't be sent (offline, server busy) is kept and sent later with the open reports. Revenue you must trust: send it from your server with the secret key (the publishable key is public). |
148
+ | `pendingOpenReports()` / `flushOpenReports()` | Open reports saved while offline (sent again on start and resume). After a 429/5xx the queue waits (15 s up to 1 h, at least the server's `Retry-After`) before sending again. |
133
149
  | `deviceClass()` | `phone` or `tablet` (iPad / 600 dp and up), as sent with open reports. |
134
150
  | `openStoreSheet(url, options?)` | The app store inside your app for one of your links (another app to install), deep link kept through the install. Options: `androidPackage`, `listing`, `inline`, `appStoreId`, `providerToken`, `customProductPageId`, `style`. Resolves `{ opened, method, clickId, linkId, referrer, reason }`. |
151
+ | `setEnabled(enabled)` / `isEnabled()` | Opt-out switch for consent flows (see above). Kept on the phone; works before `start()`. |
135
152
  | `doctor()` | Setup check for debug builds (key, endpoint, this app listed in your link domain's files, Android signing certificate). Resolves `{ ok, findings }`. |
136
153
  | `stop()` | Stops delivering events to this object. |
137
154
 
@@ -145,13 +162,18 @@ The plugin is a thin layer. All link logic (resolving short links, the once-per-
145
162
  check, open reports and their retry queue, app-state labels) runs in the native SDKs, which share
146
163
  golden test vectors with the Strait engine:
147
164
 
148
- - **Android:** `strait-sdk-android` **v0.8.3** from JitPack. The plugin adds JitPack to your Gradle
165
+ - **Android:** `strait-sdk-android` **v0.10.0** from JitPack (the version is pinned in `android/build.gradle`). The plugin adds JitPack to your Gradle
149
166
  repositories, limited to the `com.github.strait-link` group, so nothing else is ever fetched from
150
167
  it. It reads the Play Install Referrer (`com.android.installreferrer:installreferrer:2.2`), the launch
151
168
  intent and `onNewIntent`, and keeps state in SharedPreferences (`strait`).
152
- - **iOS:** `StraitSDK` **0.9.4+** through Swift Package Manager. Links come from Capacitor's
169
+ - **iOS:** `StraitSDK` **0.11.0+** through Swift Package Manager (pinned in `Package.swift`). Links come from Capacitor's
153
170
  `capacitorOpenURL` / `capacitorOpenUniversalLink` notifications; state lives in `UserDefaults`.
154
171
 
172
+ **Reinstalls (contract B6a):** Android Auto Backup and restored iPhones bring the "deferred check
173
+ done" flag back after a reinstall. The plugin passes the app's install time to the native SDKs
174
+ (Android `firstInstallTime`; iOS a marker file kept out of backups), so a reinstall from a link still
175
+ gets its deferred link and is counted. An app update is never a new install. No app code needed.
176
+
155
177
  What gets recorded, the privacy details and the match methods are the same as the native SDKs:
156
178
  see [Android](https://github.com/strait-link/strait-sdk-android#what-strait-records-automatically-no-extra-code)
157
179
  and [iOS](https://github.com/strait-link/strait-sdk-swift#what-strait-records-automatically-no-extra-code).
@@ -168,6 +190,17 @@ adb shell am start -n <your.package>/.MainActivity \
168
190
 
169
191
  Take both values from the Play Store URL your link redirects an Android phone to (its `referrer=`).
170
192
 
193
+ ## Size and speed
194
+
195
+ Measured 25 Oct 2026 on 0.3.0.
196
+
197
+ | What | Size or time | How it was measured |
198
+ |---|---|---|
199
+ | npm package | 15.6 KB download, 50 KB unpacked (JS, plus the Android and iOS plugin sources) | `npm pack --dry-run` |
200
+ | In your web bundle | 1.5 KB minified, 0.8 KB gzip (`@capacitor/core` is yours already) | esbuild 0.25 `--bundle --minify` |
201
+ | Native | the Android SDK (about 35 KB of dex after R8) and the Swift SDK (about 280 KB of arm64 code before App Store compression); see their READMEs | measured in those repos |
202
+ | Start-up (JS side) | 3.0 ms to load the module with `@capacitor/core` + 0.07 ms for `createStrait(...)` | fresh Node 26 process, median of 25. The native side's start-up is in the Android and Swift READMEs |
203
+
171
204
  ## Sample app
172
205
 
173
206
  [`examples/capacitor-app`](examples/capacitor-app): a plain-JS Capacitor app with two screens
@@ -1,6 +1,6 @@
1
1
  // @straitlink/capacitor, Android side: a thin Capacitor plugin over strait-sdk-android (JitPack).
2
2
  ext {
3
- straitSdkVersion = 'v0.8.3'
3
+ straitSdkVersion = 'v0.10.0' // setEnabled + B6a/B13a/C1 (strait-sdk-android v0.10.0)
4
4
  }
5
5
 
6
6
  buildscript {
@@ -15,7 +15,7 @@ buildscript {
15
15
 
16
16
  apply plugin: 'com.android.library'
17
17
 
18
- // strait-sdk-android is built by JitPack from its version tags. Gradle resolves this plugin's
18
+ // strait-sdk-android is built by JitPack from its version tags (or, between releases, a main commit). Gradle resolves this plugin's
19
19
  // dependencies with the app's repositories, so add JitPack to every project, limited to the
20
20
  // Strait group (nothing else is ever fetched from JitPack).
21
21
  rootProject.allprojects {
@@ -57,10 +57,14 @@ import kotlin.Unit;
57
57
  */
58
58
  @CapacitorPlugin(name = "Strait")
59
59
  public class StraitPlugin extends Plugin {
60
+ /** strait-sdk-android's opt-out key in the "strait" preferences: "0" = off, absent = on. */
61
+ private static final String ENABLED_KEY = "strait.enabled";
60
62
  private final ExecutorService executor = Executors.newSingleThreadExecutor();
61
63
  private StraitClient client;
62
64
  /** A link that arrived (onNewIntent) before JS called start(). */
63
65
  private String pendingUrl;
66
+ /** setEnabled() before start(): applied to the client before it starts (which also clears saved reports). */
67
+ private Boolean pendingEnabled;
64
68
 
65
69
  @PluginMethod
66
70
  public synchronized void start(PluginCall call) {
@@ -81,7 +85,7 @@ public class StraitPlugin extends Plugin {
81
85
  if (h != null && !h.isEmpty()) hosts.add(h);
82
86
  }
83
87
  Context ctx = getContext().getApplicationContext();
84
- SharedPreferences prefs = ctx.getSharedPreferences("strait", Context.MODE_PRIVATE);
88
+ SharedPreferences prefs = prefs(ctx);
85
89
  KeyValueStore storage = new KeyValueStore() {
86
90
  @Override public String get(String k) { return prefs.getString(k, null); }
87
91
  @Override public void set(String k, String v) { prefs.edit().putString(k, v).apply(); }
@@ -99,8 +103,11 @@ public class StraitPlugin extends Plugin {
99
103
  new UrlConnectionTransport(10_000, 10_000),
100
104
  executor,
101
105
  System::currentTimeMillis,
102
- deviceClass(ctx)
106
+ deviceClass(ctx),
107
+ () -> installTime(ctx) // B6a: Auto Backup restores the flag; a new install time re-runs the check
103
108
  ));
109
+ if (pendingEnabled != null) client.setEnabled(pendingEnabled); // before anything is sent
110
+ pendingEnabled = null;
104
111
  client.onLinkStart(s -> { notifyListeners("linkStart", toJs(s), true); return Unit.INSTANCE; });
105
112
  client.onLink(e -> { notifyListeners("link", toJs(e), true); return Unit.INSTANCE; });
106
113
  client.onAppState(AppLifecycleState.ACTIVE, System.currentTimeMillis());
@@ -111,6 +118,44 @@ public class StraitPlugin extends Plugin {
111
118
  executor.execute(call::resolve); // after start's work on the same single thread
112
119
  }
113
120
 
121
+ /** Opt-out switch (consent): the native SDK's setEnabled. Before start() it is saved and applied at start. */
122
+ @PluginMethod
123
+ public synchronized void setEnabled(PluginCall call) {
124
+ Boolean on = call.getBoolean("enabled");
125
+ if (on == null) {
126
+ call.reject("Strait: setEnabled needs enabled (true or false)");
127
+ return;
128
+ }
129
+ if (client != null) {
130
+ client.setEnabled(on);
131
+ executor.execute(call::resolve); // after the SDK's clearing / re-run on the same single thread
132
+ return;
133
+ }
134
+ pendingEnabled = on;
135
+ prefs(getContext()).edit().putString(ENABLED_KEY, on ? "1" : "0").apply();
136
+ call.resolve();
137
+ }
138
+
139
+ @PluginMethod
140
+ public synchronized void isEnabled(PluginCall call) {
141
+ JSObject r = new JSObject();
142
+ r.put("enabled", client != null ? client.isEnabled() : !"0".equals(prefs(getContext()).getString(ENABLED_KEY, null)));
143
+ call.resolve(r);
144
+ }
145
+
146
+ private static SharedPreferences prefs(Context ctx) {
147
+ return ctx.getApplicationContext().getSharedPreferences("strait", Context.MODE_PRIVATE);
148
+ }
149
+
150
+ /** This install's time (PackageInfo.firstInstallTime, epoch ms), or null; contract B6a. */
151
+ private static Long installTime(Context ctx) {
152
+ try {
153
+ return ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).firstInstallTime;
154
+ } catch (Exception e) {
155
+ return null;
156
+ }
157
+ }
158
+
114
159
  @PluginMethod
115
160
  public void checkDeferred(PluginCall call) {
116
161
  StraitClient c = ready(call);
@@ -131,9 +176,10 @@ public class StraitPlugin extends Plugin {
131
176
  String currency = call.getString("currency");
132
177
  String linkId = call.getString("linkId");
133
178
  String clickId = call.getString("clickId");
179
+ String eventId = call.getString("eventId");
134
180
  executor.execute(() -> {
135
181
  JSObject r = new JSObject();
136
- r.put("accepted", c.trackEvent(name, value, currency, linkId, clickId));
182
+ r.put("accepted", c.trackEvent(name, value, currency, linkId, clickId, eventId));
137
183
  call.resolve(r);
138
184
  });
139
185
  }
package/dist/strait.d.ts CHANGED
@@ -86,6 +86,8 @@ export interface TrackEventExtra {
86
86
  currency?: string;
87
87
  linkId?: string;
88
88
  clickId?: string;
89
+ /** Your id for this conversion, e.g. the order id (1-64 of A-Z a-z 0-9 _ . : -). Stored once (B13a). */
90
+ eventId?: string;
89
91
  }
90
92
  /** The native side (Android: StraitPlugin.java over strait-sdk-android; iOS: StraitPlugin.swift over StraitSDK). */
91
93
  export interface StraitNativePlugin {
@@ -111,6 +113,12 @@ export interface StraitNativePlugin {
111
113
  openStoreSheet(options: {
112
114
  url: string;
113
115
  } & StoreSheetOptions): Promise<StoreSheetResult>;
116
+ setEnabled(options: {
117
+ enabled: boolean;
118
+ }): Promise<void>;
119
+ isEnabled(): Promise<{
120
+ enabled: boolean;
121
+ }>;
114
122
  addListener(event: 'link', cb: (e: LinkEvent) => void): Promise<PluginListenerHandle>;
115
123
  addListener(event: 'linkStart', cb: (s: LinkStart) => void): Promise<PluginListenerHandle>;
116
124
  }
@@ -142,6 +150,17 @@ export interface Strait {
142
150
  * want people to install), keeping the deep link through the install. Never throws.
143
151
  */
144
152
  openStoreSheet(url: string, options?: StoreSheetOptions): Promise<StoreSheetResult>;
153
+ /**
154
+ * Opt-out switch for consent flows (default on, kept on the phone across launches by the native SDK).
155
+ * Off: no open reports, no events, no deferred or clipboard matching, nothing remembered; reports saved
156
+ * earlier and the remembered tap are deleted. A link that carries its own destination still reaches
157
+ * onLink; a short link is looked up through /v1/lookup, which records nothing (no tap, no open, no tap
158
+ * id), so it still routes (`reason: 'disabled'` only if that lookup fails). Back on: sending resumes, and
159
+ * a first-launch check skipped while off runs now. Works before start(): call it first on a consent screen.
160
+ */
161
+ setEnabled(enabled: boolean): Promise<void>;
162
+ /** The opt-out switch's current value (see setEnabled). True when it can't be read (the default). */
163
+ isEnabled(): Promise<boolean>;
145
164
  /** Stop delivering events to this object. */
146
165
  stop(): void;
147
166
  }
package/dist/strait.js CHANGED
@@ -55,12 +55,18 @@ export function createStrait(config, native) {
55
55
  id: '', kind: 'deferred', route: 'fingerprint', appState: 'foreground',
56
56
  matched: false, reason: 'unavailable', ms: 0, at: Date.now(),
57
57
  }),
58
- trackEvent: (name, extra = {}) => safe(async () => (await native.trackEvent({ name, ...extra })).accepted === true, false),
58
+ trackEvent: (name, extra = {}) => safe(async () => {
59
+ // Native getString() reads a number as missing: send a plain-JS number order id as its string (B13a).
60
+ const eventId = extra.eventId != null && extra.eventId !== '' ? { eventId: String(extra.eventId) } : {};
61
+ return (await native.trackEvent({ name, ...extra, ...eventId })).accepted === true;
62
+ }, false),
59
63
  pendingOpenReports: () => safe(async () => (await native.pendingOpenReports()).count ?? 0, 0),
60
64
  flushOpenReports: () => safe(() => native.flushOpenReports(), undefined),
61
65
  deviceClass: () => safe(async () => (await native.deviceClass()).deviceClass, undefined),
62
66
  doctor: () => safe(() => native.doctor(), { ok: false, findings: [] }),
63
67
  openStoreSheet: (url, options = {}) => safe(() => native.openStoreSheet({ url, ...options }), { opened: false, method: 'none', reason: 'unavailable' }),
68
+ setEnabled: (enabled) => safe(() => native.setEnabled({ enabled: enabled === true }), undefined),
69
+ isEnabled: () => safe(async () => (await native.isEnabled()).enabled !== false, true),
64
70
  stop() {
65
71
  linkCbs.clear();
66
72
  startCbs.clear();
@@ -19,12 +19,16 @@ public class StraitPlugin: CAPPlugin, CAPBridgedPlugin {
19
19
  CAPPluginMethod(name: "deviceClass", returnType: CAPPluginReturnPromise),
20
20
  CAPPluginMethod(name: "doctor", returnType: CAPPluginReturnPromise),
21
21
  CAPPluginMethod(name: "openStoreSheet", returnType: CAPPluginReturnPromise),
22
+ CAPPluginMethod(name: "setEnabled", returnType: CAPPluginReturnPromise),
23
+ CAPPluginMethod(name: "isEnabled", returnType: CAPPluginReturnPromise),
22
24
  ]
23
25
 
24
26
  private var links: StraitLinks?
25
27
  private var subscriptions: [StraitSubscription] = []
26
28
  /// A link that arrived before JS called start().
27
29
  private var pendingURL: URL?
30
+ /// setEnabled() before start(): applied to StraitLinks before it starts (which also clears saved reports).
31
+ private var pendingEnabled: Bool?
28
32
 
29
33
  override public func load() {
30
34
  for name in [Notification.Name.capacitorOpenURL, .capacitorOpenUniversalLink] {
@@ -51,6 +55,8 @@ public class StraitPlugin: CAPPlugin, CAPBridgedPlugin {
51
55
  let hosts = (call.getArray("linkHosts") as? [String]) ?? []
52
56
  let l = StraitLinks(StraitLinksConfig(publishableKey: key, endpoint: endpoint, linkHosts: hosts))
53
57
  links = l
58
+ if let on = pendingEnabled { l.setEnabled(on) } // before anything is sent
59
+ pendingEnabled = nil
54
60
  subscriptions = [
55
61
  l.onLinkStart { [weak self] s in self?.notifyListeners("linkStart", data: Self.js(s), retainUntilConsumed: true) },
56
62
  l.onLink { [weak self] e in self?.notifyListeners("link", data: Self.js(e), retainUntilConsumed: true) },
@@ -62,6 +68,27 @@ public class StraitPlugin: CAPPlugin, CAPBridgedPlugin {
62
68
  }
63
69
  }
64
70
 
71
+ /// Opt-out switch (consent): StraitSDK's setEnabled. Before start() it is saved (StraitLinks' default
72
+ /// storage, UserDefaults) and applied at start.
73
+ @objc func setEnabled(_ call: CAPPluginCall) {
74
+ guard let on = call.getBool("enabled") else {
75
+ call.reject("Strait: setEnabled needs enabled (true or false)")
76
+ return
77
+ }
78
+ DispatchQueue.main.async { [self] in
79
+ if let l = links { l.setEnabled(on) { call.resolve() }; return }
80
+ pendingEnabled = on
81
+ UserDefaultsStorage().setItem(StraitLinks.enabledKey, on ? "1" : "0")
82
+ call.resolve()
83
+ }
84
+ }
85
+
86
+ @objc func isEnabled(_ call: CAPPluginCall) {
87
+ DispatchQueue.main.async { [self] in
88
+ call.resolve(["enabled": links?.isEnabled ?? (UserDefaultsStorage().getItem(StraitLinks.enabledKey) != "0")])
89
+ }
90
+ }
91
+
65
92
  @objc func checkDeferred(_ call: CAPPluginCall) {
66
93
  guard let l = ready(call) else { return }
67
94
  l.checkDeferred { e in call.resolve(Self.js(e)) }
@@ -78,7 +105,8 @@ public class StraitPlugin: CAPPlugin, CAPBridgedPlugin {
78
105
  value: call.getDouble("value"),
79
106
  currency: call.getString("currency"),
80
107
  linkId: call.getString("linkId"),
81
- clickId: call.getString("clickId")
108
+ clickId: call.getString("clickId"),
109
+ eventId: call.getString("eventId")
82
110
  ) { ok in call.resolve(["accepted": ok]) }
83
111
  }
84
112
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@straitlink/capacitor",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Deep linking for Capacitor and Ionic apps: direct links (App Links, Universal Links, custom schemes), deferred links that survive the install and link-open analytics. Wraps the Strait Android and iOS SDKs.",
5
5
  "keywords": [
6
6
  "capacitor",