@microsurveysai/react-native 0.1.0 → 0.1.1
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/README.md +1 -0
- package/dist/index.cjs +42 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +42 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ import { MicroSurvey } from "@microsurveysai/react-native";
|
|
|
62
62
|
| `refreshOnForeground` | `true` | On app foreground, retry queued ingest and refresh a stale config. |
|
|
63
63
|
| `configTTLms` | 12h | How long the cached config counts as fresh. |
|
|
64
64
|
| `storage` | AsyncStorage | A synchronous store (e.g. MMKV) to persist into instead. |
|
|
65
|
+
| `appVersion` | — | Your app's version (e.g. `"3.2.0"`), sent with responses so results can be compared across releases. With Expo, pass `Application.nativeApplicationVersion` from `expo-application`. |
|
|
65
66
|
|
|
66
67
|
`<MicroSurveysProvider>` also takes `autoStart` (default `true`) and `fontFamily` (a font your app
|
|
67
68
|
registered, e.g. with `expo-font`; surveys use the system font otherwise).
|
package/dist/index.cjs
CHANGED
|
@@ -246,16 +246,21 @@ var ApiClient = class {
|
|
|
246
246
|
return { kind: "config", rawText, config: parseConfig(rawText), etag: res.headers.get("ETag") };
|
|
247
247
|
}
|
|
248
248
|
// ── Impressions / responses ─────────────────────────────────────────────────
|
|
249
|
+
/** Queues the impression and returns its `clientId`, so the response from the
|
|
250
|
+
* same showing can point back to it. */
|
|
249
251
|
recordImpression(input) {
|
|
252
|
+
const clientId = uuid();
|
|
250
253
|
const payload = {
|
|
251
|
-
clientId
|
|
254
|
+
clientId,
|
|
252
255
|
surveyId: input.surveyId,
|
|
253
256
|
triggerId: input.triggerId ?? void 0,
|
|
254
257
|
endUserId: input.endUserId,
|
|
255
258
|
shownAt: input.shownAt.toISOString(),
|
|
256
|
-
dismissed: input.dismissed
|
|
259
|
+
dismissed: input.dismissed,
|
|
260
|
+
context: input.context
|
|
257
261
|
};
|
|
258
262
|
this.enqueue("/api/sdk/impressions", { impressions: [payload] });
|
|
263
|
+
return clientId;
|
|
259
264
|
}
|
|
260
265
|
recordResponse(input) {
|
|
261
266
|
const payload = {
|
|
@@ -265,6 +270,9 @@ var ApiClient = class {
|
|
|
265
270
|
completed: input.completed,
|
|
266
271
|
submittedAt: input.submittedAt.toISOString(),
|
|
267
272
|
userProps: input.userProps,
|
|
273
|
+
impressionId: input.impressionId,
|
|
274
|
+
triggerId: input.triggerId ?? void 0,
|
|
275
|
+
context: input.context,
|
|
268
276
|
answers: input.answers
|
|
269
277
|
};
|
|
270
278
|
this.enqueue("/api/sdk/responses", { responses: [payload] });
|
|
@@ -699,6 +707,9 @@ var MicroSurveysClient = class {
|
|
|
699
707
|
__publicField(this, "engine");
|
|
700
708
|
__publicField(this, "configTTLms");
|
|
701
709
|
__publicField(this, "refreshOnForeground");
|
|
710
|
+
__publicField(this, "platform");
|
|
711
|
+
__publicField(this, "osVersion");
|
|
712
|
+
__publicField(this, "appVersion");
|
|
702
713
|
__publicField(this, "subscribeForeground");
|
|
703
714
|
__publicField(this, "presentListeners", /* @__PURE__ */ new Set());
|
|
704
715
|
__publicField(this, "configListeners", /* @__PURE__ */ new Set());
|
|
@@ -712,6 +723,9 @@ var MicroSurveysClient = class {
|
|
|
712
723
|
this.api = new ApiClient(opts.apiKey, opts.apiBaseURL ?? DEFAULT_BASE_URL, kv);
|
|
713
724
|
this.configTTLms = opts.configTTLms ?? DEFAULT_CONFIG_TTL_MS;
|
|
714
725
|
this.refreshOnForeground = opts.refreshOnForeground ?? true;
|
|
726
|
+
this.platform = opts.platform;
|
|
727
|
+
this.osVersion = opts.osVersion;
|
|
728
|
+
this.appVersion = opts.appVersion;
|
|
715
729
|
this.subscribeForeground = opts.subscribeForeground;
|
|
716
730
|
this.engine = new TriggerEngine({
|
|
717
731
|
store: this.triggerStateStore,
|
|
@@ -819,7 +833,15 @@ var MicroSurveysClient = class {
|
|
|
819
833
|
}
|
|
820
834
|
recordOutcome(surveyId, triggerId, identity, shownAt, result) {
|
|
821
835
|
const endUserId = endUserIdOf(identity);
|
|
822
|
-
|
|
836
|
+
const context = this.deviceContext();
|
|
837
|
+
const impressionId = this.api.recordImpression({
|
|
838
|
+
surveyId,
|
|
839
|
+
triggerId,
|
|
840
|
+
endUserId,
|
|
841
|
+
shownAt,
|
|
842
|
+
dismissed: result.dismissed,
|
|
843
|
+
context
|
|
844
|
+
});
|
|
823
845
|
if (result.completed || result.answers.length > 0) {
|
|
824
846
|
this.api.recordResponse({
|
|
825
847
|
surveyId,
|
|
@@ -827,10 +849,23 @@ var MicroSurveysClient = class {
|
|
|
827
849
|
completed: result.completed,
|
|
828
850
|
submittedAt: /* @__PURE__ */ new Date(),
|
|
829
851
|
userProps: identity.userProperties,
|
|
852
|
+
impressionId,
|
|
853
|
+
triggerId,
|
|
854
|
+
context,
|
|
830
855
|
answers: result.answers
|
|
831
856
|
});
|
|
832
857
|
}
|
|
833
858
|
}
|
|
859
|
+
/** Where this showing happened. The language is read at record time: the user
|
|
860
|
+
* can change it while the app runs. */
|
|
861
|
+
deviceContext() {
|
|
862
|
+
let locale;
|
|
863
|
+
try {
|
|
864
|
+
locale = Intl.DateTimeFormat().resolvedOptions().locale || void 0;
|
|
865
|
+
} catch {
|
|
866
|
+
}
|
|
867
|
+
return { platform: this.platform, appVersion: this.appVersion, osVersion: this.osVersion, locale };
|
|
868
|
+
}
|
|
834
869
|
};
|
|
835
870
|
function createClient(opts) {
|
|
836
871
|
return new MicroSurveysClient(opts);
|
|
@@ -931,6 +966,8 @@ var MicroSurveys = class {
|
|
|
931
966
|
refreshOnForeground: opts.refreshOnForeground ?? true,
|
|
932
967
|
// Survey platform targeting: "ios" | "android".
|
|
933
968
|
platform: import_react_native.Platform.OS,
|
|
969
|
+
osVersion: String(import_react_native.Platform.Version),
|
|
970
|
+
appVersion: opts.appVersion,
|
|
934
971
|
storage: kv,
|
|
935
972
|
subscribeForeground: appStateForeground
|
|
936
973
|
});
|
|
@@ -1823,8 +1860,8 @@ var styles4 = import_react_native6.StyleSheet.create({
|
|
|
1823
1860
|
// src/provider.tsx
|
|
1824
1861
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1825
1862
|
var MicroSurveysContext = (0, import_react4.createContext)({ instance: null });
|
|
1826
|
-
function MicroSurveysProvider({ apiKey, apiBaseURL, instance, autoStart = true, fontFamily, children }) {
|
|
1827
|
-
const [owned] = (0, import_react4.useState)(() => !instance && apiKey ? new MicroSurveys({ apiKey, apiBaseURL }) : null);
|
|
1863
|
+
function MicroSurveysProvider({ apiKey, apiBaseURL, appVersion, instance, autoStart = true, fontFamily, children }) {
|
|
1864
|
+
const [owned] = (0, import_react4.useState)(() => !instance && apiKey ? new MicroSurveys({ apiKey, apiBaseURL, appVersion }) : null);
|
|
1828
1865
|
const ms = instance ?? owned;
|
|
1829
1866
|
(0, import_react4.useEffect)(() => {
|
|
1830
1867
|
if (!ms || !autoStart) return;
|