@supermetry/react-native 0.1.0 → 0.2.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/README.md +3 -4
- package/dist/client.d.ts +5 -3
- package/dist/index.cjs +3 -4
- package/dist/index.js +3 -4
- package/dist/platform.d.ts +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,8 +19,7 @@ import { SupermetryProvider, createSupermetry, trackNavigation, useSupermetry }
|
|
|
19
19
|
|
|
20
20
|
const supermetry = createSupermetry({
|
|
21
21
|
site: "your-site-id",
|
|
22
|
-
|
|
23
|
-
appUrl: "https://app.example.com", // must be an allowed host of the site
|
|
22
|
+
appUrl: "https://app.supermetry.com", // must be an allowed host of the site
|
|
24
23
|
storage: AsyncStorage,
|
|
25
24
|
});
|
|
26
25
|
|
|
@@ -48,7 +47,7 @@ function CheckoutButton() {
|
|
|
48
47
|
|
|
49
48
|
## API
|
|
50
49
|
|
|
51
|
-
- `createSupermetry(options)` → client. Options: `site`, `
|
|
50
|
+
- `createSupermetry(options)` → client. Options: `site`, `appUrl` (required), `host` (defaults to `https://app.supermetry.com`; set it when self-hosting), `endpoint`, `storage`, `disabled`, `onError`, `fetch`, `userAgent`, `maxQueueSize` (500), `maxAttempts` (10), `retryDelay` (1000 ms), `maxRetryDelay` (60000 ms), `storagePrefix` (`"supermetry:"`).
|
|
52
51
|
- `screen(name, props?)` sends a `pageview` for `appUrl + "/" + slug(name)` (`"Product Details"` → `/product-details`, `"Settings/Edit Profile"` → `/settings/edit-profile`) and makes it the current screen.
|
|
53
52
|
- `pageview(urlOrPath?, props?)` sends a pageview for an absolute URL or a path under `appUrl`.
|
|
54
53
|
- `track(name, props?, { revenue?, url? })`: custom event, URL defaults to the current screen.
|
|
@@ -59,7 +58,7 @@ function CheckoutButton() {
|
|
|
59
58
|
|
|
60
59
|
## Behaviour
|
|
61
60
|
|
|
62
|
-
- **User-Agent**: a browser-shaped UA built from `Platform` so the server detects OS and device, e.g. `Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) Supermetry-ReactNative/0.
|
|
61
|
+
- **User-Agent**: a browser-shaped UA built from `Platform` so the server detects OS and device, e.g. `Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) Supermetry-ReactNative/0.2.0` or `Mozilla/5.0 (Linux; Android 14; Pixel 8) Supermetry-ReactNative/0.2.0`.
|
|
63
62
|
- `screen_width` comes from `Dimensions.get("window").width`.
|
|
64
63
|
- **Delivery**: events go to an in-memory queue and are sent in order. Network errors, 429 and 5xx are retried with exponential backoff (honouring `Retry-After`) and the same `id`/`ts`, so the server deduplicates; `400` drops the event. When the app goes to the background the queue is flushed and anything undelivered is written to `storage`, then restored on the next launch. Events older than 24 h are discarded.
|
|
65
64
|
- Props are capped at 30 string/number/boolean values; invalid traits are dropped locally; traits are only ever sent on `identify`.
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { VERSION } from "./platform";
|
|
2
2
|
import { type PropValue, type Props, type Revenue, type Traits } from "./validate";
|
|
3
3
|
export declare const EVENTS_PATH = "/api/public/v1/events";
|
|
4
|
+
/** Supermetry Cloud, used when `host` is omitted. */
|
|
5
|
+
export declare const DEFAULT_HOST = "https://app.supermetry.com";
|
|
4
6
|
/** Async key/value storage; `@react-native-async-storage/async-storage` fits as-is. */
|
|
5
7
|
export interface SupermetryStorage {
|
|
6
8
|
getItem(key: string): Promise<string | null>;
|
|
@@ -27,9 +29,9 @@ export interface EventPayload {
|
|
|
27
29
|
export interface SupermetryReactNativeOptions {
|
|
28
30
|
/** Public site ID. */
|
|
29
31
|
site: string;
|
|
30
|
-
/** Supermetry origin
|
|
31
|
-
host
|
|
32
|
-
/** Base URL for screens, e.g. `https://app.
|
|
32
|
+
/** Supermetry origin. Defaults to Supermetry Cloud (`https://app.supermetry.com`); set it when self-hosting. */
|
|
33
|
+
host?: string;
|
|
34
|
+
/** Base URL for screens, e.g. `https://app.supermetry.com`. Its host must be an allowed host of the site. */
|
|
33
35
|
appUrl: string;
|
|
34
36
|
/** Full events endpoint; defaults to `host + "/api/public/v1/events"`. */
|
|
35
37
|
endpoint?: string;
|
package/dist/index.cjs
CHANGED
|
@@ -56,7 +56,7 @@ var import_react_native2 = require("react-native");
|
|
|
56
56
|
|
|
57
57
|
// src/platform.ts
|
|
58
58
|
var import_react_native = require("react-native");
|
|
59
|
-
var VERSION = "0.
|
|
59
|
+
var VERSION = "0.2.0";
|
|
60
60
|
var SUFFIX = `Supermetry-ReactNative/${VERSION}`;
|
|
61
61
|
function clean(value) {
|
|
62
62
|
return typeof value === "string" ? value.replace(/[;()\r\n]/g, " ").replace(/\s+/g, " ").trim() : "";
|
|
@@ -216,6 +216,7 @@ function sanitizeRevenue(revenue) {
|
|
|
216
216
|
|
|
217
217
|
// src/client.ts
|
|
218
218
|
var EVENTS_PATH = "/api/public/v1/events";
|
|
219
|
+
var DEFAULT_HOST = "https://app.supermetry.com";
|
|
219
220
|
var MAX_AGE_MS = 24 * 60 * 60 * 1000 - 60000;
|
|
220
221
|
function newEventId() {
|
|
221
222
|
const bytes = new Uint8Array(16);
|
|
@@ -267,13 +268,11 @@ class Client {
|
|
|
267
268
|
constructor(options) {
|
|
268
269
|
if (!options?.site)
|
|
269
270
|
throw new TypeError("@supermetry/react-native: `site` is required");
|
|
270
|
-
if (!options.host && !options.endpoint)
|
|
271
|
-
throw new TypeError("@supermetry/react-native: `host` is required");
|
|
272
271
|
if (!validEventUrl(options.appUrl)) {
|
|
273
272
|
throw new TypeError("@supermetry/react-native: `appUrl` must be an absolute http(s) URL");
|
|
274
273
|
}
|
|
275
274
|
this.options = options;
|
|
276
|
-
this.endpoint = options.endpoint ?? options.host.replace(/\/+$/, "") + EVENTS_PATH;
|
|
275
|
+
this.endpoint = options.endpoint ?? (options.host || DEFAULT_HOST).replace(/\/+$/, "") + EVENTS_PATH;
|
|
277
276
|
this.appUrl = options.appUrl.replace(/\/+$/, "");
|
|
278
277
|
this.userAgent = options.userAgent ?? buildUserAgent();
|
|
279
278
|
const prefix = options.storagePrefix ?? "supermetry:";
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { AppState } from "react-native";
|
|
|
3
3
|
|
|
4
4
|
// src/platform.ts
|
|
5
5
|
import { Dimensions, Platform } from "react-native";
|
|
6
|
-
var VERSION = "0.
|
|
6
|
+
var VERSION = "0.2.0";
|
|
7
7
|
var SUFFIX = `Supermetry-ReactNative/${VERSION}`;
|
|
8
8
|
function clean(value) {
|
|
9
9
|
return typeof value === "string" ? value.replace(/[;()\r\n]/g, " ").replace(/\s+/g, " ").trim() : "";
|
|
@@ -163,6 +163,7 @@ function sanitizeRevenue(revenue) {
|
|
|
163
163
|
|
|
164
164
|
// src/client.ts
|
|
165
165
|
var EVENTS_PATH = "/api/public/v1/events";
|
|
166
|
+
var DEFAULT_HOST = "https://app.supermetry.com";
|
|
166
167
|
var MAX_AGE_MS = 24 * 60 * 60 * 1000 - 60000;
|
|
167
168
|
function newEventId() {
|
|
168
169
|
const bytes = new Uint8Array(16);
|
|
@@ -214,13 +215,11 @@ class Client {
|
|
|
214
215
|
constructor(options) {
|
|
215
216
|
if (!options?.site)
|
|
216
217
|
throw new TypeError("@supermetry/react-native: `site` is required");
|
|
217
|
-
if (!options.host && !options.endpoint)
|
|
218
|
-
throw new TypeError("@supermetry/react-native: `host` is required");
|
|
219
218
|
if (!validEventUrl(options.appUrl)) {
|
|
220
219
|
throw new TypeError("@supermetry/react-native: `appUrl` must be an absolute http(s) URL");
|
|
221
220
|
}
|
|
222
221
|
this.options = options;
|
|
223
|
-
this.endpoint = options.endpoint ?? options.host.replace(/\/+$/, "") + EVENTS_PATH;
|
|
222
|
+
this.endpoint = options.endpoint ?? (options.host || DEFAULT_HOST).replace(/\/+$/, "") + EVENTS_PATH;
|
|
224
223
|
this.appUrl = options.appUrl.replace(/\/+$/, "");
|
|
225
224
|
this.userAgent = options.userAgent ?? buildUserAgent();
|
|
226
225
|
const prefix = options.storagePrefix ?? "supermetry:";
|
package/dist/platform.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.2.0";
|
|
2
2
|
type PlatformLike = {
|
|
3
3
|
OS: string;
|
|
4
4
|
Version: number | string;
|
|
@@ -7,7 +7,7 @@ type PlatformLike = {
|
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Browser-shaped User-Agent so the server's parser detects OS and device class,
|
|
10
|
-
* e.g. `Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) Supermetry-ReactNative/0.
|
|
10
|
+
* e.g. `Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) Supermetry-ReactNative/0.2.0`.
|
|
11
11
|
*/
|
|
12
12
|
export declare function buildUserAgent(platform?: PlatformLike): string;
|
|
13
13
|
export declare function screenWidth(): number | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supermetry/react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "React Native SDK for Supermetry self-hosted analytics",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"url": "git+https://github.com/velixio/supermetry.git",
|
|
9
9
|
"directory": "sdk/react-native"
|
|
10
10
|
},
|
|
11
|
-
"homepage": "https://
|
|
11
|
+
"homepage": "https://supermetry.com",
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/velixio/supermetry/issues"
|
|
14
14
|
},
|