@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/dist/index.d.cts CHANGED
@@ -176,6 +176,11 @@ interface CreateClientOptions {
176
176
  refreshOnForeground?: boolean;
177
177
  /** This device's platform for survey targeting ("ios" | "android"). */
178
178
  platform: string;
179
+ /** The OS version, sent with responses. */
180
+ osVersion?: string;
181
+ /** The host app's version, sent with responses so results can be compared
182
+ * across releases. */
183
+ appVersion?: string;
179
184
  /** Where config, identity, trigger state and the outbox persist. Must already
180
185
  * hold its data when the client is created. */
181
186
  storage: KeyValueStorage;
@@ -199,6 +204,9 @@ declare class MicroSurveysClient {
199
204
  private readonly engine;
200
205
  private readonly configTTLms;
201
206
  private readonly refreshOnForeground;
207
+ private readonly platform;
208
+ private readonly osVersion;
209
+ private readonly appVersion;
202
210
  private readonly subscribeForeground;
203
211
  private readonly presentListeners;
204
212
  private readonly configListeners;
@@ -233,6 +241,9 @@ declare class MicroSurveysClient {
233
241
  /** Records the outcome of an **inline** `<MicroSurvey>` (no trigger/gate). */
234
242
  recordInline(survey: Survey, result: SurveyResult, shownAt: Date): void;
235
243
  private recordOutcome;
244
+ /** Where this showing happened. The language is read at record time: the user
245
+ * can change it while the app runs. */
246
+ private deviceContext;
236
247
  }
237
248
 
238
249
  /** The fields of an Amplitude event this plugin reads. */
@@ -284,6 +295,9 @@ interface MicroSurveysOptions {
284
295
  storage?: KeyValueStorage;
285
296
  /** An async store to persist into. Defaults to `@react-native-async-storage/async-storage`. */
286
297
  asyncStorage?: AsyncKeyValueStorage;
298
+ /** Your app's version (e.g. "3.2.0"), sent with responses so results can be
299
+ * compared across releases. With Expo: `Application.nativeApplicationVersion`. */
300
+ appVersion?: string;
287
301
  }
288
302
  declare class MicroSurveys {
289
303
  readonly apiKey: string;
@@ -330,6 +344,8 @@ interface MicroSurveysProviderProps {
330
344
  apiKey?: string;
331
345
  /** Override the API base for self-hosted deployments. Ignored when `instance` is passed. */
332
346
  apiBaseURL?: string;
347
+ /** Your app's version (e.g. "3.2.0"), sent with responses. Ignored when `instance` is passed. */
348
+ appVersion?: string;
333
349
  /** A `MicroSurveys` you created yourself, e.g. to register its Amplitude plugin. */
334
350
  instance?: MicroSurveys;
335
351
  /** Start automatically on mount (load config, flush queued ingest). Default true. */
@@ -339,7 +355,7 @@ interface MicroSurveysProviderProps {
339
355
  fontFamily?: string;
340
356
  children?: ReactNode;
341
357
  }
342
- declare function MicroSurveysProvider({ apiKey, apiBaseURL, instance, autoStart, fontFamily, children }: MicroSurveysProviderProps): react.JSX.Element;
358
+ declare function MicroSurveysProvider({ apiKey, apiBaseURL, appVersion, instance, autoStart, fontFamily, children }: MicroSurveysProviderProps): react.JSX.Element;
343
359
  /** The `MicroSurveys` instance from the nearest provider (or null outside one). */
344
360
  declare function useMicroSurveysInstance(): MicroSurveys | null;
345
361
  /** Event + identity helpers bound to the provider's instance. Safe no-ops
package/dist/index.d.ts CHANGED
@@ -176,6 +176,11 @@ interface CreateClientOptions {
176
176
  refreshOnForeground?: boolean;
177
177
  /** This device's platform for survey targeting ("ios" | "android"). */
178
178
  platform: string;
179
+ /** The OS version, sent with responses. */
180
+ osVersion?: string;
181
+ /** The host app's version, sent with responses so results can be compared
182
+ * across releases. */
183
+ appVersion?: string;
179
184
  /** Where config, identity, trigger state and the outbox persist. Must already
180
185
  * hold its data when the client is created. */
181
186
  storage: KeyValueStorage;
@@ -199,6 +204,9 @@ declare class MicroSurveysClient {
199
204
  private readonly engine;
200
205
  private readonly configTTLms;
201
206
  private readonly refreshOnForeground;
207
+ private readonly platform;
208
+ private readonly osVersion;
209
+ private readonly appVersion;
202
210
  private readonly subscribeForeground;
203
211
  private readonly presentListeners;
204
212
  private readonly configListeners;
@@ -233,6 +241,9 @@ declare class MicroSurveysClient {
233
241
  /** Records the outcome of an **inline** `<MicroSurvey>` (no trigger/gate). */
234
242
  recordInline(survey: Survey, result: SurveyResult, shownAt: Date): void;
235
243
  private recordOutcome;
244
+ /** Where this showing happened. The language is read at record time: the user
245
+ * can change it while the app runs. */
246
+ private deviceContext;
236
247
  }
237
248
 
238
249
  /** The fields of an Amplitude event this plugin reads. */
@@ -284,6 +295,9 @@ interface MicroSurveysOptions {
284
295
  storage?: KeyValueStorage;
285
296
  /** An async store to persist into. Defaults to `@react-native-async-storage/async-storage`. */
286
297
  asyncStorage?: AsyncKeyValueStorage;
298
+ /** Your app's version (e.g. "3.2.0"), sent with responses so results can be
299
+ * compared across releases. With Expo: `Application.nativeApplicationVersion`. */
300
+ appVersion?: string;
287
301
  }
288
302
  declare class MicroSurveys {
289
303
  readonly apiKey: string;
@@ -330,6 +344,8 @@ interface MicroSurveysProviderProps {
330
344
  apiKey?: string;
331
345
  /** Override the API base for self-hosted deployments. Ignored when `instance` is passed. */
332
346
  apiBaseURL?: string;
347
+ /** Your app's version (e.g. "3.2.0"), sent with responses. Ignored when `instance` is passed. */
348
+ appVersion?: string;
333
349
  /** A `MicroSurveys` you created yourself, e.g. to register its Amplitude plugin. */
334
350
  instance?: MicroSurveys;
335
351
  /** Start automatically on mount (load config, flush queued ingest). Default true. */
@@ -339,7 +355,7 @@ interface MicroSurveysProviderProps {
339
355
  fontFamily?: string;
340
356
  children?: ReactNode;
341
357
  }
342
- declare function MicroSurveysProvider({ apiKey, apiBaseURL, instance, autoStart, fontFamily, children }: MicroSurveysProviderProps): react.JSX.Element;
358
+ declare function MicroSurveysProvider({ apiKey, apiBaseURL, appVersion, instance, autoStart, fontFamily, children }: MicroSurveysProviderProps): react.JSX.Element;
343
359
  /** The `MicroSurveys` instance from the nearest provider (or null outside one). */
344
360
  declare function useMicroSurveysInstance(): MicroSurveys | null;
345
361
  /** Event + identity helpers bound to the provider's instance. Safe no-ops
package/dist/index.js CHANGED
@@ -205,16 +205,21 @@ var ApiClient = class {
205
205
  return { kind: "config", rawText, config: parseConfig(rawText), etag: res.headers.get("ETag") };
206
206
  }
207
207
  // ── Impressions / responses ─────────────────────────────────────────────────
208
+ /** Queues the impression and returns its `clientId`, so the response from the
209
+ * same showing can point back to it. */
208
210
  recordImpression(input) {
211
+ const clientId = uuid();
209
212
  const payload = {
210
- clientId: uuid(),
213
+ clientId,
211
214
  surveyId: input.surveyId,
212
215
  triggerId: input.triggerId ?? void 0,
213
216
  endUserId: input.endUserId,
214
217
  shownAt: input.shownAt.toISOString(),
215
- dismissed: input.dismissed
218
+ dismissed: input.dismissed,
219
+ context: input.context
216
220
  };
217
221
  this.enqueue("/api/sdk/impressions", { impressions: [payload] });
222
+ return clientId;
218
223
  }
219
224
  recordResponse(input) {
220
225
  const payload = {
@@ -224,6 +229,9 @@ var ApiClient = class {
224
229
  completed: input.completed,
225
230
  submittedAt: input.submittedAt.toISOString(),
226
231
  userProps: input.userProps,
232
+ impressionId: input.impressionId,
233
+ triggerId: input.triggerId ?? void 0,
234
+ context: input.context,
227
235
  answers: input.answers
228
236
  };
229
237
  this.enqueue("/api/sdk/responses", { responses: [payload] });
@@ -658,6 +666,9 @@ var MicroSurveysClient = class {
658
666
  __publicField(this, "engine");
659
667
  __publicField(this, "configTTLms");
660
668
  __publicField(this, "refreshOnForeground");
669
+ __publicField(this, "platform");
670
+ __publicField(this, "osVersion");
671
+ __publicField(this, "appVersion");
661
672
  __publicField(this, "subscribeForeground");
662
673
  __publicField(this, "presentListeners", /* @__PURE__ */ new Set());
663
674
  __publicField(this, "configListeners", /* @__PURE__ */ new Set());
@@ -671,6 +682,9 @@ var MicroSurveysClient = class {
671
682
  this.api = new ApiClient(opts.apiKey, opts.apiBaseURL ?? DEFAULT_BASE_URL, kv);
672
683
  this.configTTLms = opts.configTTLms ?? DEFAULT_CONFIG_TTL_MS;
673
684
  this.refreshOnForeground = opts.refreshOnForeground ?? true;
685
+ this.platform = opts.platform;
686
+ this.osVersion = opts.osVersion;
687
+ this.appVersion = opts.appVersion;
674
688
  this.subscribeForeground = opts.subscribeForeground;
675
689
  this.engine = new TriggerEngine({
676
690
  store: this.triggerStateStore,
@@ -778,7 +792,15 @@ var MicroSurveysClient = class {
778
792
  }
779
793
  recordOutcome(surveyId, triggerId, identity, shownAt, result) {
780
794
  const endUserId = endUserIdOf(identity);
781
- this.api.recordImpression({ surveyId, triggerId, endUserId, shownAt, dismissed: result.dismissed });
795
+ const context = this.deviceContext();
796
+ const impressionId = this.api.recordImpression({
797
+ surveyId,
798
+ triggerId,
799
+ endUserId,
800
+ shownAt,
801
+ dismissed: result.dismissed,
802
+ context
803
+ });
782
804
  if (result.completed || result.answers.length > 0) {
783
805
  this.api.recordResponse({
784
806
  surveyId,
@@ -786,10 +808,23 @@ var MicroSurveysClient = class {
786
808
  completed: result.completed,
787
809
  submittedAt: /* @__PURE__ */ new Date(),
788
810
  userProps: identity.userProperties,
811
+ impressionId,
812
+ triggerId,
813
+ context,
789
814
  answers: result.answers
790
815
  });
791
816
  }
792
817
  }
818
+ /** Where this showing happened. The language is read at record time: the user
819
+ * can change it while the app runs. */
820
+ deviceContext() {
821
+ let locale;
822
+ try {
823
+ locale = Intl.DateTimeFormat().resolvedOptions().locale || void 0;
824
+ } catch {
825
+ }
826
+ return { platform: this.platform, appVersion: this.appVersion, osVersion: this.osVersion, locale };
827
+ }
793
828
  };
794
829
  function createClient(opts) {
795
830
  return new MicroSurveysClient(opts);
@@ -890,6 +925,8 @@ var MicroSurveys = class {
890
925
  refreshOnForeground: opts.refreshOnForeground ?? true,
891
926
  // Survey platform targeting: "ios" | "android".
892
927
  platform: Platform.OS,
928
+ osVersion: String(Platform.Version),
929
+ appVersion: opts.appVersion,
893
930
  storage: kv,
894
931
  subscribeForeground: appStateForeground
895
932
  });
@@ -1795,8 +1832,8 @@ var styles4 = StyleSheet4.create({
1795
1832
  // src/provider.tsx
1796
1833
  import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
1797
1834
  var MicroSurveysContext = createContext({ instance: null });
1798
- function MicroSurveysProvider({ apiKey, apiBaseURL, instance, autoStart = true, fontFamily, children }) {
1799
- const [owned] = useState4(() => !instance && apiKey ? new MicroSurveys({ apiKey, apiBaseURL }) : null);
1835
+ function MicroSurveysProvider({ apiKey, apiBaseURL, appVersion, instance, autoStart = true, fontFamily, children }) {
1836
+ const [owned] = useState4(() => !instance && apiKey ? new MicroSurveys({ apiKey, apiBaseURL, appVersion }) : null);
1800
1837
  const ms = instance ?? owned;
1801
1838
  useEffect3(() => {
1802
1839
  if (!ms || !autoStart) return;