@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,189 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: simasdk
|
|
3
|
+
description: Integrate and operate `simasdk` (litepacks/simasdk) in Capacitor 7/8 + React or vanilla TypeScript mobile apps. Use when adding native Firebase Analytics (`first_open` for Google Ads iOS/Android install campaigns or custom events), In-App Review policies, Android back-button overlay stacks, semantic haptics, native shell bootstrap (StatusBar/SplashScreen/Orientation), versioned native storage (`UserDefaults`/`SharedPreferences`), or opt-in AdMob interstitial/rewarded frequency policies.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# simasdk Integration & Operations Skill
|
|
7
|
+
|
|
8
|
+
Use this runbook whenever integrating, migrating, or debugging `simasdk` in a Capacitor 7 or Capacitor 8 mobile application.
|
|
9
|
+
|
|
10
|
+
## Core Architectural Rules (Never Violate)
|
|
11
|
+
|
|
12
|
+
1. **Single package, zero forced third-party native bloat.**
|
|
13
|
+
`simasdk` never forces Firebase or AdMob into native iOS/Android builds. Only add native `FirebaseAnalytics` (Xcode SPM / Podfile / Gradle) or `@capacitor-community/admob` when the host app explicitly needs them.
|
|
14
|
+
2. **Never install the Firebase Web SDK** (`firebase` npm package) for mobile analytics. `@cond/simasdk/firebase` bridges directly to native iOS/Android Firebase Analytics and safely returns `{ ok: true, status: 'ignored_web' }` on web/SSR.
|
|
15
|
+
3. **Never log automatic Firebase events manually.** Never call `track('first_open')`, `track('session_start')`, or any `firebase_*` / `ga_*` / `google_*` event. Native Firebase collects `first_open` automatically once configured—even with zero React or JS event code.
|
|
16
|
+
4. **Never break product flows on analytics or review failures.** `sima.track()` and `review.recordSuccess()` are non-throwing by design. Always call them *after* the user's product action succeeds.
|
|
17
|
+
5. **Never rely on silent data truncation.** `track()` strictly accepts `string` (<= 100 chars) and finite `number` values only (identical on iOS and Android). Do not pass booleans, arrays, or nested objects.
|
|
18
|
+
6. **React is optional.** Never import `@cond/simasdk/react` in non-React apps or utility modules that must run outside React.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Subpath Selection Matrix
|
|
23
|
+
|
|
24
|
+
| Need | Import Path | Native Dependency Added |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| Core analytics client (`createSima`) | `simasdk` | None |
|
|
27
|
+
| React provider & hooks (`SimaProvider`, `useSima`, `useBackHandler`, `useStoredValue`) | `@cond/simasdk/react` | None (`react` optional peer) |
|
|
28
|
+
| Persistent In-App Review policy (`createReviewPolicy`) | `@cond/simasdk/review` | iOS `StoreKit` (system), Android `play:review:2.0.2` |
|
|
29
|
+
| Native Firebase Analytics adapter (`firebaseAnalytics`) | `@cond/simasdk/firebase` | Opt-in host app `FirebaseAnalytics` / `firebase-analytics` |
|
|
30
|
+
| Android back-button stack & double-back exit | `@cond/simasdk/back-button` | Uses `@capacitor/app` if installed |
|
|
31
|
+
| Semantic haptics with persisted toggle | `@cond/simasdk/haptics` | Built-in `SimaHaptics` (iOS `UIKit`, Android `VibrationEffect`) |
|
|
32
|
+
| StatusBar / SplashScreen / Orientation bootstrap | `@cond/simasdk/shell` | Uses installed official `@capacitor/*` plugins only |
|
|
33
|
+
| Typed, versioned native key-value storage | `@cond/simasdk/storage` | Built-in `SimaStorage` (`UserDefaults` / `SharedPreferences`) |
|
|
34
|
+
| AdMob interstitial frequency/cooldown & rewarded policy | `@cond/simasdk/ads` | Opt-in host app `@capacitor-community/admob` |
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Integration Recipes
|
|
39
|
+
|
|
40
|
+
### 1. Install & Sync
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @cond/simasdk
|
|
44
|
+
npx cap sync
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- Supported Capacitor versions: **`^7.0.0 || ^8.0.0`**
|
|
48
|
+
- Supported iOS: **`14.0+`** (SwiftPM range `"7.0.0"..<"9.0.0"`, CocoaPods podspec included)
|
|
49
|
+
- Supported Android: **`minSdk 24`**, **Java 17** plugins (no Kotlin version conflicts between Cap 7 and Cap 8)
|
|
50
|
+
|
|
51
|
+
### 2. Native Firebase Analytics & iOS `first_open` (Google Ads)
|
|
52
|
+
|
|
53
|
+
**Minimal install-only setup (zero React/JS event code needed):**
|
|
54
|
+
1. In Xcode (`npx cap open ios`): **File -> Add Package Dependencies...** -> `https://github.com/firebase/firebase-ios-sdk.git` -> add **`FirebaseAnalytics`** to the **`App`** target.
|
|
55
|
+
2. Add `GoogleService-Info.plist` to `ios/App/App/` with **Target Membership -> `App`** checked. Verify `BUNDLE_ID` matches Xcode `PRODUCT_BUNDLE_IDENTIFIER`.
|
|
56
|
+
3. In `ios/App/App/AppDelegate.swift`, call `FirebaseApp.configure()` inside `application(_:didFinishLaunchingWithOptions:)`:
|
|
57
|
+
```swift
|
|
58
|
+
import FirebaseCore
|
|
59
|
+
// inside didFinishLaunchingWithOptions:
|
|
60
|
+
FirebaseApp.configure()
|
|
61
|
+
```
|
|
62
|
+
*(If `AppDelegate` already configures Firebase, `SimaFirebasePlugin.load()` is a safe no-op. If omitted, `SimaFirebasePlugin.load()` configures the default app when `GoogleService-Info.plist` is bundled.)*
|
|
63
|
+
4. On Android: place `google-services.json` in `android/app/`, apply `com.google.gms.google-services`, and add `platform('com.google.firebase:firebase-bom:35.2.0')` + `com.google.firebase:firebase-analytics` in `android/app/build.gradle`.
|
|
64
|
+
|
|
65
|
+
**Custom events (React & outside React):**
|
|
66
|
+
```ts
|
|
67
|
+
// src/sima.ts
|
|
68
|
+
import { createSima } from '@cond/simasdk';
|
|
69
|
+
import { firebaseAnalytics } from '@cond/simasdk/firebase';
|
|
70
|
+
|
|
71
|
+
export const sima = createSima({
|
|
72
|
+
analytics: firebaseAnalytics(),
|
|
73
|
+
onError: (err) => console.warn('[simasdk]', err.code, err.message),
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
// Wrap app root once (StrictMode-safe pure Context provider)
|
|
79
|
+
<SimaProvider client={sima}>
|
|
80
|
+
<App />
|
|
81
|
+
</SimaProvider>
|
|
82
|
+
|
|
83
|
+
// Inside components
|
|
84
|
+
const { track } = useSima();
|
|
85
|
+
await exportPhoto();
|
|
86
|
+
await track('photo_exported', { format: 'jpeg', width: 1920 });
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Start with analytics disabled prior to user consent:**
|
|
90
|
+
- Do **not** rely on calling `sima.setAnalyticsCollectionEnabled(false)` from JS after launch—it cannot undo startup `first_open`.
|
|
91
|
+
- Instead set:
|
|
92
|
+
- iOS `Info.plist`: `<key>FIREBASE_ANALYTICS_COLLECTION_ENABLED</key><false/>`
|
|
93
|
+
- Android `AndroidManifest.xml`: `<meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />`
|
|
94
|
+
- Then call `await sima.setAnalyticsCollectionEnabled(true)` after consent is granted.
|
|
95
|
+
|
|
96
|
+
### 3. In-App Review Policy (`@cond/simasdk/review`)
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { createReviewPolicy } from '@cond/simasdk/review';
|
|
100
|
+
|
|
101
|
+
export const exportReview = createReviewPolicy({
|
|
102
|
+
key: 'successful_exports',
|
|
103
|
+
minimumActions: 3,
|
|
104
|
+
cooldownDays: 90,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Call ONLY after a successful product action (never from a "Rate Us" button)
|
|
108
|
+
const result = await exportReview.recordSuccess();
|
|
109
|
+
// status: 'not_eligible' | 'cooldown' | 'requested' | 'unsupported' | 'failed'
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
- Concurrent calls on the same `key` are serialized (at most 1 native request).
|
|
113
|
+
- Failed native calls persist `actionCount` but **do not** start cooldown.
|
|
114
|
+
- `'requested'` means the OS API was invoked; never assume the OS showed a prompt or that the user rated the app.
|
|
115
|
+
|
|
116
|
+
### 4. Android Back Button Stack (`@cond/simasdk/back-button` + `@cond/simasdk/react`)
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import {
|
|
120
|
+
attachCapacitorBackButton,
|
|
121
|
+
createDoubleBackExit,
|
|
122
|
+
registerBackHandler,
|
|
123
|
+
} from '@cond/simasdk/back-button';
|
|
124
|
+
|
|
125
|
+
await attachCapacitorBackButton();
|
|
126
|
+
registerBackHandler(
|
|
127
|
+
createDoubleBackExit({ windowMs: 2000, onFirstPress: () => showToast('Press back again to exit') }),
|
|
128
|
+
{ priority: 0 },
|
|
129
|
+
);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
In React modals/sheets:
|
|
133
|
+
```tsx
|
|
134
|
+
import { useBackHandler } from '@cond/simasdk/react';
|
|
135
|
+
|
|
136
|
+
useBackHandler(() => {
|
|
137
|
+
closeSheet();
|
|
138
|
+
return true;
|
|
139
|
+
}, { enabled: isOpen, priority: 100 });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 5. Haptics, Shell, Storage, and AdMob Policy
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
// Haptics (persisted on/off toggle, zero-throw web no-op)
|
|
146
|
+
import { createHaptics } from '@cond/simasdk/haptics';
|
|
147
|
+
export const haptics = createHaptics();
|
|
148
|
+
await haptics.light();
|
|
149
|
+
await haptics.success();
|
|
150
|
+
|
|
151
|
+
// Native Shell Bootstrap (only touches installed @capacitor/* plugins)
|
|
152
|
+
import { initShell } from '@cond/simasdk/shell';
|
|
153
|
+
await initShell({ statusBarStyle: 'dark', orientation: 'portrait', hideSplash: true });
|
|
154
|
+
|
|
155
|
+
// Versioned Native Storage (UserDefaults / SharedPreferences / localStorage)
|
|
156
|
+
import { createStorage } from '@cond/simasdk/storage';
|
|
157
|
+
export const settingsStore = createStorage({ namespace: 'settings', version: 1 });
|
|
158
|
+
await settingsStore.set('sound', true);
|
|
159
|
+
|
|
160
|
+
// Opt-in AdMob Interstitial / Rewarded Policy (lazy @capacitor-community/admob bridge)
|
|
161
|
+
import { createAdPolicy } from '@cond/simasdk/ads';
|
|
162
|
+
export const levelAds = createAdPolicy({
|
|
163
|
+
key: 'level_complete',
|
|
164
|
+
interstitialAdId: { ios: 'ca-app-pub-ios', android: 'ca-app-pub-android' },
|
|
165
|
+
minActionsBeforeFirst: 2,
|
|
166
|
+
actionsBetweenAds: 3,
|
|
167
|
+
cooldownSeconds: 90,
|
|
168
|
+
disabled: () => isProUser(),
|
|
169
|
+
});
|
|
170
|
+
await levelAds.recordActionAndMaybeShow();
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Verification & Debugging Checklist
|
|
176
|
+
|
|
177
|
+
1. **Automated project audit:** Run `npx simasdk doctor` (or `npx simasdk doctor --json`) to check Capacitor version compatibility, iOS plugin sync, `GoogleService-Info.plist` Bundle ID & Target Membership, `FirebaseApp.configure()`, and Android Gradle/manifest config.
|
|
178
|
+
2. **Scaffold starter file:** Run `npx simasdk init --firebase --review --haptics --storage --back-button --shell` (or `--all`) to create `src/sima.ts`.
|
|
179
|
+
3. **Plugin discovery:** After `npx cap sync ios`, confirm `ios/App/App/capacitor.config.json` includes `SimaFirebasePlugin`, `SimaReviewPlugin`, `SimaHapticsPlugin`, and `SimaStoragePlugin`.
|
|
180
|
+
2. **Firebase DebugView (iOS):** Add `-FIRDebugEnabled` to Xcode Scheme -> Run -> Arguments, reinstall the app on a device/simulator, and confirm `first_open` appears in **Firebase Console -> Analytics -> DebugView**.
|
|
181
|
+
3. **Google Ads iOS `first_open`:** Ensure **App Store ID** is set in Firebase Project Settings -> iOS app, the correct GA4 property is linked in **Google Ads -> Data Manager -> Google Analytics (GA4) & Firebase**, and the **iOS** stream's `first_open` (not Android's) is imported under **Goals -> Conversions** as **Primary**.
|
|
182
|
+
4. **Never commit secrets:** Keep `GoogleService-Info.plist` and `google-services.json` out of public git repositories.
|
|
183
|
+
|
|
184
|
+
## Common Mistakes to Avoid
|
|
185
|
+
|
|
186
|
+
- Calling `review.recordSuccess()` on a "Rate Us" button in Settings (violates Apple HIG; use an App Store `?action=write-review` URL instead).
|
|
187
|
+
- Passing boolean values in `sima.track(event, { is_pro: true })` — use strings or numbers (`{ plan: 'pro' }` or `{ is_pro: 1 }`).
|
|
188
|
+
- Checking `track()` only in a browser preview and assuming native Firebase works — browser always returns `ignored_web`; verify on a native iOS/Android build where missing config returns `NATIVE_NOT_CONFIGURED`.
|
|
189
|
+
- Assuming DebugView visibility means Google Ads is ready — DebugView traffic is excluded from production GA4/Google Ads reports; run a non-debug install and allow 24–72 hours for iOS conversion sync.
|