@cond/simasdk 0.0.0-stage → 0.1.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/CondSimasdk.podspec +18 -0
- package/Package.swift +29 -0
- package/README.md +508 -2
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/simasdk/SimaFirebasePlugin.java +139 -0
- package/android/src/main/java/com/simasdk/SimaHapticsPlugin.java +101 -0
- package/android/src/main/java/com/simasdk/SimaReviewPlugin.java +48 -0
- package/android/src/main/java/com/simasdk/SimaStoragePlugin.java +79 -0
- package/dist/ads.cjs +214 -0
- package/dist/ads.cjs.map +1 -0
- package/dist/ads.d.cts +98 -0
- package/dist/ads.d.ts +98 -0
- package/dist/ads.js +211 -0
- package/dist/ads.js.map +1 -0
- package/dist/back-button.cjs +95 -0
- package/dist/back-button.cjs.map +1 -0
- package/dist/back-button.d.cts +45 -0
- package/dist/back-button.d.ts +45 -0
- package/dist/back-button.js +88 -0
- package/dist/back-button.js.map +1 -0
- package/dist/cli.js +662 -0
- package/dist/firebase.cjs +102 -0
- package/dist/firebase.cjs.map +1 -0
- package/dist/firebase.d.cts +40 -0
- package/dist/firebase.d.ts +40 -0
- package/dist/firebase.js +99 -0
- package/dist/firebase.js.map +1 -0
- package/dist/haptics.cjs +81 -0
- package/dist/haptics.cjs.map +1 -0
- package/dist/haptics.d.cts +51 -0
- package/dist/haptics.d.ts +51 -0
- package/dist/haptics.js +78 -0
- package/dist/haptics.js.map +1 -0
- package/dist/index.cjs +233 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +99 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.js +226 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +118 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +51 -0
- package/dist/react.d.ts +51 -0
- package/dist/react.js +113 -0
- package/dist/react.js.map +1 -0
- package/dist/review.cjs +195 -0
- package/dist/review.cjs.map +1 -0
- package/dist/review.d.cts +76 -0
- package/dist/review.d.ts +76 -0
- package/dist/review.js +192 -0
- package/dist/review.js.map +1 -0
- package/dist/shell.cjs +97 -0
- package/dist/shell.cjs.map +1 -0
- package/dist/shell.d.cts +36 -0
- package/dist/shell.d.ts +36 -0
- package/dist/shell.js +91 -0
- package/dist/shell.js.map +1 -0
- package/dist/storage.cjs +140 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +48 -0
- package/dist/storage.d.ts +48 -0
- package/dist/storage.js +136 -0
- package/dist/storage.js.map +1 -0
- package/ios/Sources/SimasdkPlugin/SimaFirebasePlugin.swift +188 -0
- package/ios/Sources/SimasdkPlugin/SimaHapticsPlugin.swift +61 -0
- package/ios/Sources/SimasdkPlugin/SimaReviewPlugin.swift +40 -0
- package/ios/Sources/SimasdkPlugin/SimaStoragePlugin.swift +58 -0
- package/package.json +118 -4
- package/skills/simasdk/SKILL.md +189 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CondSimasdk'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = 'https://github.com/litepacks/simasdk'
|
|
11
|
+
s.author = 'litepacks'
|
|
12
|
+
s.source = { :git => 'https://github.com/litepacks/simasdk.git', :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/SimasdkPlugin/**/*.{swift,h,m}'
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.frameworks = 'StoreKit'
|
|
17
|
+
s.swift_version = '5.9'
|
|
18
|
+
end
|
package/Package.swift
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CondSimasdk",
|
|
6
|
+
platforms: [.iOS(.v14)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CondSimasdk",
|
|
10
|
+
targets: ["SimasdkPlugin"]
|
|
11
|
+
)
|
|
12
|
+
],
|
|
13
|
+
dependencies: [
|
|
14
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", "7.0.0"..<"9.0.0")
|
|
15
|
+
],
|
|
16
|
+
targets: [
|
|
17
|
+
.target(
|
|
18
|
+
name: "SimasdkPlugin",
|
|
19
|
+
dependencies: [
|
|
20
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
21
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
22
|
+
],
|
|
23
|
+
path: "ios/Sources/SimasdkPlugin",
|
|
24
|
+
linkerSettings: [
|
|
25
|
+
.linkedFramework("StoreKit")
|
|
26
|
+
]
|
|
27
|
+
)
|
|
28
|
+
]
|
|
29
|
+
)
|
package/README.md
CHANGED
|
@@ -1,3 +1,509 @@
|
|
|
1
|
-
#
|
|
1
|
+
# simasdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lightweight, single-package Capacitor SDK (`litepacks/simasdk`) for React + Capacitor mobile apps.
|
|
4
|
+
|
|
5
|
+
`simasdk` provides a cohesive set of lightweight, zero-bloat mobile modules:
|
|
6
|
+
|
|
7
|
+
1. **Native In-App Review policy (`@cond/simasdk/review`)** — persistent action counter, cooldown management, concurrency protection, and native StoreKit / Google Play In-App Review bridging.
|
|
8
|
+
2. **Opt-in Native Firebase Analytics (`simasdk` + `@cond/simasdk/firebase` + `@cond/simasdk/react`)** — automatic native `first_open` tracking for iOS/Android install campaigns (Google Ads) and strongly validated custom event tracking from React or plain TypeScript.
|
|
9
|
+
3. **Android Back Button Stack (`@cond/simasdk/back-button` + `useBackHandler` in `@cond/simasdk/react`)** — priority-ordered modal/overlay/navigation back handlers and double-back-to-exit helper.
|
|
10
|
+
4. **Semantic Haptics (`@cond/simasdk/haptics`)** — `light`, `medium`, `heavy`, `success`, `warning`, `error`, `selection` with persisted user on/off preference and native `UIKit` / `VibrationEffect` plugin (zero third-party deps).
|
|
11
|
+
5. **Native Shell Bootstrap (`@cond/simasdk/shell`)** — single non-throwing `initShell()` for `StatusBar`, `SplashScreen`, and `ScreenOrientation` when installed.
|
|
12
|
+
6. **Versioned Native Storage (`@cond/simasdk/storage` + `useStoredValue` in `@cond/simasdk/react`)** — typed, schema-versioned storage backed by `UserDefaults` (iOS) / `SharedPreferences` (Android) and `localStorage` on web.
|
|
13
|
+
7. **Opt-in AdMob Frequency Policy (`@cond/simasdk/ads`)** — interstitial frequency/cooldown policy and rewarded ad helper with a lazy `@capacitor-community/admob` driver (zero mandatory AdMob native SDK).
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Architecture & Guarantees
|
|
18
|
+
|
|
19
|
+
- **Single npm package, zero mandatory Firebase in native builds.**
|
|
20
|
+
Installing `simasdk` and running `npx cap sync` **never** pulls Firebase or Google measurement binaries into your iOS or Android app:
|
|
21
|
+
- **iOS (`Package.swift` / `CondSimasdk.podspec`)**: links only `Capacitor`, `Cordova`, and Apple's built-in `StoreKit.framework`. `SimaFirebasePlugin` bridges to `FIRApp` / `FIRAnalytics` via Objective-C runtime dispatch only when the host app links `FirebaseAnalytics`.
|
|
22
|
+
- **Android (`android/build.gradle`)**: declares `com.google.firebase:firebase-analytics` as `compileOnly`, so Firebase is never packaged into APKs/AABs unless the host app explicitly adds it.
|
|
23
|
+
- **No Firebase Web SDK.** Web previews (Vite) and SSR imports never access `window` at module load and never send analytics data.
|
|
24
|
+
- **Optional React peer dependency.** Projects without React can import `simasdk`, `@cond/simasdk/review`, and `@cond/simasdk/firebase` without installing or resolving `react`.
|
|
25
|
+
- **Non-throwing analytics.** `track()` and `setAnalyticsCollectionEnabled()` never throw into product flows (such as saving a photo or exporting a file). Native misconfigurations return `{ ok: false, status: 'error', error }` instead of silently succeeding.
|
|
26
|
+
- **No background retry queue or event database.** Events are forwarded directly to native Firebase Analytics.
|
|
27
|
+
|
|
28
|
+
### Supported Toolchain & Compatibility
|
|
29
|
+
|
|
30
|
+
| Component | Supported / Verified Version |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| Capacitor | `^7.0.0 \|\| ^8.0.0` (SPM range `"7.0.0"..<"9.0.0"`, verified with Capacitor `8.6.3`) |
|
|
33
|
+
| Node.js (Capacitor 8 CLI) | `>= 22.0.0` (`>= 20.0.0` for Capacitor 7) |
|
|
34
|
+
| React (optional peer) | `>= 18.0.0 < 20.0.0` (verified with `19.x`) |
|
|
35
|
+
| iOS Deployment Target | `iOS 14.0+` (verified Release arm64 build on Xcode `26.6`) |
|
|
36
|
+
| Android | `minSdk 24`, `compileSdk 35/36`, **Java 17** plugins (zero Kotlin version conflicts across Cap 7 & Cap 8) |
|
|
37
|
+
|
|
38
|
+
> **CocoaPods note:** `CondSimasdk.podspec` is included for legacy CocoaPods projects, while Swift Package Manager (`Package.swift`) is the primary Capacitor 8 integration path.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Scenario 1: Shared Mobile Features Only (In-App Review Without Firebase)
|
|
43
|
+
|
|
44
|
+
Use this setup when you want persistent In-App Review prompting with **zero Firebase dependencies** in JS, iOS, or Android.
|
|
45
|
+
|
|
46
|
+
### 1. Install and sync
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install @cond/simasdk
|
|
50
|
+
npx cap sync
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 2. Define a review policy and record successful actions
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { createReviewPolicy } from '@cond/simasdk/review';
|
|
57
|
+
|
|
58
|
+
export const exportReview = createReviewPolicy({
|
|
59
|
+
key: 'successful_exports',
|
|
60
|
+
minimumActions: 3,
|
|
61
|
+
cooldownDays: 90,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export async function onPhotoExported() {
|
|
65
|
+
// Call ONLY after the user's product action succeeds.
|
|
66
|
+
const result = await exportReview.recordSuccess();
|
|
67
|
+
// result.status is one of:
|
|
68
|
+
// 'not_eligible' | 'cooldown' | 'requested' | 'unsupported' | 'failed'
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Review Policy Behavior & Semantics
|
|
73
|
+
|
|
74
|
+
- **Persistence:** `actionCount` and `lastRequestedAt` are persisted under `simasdk:review:v1:<key>` (`localStorage` on WebView/browser, with an SSR-safe in-memory fallback). Multiple instances created with the same `key` share state consistently.
|
|
75
|
+
- **Concurrency protection:** Concurrent `recordSuccess()` calls on the same `key` (even across separate instances) are serialized so every success is counted while at most one native review request is issued.
|
|
76
|
+
- **Failure semantics:** `actionCount` is incremented and persisted before invoking the native API. If the native review call fails, `lastRequestedAt` is **not** updated (so the user is not locked into a cooldown), and `{ status: 'failed', error, ... }` is returned without throwing.
|
|
77
|
+
- **Observable results only:** Neither Apple StoreKit (`AppStore.requestReview(in:)` on iOS 16+, `SKStoreReviewController.requestReview(in:)` on iOS 15) nor Google Play In-App Review (`ReviewManager.launchReviewFlow`) reveals whether the OS actually displayed a prompt or whether the user submitted a rating. `'requested'` strictly means the native API call completed without error.
|
|
78
|
+
- **No analytics coupling:** `@cond/simasdk/review` has zero dependency on Firebase and never emits analytics events.
|
|
79
|
+
|
|
80
|
+
### Native Cost for Apps That Do Not Use Review
|
|
81
|
+
|
|
82
|
+
Because `simasdk` is a single Capacitor plugin package:
|
|
83
|
+
- **iOS:** links Apple's system `StoreKit.framework` (and system `UIKit`/`Foundation` for haptics & storage; zero third-party native dependencies).
|
|
84
|
+
- **Android:** includes `com.google.android.play:review:2.0.2` (Google Play In-App Review library). Firebase and AdMob are **never** pulled in automatically.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Additional Shared Modules
|
|
89
|
+
|
|
90
|
+
### `@cond/simasdk/back-button` — Android Back Button & Overlay Stack
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import {
|
|
94
|
+
attachCapacitorBackButton,
|
|
95
|
+
createDoubleBackExit,
|
|
96
|
+
registerBackHandler,
|
|
97
|
+
} from '@cond/simasdk/back-button';
|
|
98
|
+
|
|
99
|
+
// Attach once at app startup
|
|
100
|
+
await attachCapacitorBackButton();
|
|
101
|
+
|
|
102
|
+
// Lowest priority: double-back to exit on the root screen
|
|
103
|
+
registerBackHandler(
|
|
104
|
+
createDoubleBackExit({
|
|
105
|
+
windowMs: 2000,
|
|
106
|
+
onFirstPress: () => showToast('Press back again to exit'),
|
|
107
|
+
}),
|
|
108
|
+
{ priority: 0 },
|
|
109
|
+
);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
In React components (e.g., modals or drawers), use `useBackHandler` from `@cond/simasdk/react`:
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import { useBackHandler } from '@cond/simasdk/react';
|
|
116
|
+
|
|
117
|
+
useBackHandler(
|
|
118
|
+
() => {
|
|
119
|
+
closeModal();
|
|
120
|
+
return true; // stops propagation to lower-priority handlers
|
|
121
|
+
},
|
|
122
|
+
{ enabled: isModalOpen, priority: 100 },
|
|
123
|
+
);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### `@cond/simasdk/haptics` — Semantic Haptics
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { createHaptics } from '@cond/simasdk/haptics';
|
|
130
|
+
|
|
131
|
+
export const haptics = createHaptics();
|
|
132
|
+
|
|
133
|
+
await haptics.light();
|
|
134
|
+
await haptics.success();
|
|
135
|
+
await haptics.selection();
|
|
136
|
+
|
|
137
|
+
// Persisted user preference
|
|
138
|
+
haptics.setEnabled(false);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### `@cond/simasdk/shell` — Native Shell Bootstrap
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import { initShell } from '@cond/simasdk/shell';
|
|
145
|
+
|
|
146
|
+
await initShell({
|
|
147
|
+
statusBarStyle: 'dark',
|
|
148
|
+
statusBarBackgroundColor: '#121212',
|
|
149
|
+
orientation: 'portrait',
|
|
150
|
+
hideSplash: true,
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Only calls official Capacitor plugins (`StatusBar`, `SplashScreen`, `ScreenOrientation`) that are installed in the host app; safely no-ops on web/SSR.
|
|
155
|
+
|
|
156
|
+
### `@cond/simasdk/storage` — Versioned Native Storage
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
import { createStorage } from '@cond/simasdk/storage';
|
|
160
|
+
|
|
161
|
+
export const settingsStore = createStorage({
|
|
162
|
+
namespace: 'settings',
|
|
163
|
+
version: 2,
|
|
164
|
+
migrate(key, oldValue, fromVersion) {
|
|
165
|
+
// Optional schema migration when version increments
|
|
166
|
+
return oldValue;
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
await settingsStore.set('sound', true);
|
|
171
|
+
const sound = await settingsStore.get('sound', true);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
In React, pair with `useStoredValue(settingsStore, 'sound', true)` from `@cond/simasdk/react`.
|
|
175
|
+
|
|
176
|
+
### `@cond/simasdk/ads` — Opt-in AdMob Frequency & Cooldown Policy
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
import { createAdPolicy } from '@cond/simasdk/ads';
|
|
180
|
+
|
|
181
|
+
export const levelAds = createAdPolicy({
|
|
182
|
+
key: 'level_complete',
|
|
183
|
+
interstitialAdId: {
|
|
184
|
+
ios: 'ca-app-pub-xxx/ios-interstitial',
|
|
185
|
+
android: 'ca-app-pub-xxx/android-interstitial',
|
|
186
|
+
},
|
|
187
|
+
minActionsBeforeFirst: 2,
|
|
188
|
+
actionsBetweenAds: 3,
|
|
189
|
+
cooldownSeconds: 90,
|
|
190
|
+
disabled: () => isProUser(),
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Call after a level/action finishes
|
|
194
|
+
await levelAds.recordActionAndMaybeShow();
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
`@cond/simasdk/ads` lazily bridges to `@capacitor-community/admob` if installed in your host app; `simasdk` never bundles AdMob into apps that do not install it.
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## CLI (`npx simasdk`)
|
|
202
|
+
|
|
203
|
+
`simasdk` ships with a zero-dependency CLI for auditing Capacitor projects and scaffolding setup files:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# Audit Capacitor plugin sync, iOS/Android Firebase config, Bundle ID match, and consent flags
|
|
207
|
+
npx simasdk doctor
|
|
208
|
+
npx simasdk doctor --json
|
|
209
|
+
|
|
210
|
+
# Scaffold src/sima.ts for your chosen modules
|
|
211
|
+
npx simasdk init --firebase --review --haptics --storage --back-button --shell
|
|
212
|
+
npx simasdk init --all
|
|
213
|
+
|
|
214
|
+
# Install the bundled AI agent SKILL.md locally (project) or globally (home dir)
|
|
215
|
+
npx simasdk skill install --local
|
|
216
|
+
npx simasdk skill install --global
|
|
217
|
+
npx simasdk skill install --global --target all # agents, claude, gemini/antigravity, cursor
|
|
218
|
+
npx simasdk skill uninstall --global
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Scenario 2: iOS Install Conversion Only (`first_open`, Zero React Event Code)
|
|
224
|
+
|
|
225
|
+
Use this setup when you only want Firebase's automatic `first_open` event for iOS install attribution in Google Ads—**no `<SimaProvider>`, no `useSima()`, and no `track()` calls are required.**
|
|
226
|
+
|
|
227
|
+
### 1. Install `simasdk` and sync iOS
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
npm install @cond/simasdk
|
|
231
|
+
npx cap sync ios
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### 2. Add `FirebaseAnalytics` to your iOS app in Xcode
|
|
235
|
+
|
|
236
|
+
1. Open your iOS project in Xcode: `npx cap open ios`
|
|
237
|
+
2. Select **File -> Add Package Dependencies...**
|
|
238
|
+
3. Enter `https://github.com/firebase/firebase-ios-sdk.git` (version `12.0.0` or newer).
|
|
239
|
+
4. Select the **`FirebaseAnalytics`** library product and add it to the **`App`** target.
|
|
240
|
+
|
|
241
|
+
*(If your project uses CocoaPods instead of SPM, add `pod 'FirebaseAnalytics', '~> 12.0'` to `ios/App/Podfile` and run `pod install`.)*
|
|
242
|
+
|
|
243
|
+
### 3. Add `GoogleService-Info.plist` to the `App` target
|
|
244
|
+
|
|
245
|
+
1. Download `GoogleService-Info.plist` from Firebase Console -> **Project Settings** -> your iOS app.
|
|
246
|
+
2. Drag `GoogleService-Info.plist` into `ios/App/App/` in Xcode.
|
|
247
|
+
3. In the Xcode dialog, verify:
|
|
248
|
+
- **Copy items if needed** is checked.
|
|
249
|
+
- **Add to targets -> `App`** is checked.
|
|
250
|
+
4. Confirm that `BUNDLE_ID` inside `GoogleService-Info.plist` **exactly matches** your Xcode `App` target's Bundle Identifier (`PRODUCT_BUNDLE_IDENTIFIER`).
|
|
251
|
+
5. Do **not** commit real production credentials or secrets to public repositories.
|
|
252
|
+
|
|
253
|
+
### 4. Configure Firebase in `AppDelegate.swift` (recommended)
|
|
254
|
+
|
|
255
|
+
Open `ios/App/App/AppDelegate.swift` and call `FirebaseApp.configure()` inside `application(_:didFinishLaunchingWithOptions:)`:
|
|
256
|
+
|
|
257
|
+
```swift
|
|
258
|
+
import UIKit
|
|
259
|
+
import Capacitor
|
|
260
|
+
import FirebaseCore
|
|
261
|
+
|
|
262
|
+
@UIApplicationMain
|
|
263
|
+
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
264
|
+
|
|
265
|
+
var window: UIWindow?
|
|
266
|
+
|
|
267
|
+
func application(
|
|
268
|
+
_ application: UIApplication,
|
|
269
|
+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
|
270
|
+
) -> Bool {
|
|
271
|
+
FirebaseApp.configure()
|
|
272
|
+
return true
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**Who configures Firebase and when?**
|
|
278
|
+
- Calling `FirebaseApp.configure()` in `AppDelegate` is the official Firebase recommendation because it runs before the Capacitor bridge starts and allows Firebase to capture launch options and `first_open` as early as possible.
|
|
279
|
+
- `SimaFirebasePlugin` is compatible with an existing default `FirebaseApp`: if `AppDelegate` already called `FirebaseApp.configure()`, `SimaFirebasePlugin.load()` does nothing.
|
|
280
|
+
- If `AppDelegate` did not call `FirebaseApp.configure()`, `SimaFirebasePlugin.load()` (which Capacitor runs automatically at bridge startup without any JS calls) acts as a safe fallback whenever `FirebaseAnalytics` is linked and `GoogleService-Info.plist` is present in the main bundle.
|
|
281
|
+
|
|
282
|
+
### Android Host Setup (when also measuring Android)
|
|
283
|
+
|
|
284
|
+
1. Download `google-services.json` from Firebase Console and place it at `android/app/google-services.json`.
|
|
285
|
+
2. In `android/build.gradle` (project-level), add the Google Services plugin:
|
|
286
|
+
|
|
287
|
+
```groovy
|
|
288
|
+
plugins {
|
|
289
|
+
id 'com.google.gms.google-services' version '4.6.0' apply false
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
3. In `android/app/build.gradle` (app-level), apply the plugin and add Firebase Analytics:
|
|
294
|
+
|
|
295
|
+
```groovy
|
|
296
|
+
apply plugin: 'com.google.gms.google-services'
|
|
297
|
+
|
|
298
|
+
dependencies {
|
|
299
|
+
implementation platform('com.google.firebase:firebase-bom:35.2.0')
|
|
300
|
+
implementation 'com.google.firebase:firebase-analytics'
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Android initializes Firebase automatically at app launch via `FirebaseInitProvider`, collecting `first_open` without any JS or React code.
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## Scenario 3: Custom Events from React (and Outside React)
|
|
309
|
+
|
|
310
|
+
### 1. Create a shared `sima` client
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
// src/sima.ts
|
|
314
|
+
import { createSima } from '@cond/simasdk';
|
|
315
|
+
import { firebaseAnalytics } from '@cond/simasdk/firebase';
|
|
316
|
+
|
|
317
|
+
export const sima = createSima({
|
|
318
|
+
analytics: firebaseAnalytics(),
|
|
319
|
+
onError(error) {
|
|
320
|
+
// Optional: log analytics configuration/validation issues in development.
|
|
321
|
+
console.warn('[simasdk]', error.code, error.message);
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
`createSima()` can also be called with no arguments (`createSima()`) for no-op mode.
|
|
327
|
+
|
|
328
|
+
### 2. Mount `<SimaProvider>` and track events with `useSima()`
|
|
329
|
+
|
|
330
|
+
```tsx
|
|
331
|
+
// src/App.tsx
|
|
332
|
+
import { SimaProvider, useSima } from '@cond/simasdk/react';
|
|
333
|
+
import { sima } from './sima';
|
|
334
|
+
|
|
335
|
+
export function App() {
|
|
336
|
+
return (
|
|
337
|
+
<SimaProvider client={sima}>
|
|
338
|
+
<ExportButton />
|
|
339
|
+
</SimaProvider>
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function ExportButton() {
|
|
344
|
+
const { track } = useSima();
|
|
345
|
+
|
|
346
|
+
async function handleExport() {
|
|
347
|
+
await exportPhoto();
|
|
348
|
+
// Never throws: an analytics error will not mark a successful export as failed.
|
|
349
|
+
const result = await track('photo_exported', { format: 'jpeg' });
|
|
350
|
+
if (!result.ok) {
|
|
351
|
+
// Optional inspection; already forwarded to `onError`.
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return <button onClick={handleExport}>Save photo</button>;
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### 3. Track events outside React
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
import { sima } from './sima';
|
|
363
|
+
|
|
364
|
+
await sima.track('photo_exported', { format: 'jpeg', width: 1920 });
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Event & Parameter Contract
|
|
368
|
+
|
|
369
|
+
To ensure identical representation across iOS (`NSString` / `NSNumber`) and Android (`Bundle.putString` / `putLong` / `putDouble`) with **no silent data mutation**:
|
|
370
|
+
|
|
371
|
+
- **Event names:** `1–40` ASCII characters matching `/^[A-Za-z][A-Za-z0-9_]*$/`. Reserved prefixes (`firebase_`, `ga_`, `google_`) and automatically collected/reserved event names (including `first_open`, `session_start`, `in_app_purchase`, `screen_view`, etc.) are rejected with `INVALID_EVENT_NAME`.
|
|
372
|
+
- **Parameters:** Up to `25` parameters per event. Keys must be `1–40` ASCII characters matching `/^[A-Za-z][A-Za-z0-9_]*$/` and must not start with `firebase_`, `ga_`, `google_`, `gtag_`, or `_`.
|
|
373
|
+
- **Parameter values:** `string` (max `100` characters — rejected, never silently truncated) or finite `number` (`NaN` / `Infinity` rejected). Booleans, objects, arrays, `null`, and `undefined` are rejected with `INVALID_PARAM_VALUE`.
|
|
374
|
+
- **React Strict Mode:** `<SimaProvider>` is a pure React Context provider; rendering, remounting, or React Strict Mode double-mounting never triggers native initialization or duplicate events.
|
|
375
|
+
- **Provider guard:** Calling `useSima()` outside `<SimaProvider>` throws a descriptive developer error.
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## Controlling Analytics Collection & User Consent
|
|
380
|
+
|
|
381
|
+
You can toggle analytics collection at runtime:
|
|
382
|
+
|
|
383
|
+
```ts
|
|
384
|
+
await sima.setAnalyticsCollectionEnabled(false);
|
|
385
|
+
// Later, after consent is granted:
|
|
386
|
+
await sima.setAnalyticsCollectionEnabled(true);
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
> **Important:** Calling `setAnalyticsCollectionEnabled(false)` from JavaScript after app launch does **not** retroactively undo `first_open` or any events that Firebase may have already collected during native startup.
|
|
390
|
+
|
|
391
|
+
To start with analytics collection **disabled before user consent**:
|
|
392
|
+
|
|
393
|
+
- **iOS (`ios/App/App/Info.plist`):**
|
|
394
|
+
|
|
395
|
+
```xml
|
|
396
|
+
<key>FIREBASE_ANALYTICS_COLLECTION_ENABLED</key>
|
|
397
|
+
<false/>
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
- **Android (`android/app/src/main/AndroidManifest.xml`, inside `<application>`):**
|
|
401
|
+
|
|
402
|
+
```xml
|
|
403
|
+
<meta-data
|
|
404
|
+
android:name="firebase_analytics_collection_enabled"
|
|
405
|
+
android:value="false" />
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
|
|
410
|
+
## iOS Native Dependencies & Measured Binary Size Impact
|
|
411
|
+
|
|
412
|
+
### Verified Transitive Dependencies of `FirebaseAnalytics` (`firebase-ios-sdk 12.19.3`)
|
|
413
|
+
|
|
414
|
+
Adding the standard `FirebaseAnalytics` product via Swift Package Manager links:
|
|
415
|
+
|
|
416
|
+
- **Embedded dynamic frameworks:**
|
|
417
|
+
- `FirebaseAnalytics.framework`
|
|
418
|
+
- `GoogleAppMeasurement.framework` (`12.19.2`)
|
|
419
|
+
- `GoogleAppMeasurementIdentitySupport.framework` (hooks into Apple's `AdSupport` framework for IDFA when ATT permission is granted)
|
|
420
|
+
- `GoogleAdsOnDeviceConversion.framework` (`3.7.0` — on-device conversion measurement for Google Ads)
|
|
421
|
+
- **Statically linked support libraries:** `FirebaseCore`, `FirebaseInstallations`, `GoogleUtilities` (`8.1.5`), `nanopb` (`2.30910.1`), `FBLPromises` (`2.4.1`).
|
|
422
|
+
|
|
423
|
+
**`FirebaseAnalytics` vs. `FirebaseAnalyticsCore` for Google Ads:**
|
|
424
|
+
- **`FirebaseAnalytics` (recommended for Google Ads):** Includes `GoogleAppMeasurementIdentitySupport` and `GoogleAdsOnDeviceConversion` for full Google Ads install attribution, conversion modeling, and remarketing audiences (when ATT is granted).
|
|
425
|
+
- **`FirebaseAnalyticsCore` (Pod: `FirebaseAnalytics/Core`):** Omits `AdSupport`/IDFA collection. Useful for kids' apps or strict no-IDFA apps, but reduces deterministic attribution and remarketing capabilities in Google Ads.
|
|
426
|
+
|
|
427
|
+
### Measured iOS Release Size Comparison
|
|
428
|
+
|
|
429
|
+
Measured on the same Capacitor `8.6.3` iOS app (`arm64`, `iOS 15.0` deployment target, `Xcode 26.6`, `xcodebuild -configuration Release -sdk iphoneos CODE_SIGNING_ALLOWED=NO`):
|
|
430
|
+
|
|
431
|
+
| Build Variant | Installed `.app` Bundle Size | Compressed `.ipa` Proxy Size |
|
|
432
|
+
| --- | ---: | ---: |
|
|
433
|
+
| `simasdk` only (zero Firebase) | `1,500,825 B` (`1.43 MiB`) | `635,962 B` (`621.1 KiB`) |
|
|
434
|
+
| `simasdk` + `FirebaseAnalytics` (`12.19.3`) | `2,598,242 B` (`2.48 MiB`) | `906,603 B` (`885.4 KiB`) |
|
|
435
|
+
| **Delta (`+FirebaseAnalytics`)** | **`+1,097,417 B` (`+1.05 MiB`)** | **`+270,641 B` (`+264.3 KiB`)** |
|
|
436
|
+
|
|
437
|
+
*Note: Compressed `.ipa` is a standard zip of `Payload/App.app` without App Store Connect FairPlay encryption or per-device thinning; final App Store Connect download/install numbers may vary slightly.*
|
|
438
|
+
|
|
439
|
+
---
|
|
440
|
+
|
|
441
|
+
## End-to-End Google Ads Setup Guide (iOS `first_open` Install Campaign)
|
|
442
|
+
|
|
443
|
+
Follow these steps in order to connect your Capacitor iOS app to a Google Ads App Install campaign.
|
|
444
|
+
|
|
445
|
+
### Step 1: Enable Analytics in Firebase and register your iOS app
|
|
446
|
+
|
|
447
|
+
1. Open [Firebase Console](https://console.firebase.google.com/) and create or open your project.
|
|
448
|
+
2. Ensure **Google Analytics** is enabled and linked to the intended **Google Analytics 4 (GA4)** property (**Project Settings -> Integrations -> Google Analytics**).
|
|
449
|
+
3. Add your iOS app under **Project Settings -> General -> Your apps**:
|
|
450
|
+
- Enter the exact **Apple Bundle ID** from Xcode.
|
|
451
|
+
- Enter your numeric **App Store ID** (e.g., `123456789` from `apps.apple.com/app/id123456789`). Missing App Store IDs commonly prevent Google Ads from matching iOS app conversions.
|
|
452
|
+
4. Download `GoogleService-Info.plist` and complete [Scenario 2](#scenario-2-ios-install-conversion-only-first_open-zero-react-event-code).
|
|
453
|
+
|
|
454
|
+
### Step 2: Verify live events on an iOS device with DebugView
|
|
455
|
+
|
|
456
|
+
1. In Xcode, open **Product -> Scheme -> Edit Scheme... -> Run -> Arguments**.
|
|
457
|
+
2. Under **Arguments Passed On Launch**, add:
|
|
458
|
+
```text
|
|
459
|
+
-FIRDebugEnabled
|
|
460
|
+
```
|
|
461
|
+
3. Delete any previous install of the app from your test device/simulator, then run a fresh install from Xcode.
|
|
462
|
+
4. Open **Firebase Console -> Analytics -> DebugView** and select your test device.
|
|
463
|
+
5. Confirm that **`first_open`** (and `session_start`) appears in DebugView within ~10–30 seconds.
|
|
464
|
+
6. Remove `-FIRDebugEnabled` (or disable the launch argument) when testing non-debug traffic.
|
|
465
|
+
|
|
466
|
+
### Step 3: Link the GA4 property to Google Ads
|
|
467
|
+
|
|
468
|
+
1. Open **Google Ads**.
|
|
469
|
+
2. Navigate to **Tools** (or **Admin**) -> **Data Manager** (or **Linked accounts / Product links**).
|
|
470
|
+
3. Find **Google Analytics (GA4) & Firebase** and click **Manage & link**.
|
|
471
|
+
4. Select the exact GA4 property connected to your Firebase project and complete the link.
|
|
472
|
+
5. Confirm in **Google Analytics (GA4) -> Admin -> Events** that `first_open` is present for your iOS app stream and marked as a **Key Event / Conversion**.
|
|
473
|
+
|
|
474
|
+
### Step 4: Import the iOS `first_open` conversion into Google Ads
|
|
475
|
+
|
|
476
|
+
1. In **Google Ads**, open **Goals -> Conversions -> Summary**.
|
|
477
|
+
2. Click **+ New conversion action**.
|
|
478
|
+
3. Select **App** -> **Google Analytics 4 properties** -> **Continue**.
|
|
479
|
+
4. Locate your **iOS app data stream** (verify the Apple/iOS icon and app name, **not** the Android stream) and check **`first_open`**.
|
|
480
|
+
5. Click **Import and continue**, then **Done**.
|
|
481
|
+
|
|
482
|
+
### Step 5: Set `first_open` as the campaign optimization goal
|
|
483
|
+
|
|
484
|
+
1. In **Goals -> Conversions -> Summary**, verify that the imported iOS `first_open` conversion action is set to **Primary** (used for bidding optimization).
|
|
485
|
+
2. When creating or editing your **App campaign (App installs)** for iOS, select your iOS app and verify that it optimizes toward the imported `first_open` install conversion.
|
|
486
|
+
|
|
487
|
+
### Understanding the Three Verification Stages
|
|
488
|
+
|
|
489
|
+
Do not confuse these three distinct milestones:
|
|
490
|
+
|
|
491
|
+
1. **Device DebugView (`first_open` visible in Firebase DebugView):**
|
|
492
|
+
Proves that `FirebaseAnalytics` is linked, `GoogleService-Info.plist` is bundled in the `App` target, and Firebase is configured on the device. DebugView events are isolated from standard reports.
|
|
493
|
+
2. **Conversion selectable in Google Ads (`first_open` importable under Goals -> Conversions):**
|
|
494
|
+
Proves that Firebase <-> GA4 <-> Google Ads are linked to the same property, the iOS App Store ID is configured, and non-debug `first_open` events have been processed by GA4 (typically within 24 hours of first non-debug opens).
|
|
495
|
+
3. **Attributed conversions on a live ad campaign:**
|
|
496
|
+
Occurs only after real users click a running Google Ads campaign, install, and open the app. On iOS, due to Apple ATT, SKAdNetwork, and Google's conversion modeling, attributed conversion counts typically take **24–72 hours** to appear and stabilize.
|
|
497
|
+
|
|
498
|
+
---
|
|
499
|
+
|
|
500
|
+
## Troubleshooting
|
|
501
|
+
|
|
502
|
+
| Symptom | Likely Cause | Fix |
|
|
503
|
+
| --- | --- | --- |
|
|
504
|
+
| `first_open` never appears in DebugView | Wrong Bundle ID in `GoogleService-Info.plist` | Match `BUNDLE_ID` in `GoogleService-Info.plist` to Xcode's `PRODUCT_BUNDLE_IDENTIFIER` and re-download the plist if needed. |
|
|
505
|
+
| `track()` returns `NATIVE_NOT_CONFIGURED` on iOS | `GoogleService-Info.plist` not included in `App` target, or `FirebaseAnalytics` not linked | Check **Target Membership -> `App`** on `GoogleService-Info.plist` in Xcode and verify `FirebaseAnalytics` is added to the `App` target. |
|
|
506
|
+
| No events sent despite valid plist | Analytics collection is disabled | Check `FIREBASE_ANALYTICS_COLLECTION_ENABLED` in `Info.plist`, `firebase_analytics_collection_enabled` in `AndroidManifest.xml`, and any `setAnalyticsCollectionEnabled(false)` calls. |
|
|
507
|
+
| `first_open` appears in Firebase but is missing in Google Ads import list | Wrong GA4 property linked to Google Ads, or missing App Store ID | Verify the exact GA4 Property ID in Firebase (**Project Settings -> Integrations -> Google Analytics**) matches Google Ads (**Data Manager -> Google Analytics (GA4) & Firebase**), and verify the iOS **App Store ID** in Firebase Project Settings. |
|
|
508
|
+
| iOS campaign reports 0 conversions while Android shows conversions | Android `first_open` event was imported/selected for an iOS campaign | In **Google Ads -> Goals -> Conversions**, verify the conversion action belongs to the **iOS** app stream, not the Android stream. |
|
|
509
|
+
| Events appear in DebugView immediately, but Google Ads shows "No recent conversions" or empty import | Debug traffic is excluded from production reports, or normal 24–72h propagation delay | Run a non-debug build (without `-FIRDebugEnabled`), open the app, and allow 24–72 hours for GA4/Google Ads sync and iOS conversion modeling. |
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
|
|
3
|
+
playReviewVersion = project.hasProperty('simaPlayReviewVersion') ? rootProject.ext.simaPlayReviewVersion : '2.0.2'
|
|
4
|
+
firebaseBomVersion = project.hasProperty('simaFirebaseBomVersion') ? rootProject.ext.simaFirebaseBomVersion : '35.2.0'
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
buildscript {
|
|
8
|
+
repositories {
|
|
9
|
+
google()
|
|
10
|
+
mavenCentral()
|
|
11
|
+
}
|
|
12
|
+
dependencies {
|
|
13
|
+
classpath 'com.android.tools.build:gradle:8.7.3'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
apply plugin: 'com.android.library'
|
|
18
|
+
|
|
19
|
+
android {
|
|
20
|
+
namespace "com.simasdk"
|
|
21
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
22
|
+
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdk project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdk project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "0.1.0"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Java 17 bytecode compiles cleanly on both Capacitor 7 (JDK 17) and Capacitor 8 (JDK 21),
|
|
38
|
+
// with zero Kotlin plugin version conflicts across host apps.
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
dependencies {
|
|
51
|
+
implementation project(':capacitor-android')
|
|
52
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
53
|
+
|
|
54
|
+
// Included for simasdk/review (Google Play In-App Review).
|
|
55
|
+
implementation "com.google.android.play:review:$playReviewVersion"
|
|
56
|
+
|
|
57
|
+
// compileOnly ensures Firebase Analytics is NEVER pulled into APKs/AABs unless
|
|
58
|
+
// the host app explicitly declares firebase-analytics in android/app/build.gradle.
|
|
59
|
+
compileOnly platform("com.google.firebase:firebase-bom:$firebaseBomVersion")
|
|
60
|
+
compileOnly "com.google.firebase:firebase-analytics"
|
|
61
|
+
}
|