@logbrew/react-native 0.1.8 → 0.1.9
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 +5 -0
- package/index.cjs +19 -1
- package/index.js +19 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,6 +71,11 @@ export async function verifyLogBrewSetup() {
|
|
|
71
71
|
}
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
+
Screen labels remain available as the original `metadata.screen` value. The
|
|
75
|
+
helper preserves an already machine-safe action name and otherwise normalizes
|
|
76
|
+
and bounds it for hosted ingestion, so labels such as `Checkout Complete` do
|
|
77
|
+
not cause a rejected batch.
|
|
78
|
+
|
|
74
79
|
For mobile apps, prefer an app-scoped public key through `clientKey`. Expo
|
|
75
80
|
inlines `EXPO_PUBLIC_*` values into the app, so never use a server key there.
|
|
76
81
|
`apiKey` is still accepted for compatibility with lower-level SDK examples.
|
package/index.cjs
CHANGED
|
@@ -16,6 +16,8 @@ const {
|
|
|
16
16
|
const DEFAULT_SDK_NAME = "logbrew-react-native";
|
|
17
17
|
const DEFAULT_SDK_VERSION = "0.1.0";
|
|
18
18
|
const DEFAULT_ENDPOINT = "https://api.logbrew.co/v1/events";
|
|
19
|
+
const MAX_ACTION_NAME_LENGTH = 64;
|
|
20
|
+
const SCREEN_ACTION_PREFIX = "screen:";
|
|
19
21
|
const BACKGROUND_APP_STATES = new Set(["background", "inactive"]);
|
|
20
22
|
const LogBrewNativeContext = React.createContext(null);
|
|
21
23
|
const activeTraceScopes = [];
|
|
@@ -294,7 +296,7 @@ function captureScreenView(client, screenName, {
|
|
|
294
296
|
requireClient(client);
|
|
295
297
|
requireNonEmpty("screen name", screenName);
|
|
296
298
|
client.action(id, timestamp, {
|
|
297
|
-
name:
|
|
299
|
+
name: screenActionName(screenName),
|
|
298
300
|
status,
|
|
299
301
|
metadata: {
|
|
300
302
|
...getReactNativeContext({ platform, appState }),
|
|
@@ -1023,6 +1025,22 @@ function slugify(value) {
|
|
|
1023
1025
|
.replace(/^_+|_+$/g, "") || "event";
|
|
1024
1026
|
}
|
|
1025
1027
|
|
|
1028
|
+
function screenActionName(screenName) {
|
|
1029
|
+
const directName = `${SCREEN_ACTION_PREFIX}${screenName}`;
|
|
1030
|
+
if (
|
|
1031
|
+
directName.length <= MAX_ACTION_NAME_LENGTH
|
|
1032
|
+
&& /^[a-z0-9_.:-]+$/i.test(directName)
|
|
1033
|
+
) {
|
|
1034
|
+
return directName;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
const maxScreenSegmentLength = MAX_ACTION_NAME_LENGTH - SCREEN_ACTION_PREFIX.length;
|
|
1038
|
+
const screenSegment = slugify(screenName)
|
|
1039
|
+
.slice(0, maxScreenSegmentLength)
|
|
1040
|
+
.replace(/_+$/g, "") || "event";
|
|
1041
|
+
return `${SCREEN_ACTION_PREFIX}${screenSegment}`;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1026
1044
|
function statusFromStatusCode(statusCode) {
|
|
1027
1045
|
if (typeof statusCode === "number" && Number.isFinite(statusCode) && statusCode >= 400) {
|
|
1028
1046
|
return "failure";
|
package/index.js
CHANGED
|
@@ -16,6 +16,8 @@ import {
|
|
|
16
16
|
const DEFAULT_SDK_NAME = "logbrew-react-native";
|
|
17
17
|
const DEFAULT_SDK_VERSION = "0.1.0";
|
|
18
18
|
const DEFAULT_ENDPOINT = "https://api.logbrew.co/v1/events";
|
|
19
|
+
const MAX_ACTION_NAME_LENGTH = 64;
|
|
20
|
+
const SCREEN_ACTION_PREFIX = "screen:";
|
|
19
21
|
const BACKGROUND_APP_STATES = new Set(["background", "inactive"]);
|
|
20
22
|
const LogBrewNativeContext = React.createContext(null);
|
|
21
23
|
const activeTraceScopes = [];
|
|
@@ -294,7 +296,7 @@ export function captureScreenView(client, screenName, {
|
|
|
294
296
|
requireClient(client);
|
|
295
297
|
requireNonEmpty("screen name", screenName);
|
|
296
298
|
client.action(id, timestamp, {
|
|
297
|
-
name:
|
|
299
|
+
name: screenActionName(screenName),
|
|
298
300
|
status,
|
|
299
301
|
metadata: {
|
|
300
302
|
...getReactNativeContext({ platform, appState }),
|
|
@@ -1012,6 +1014,22 @@ function slugify(value) {
|
|
|
1012
1014
|
.replace(/^_+|_+$/g, "") || "event";
|
|
1013
1015
|
}
|
|
1014
1016
|
|
|
1017
|
+
function screenActionName(screenName) {
|
|
1018
|
+
const directName = `${SCREEN_ACTION_PREFIX}${screenName}`;
|
|
1019
|
+
if (
|
|
1020
|
+
directName.length <= MAX_ACTION_NAME_LENGTH
|
|
1021
|
+
&& /^[a-z0-9_.:-]+$/i.test(directName)
|
|
1022
|
+
) {
|
|
1023
|
+
return directName;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
const maxScreenSegmentLength = MAX_ACTION_NAME_LENGTH - SCREEN_ACTION_PREFIX.length;
|
|
1027
|
+
const screenSegment = slugify(screenName)
|
|
1028
|
+
.slice(0, maxScreenSegmentLength)
|
|
1029
|
+
.replace(/_+$/g, "") || "event";
|
|
1030
|
+
return `${SCREEN_ACTION_PREFIX}${screenSegment}`;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1015
1033
|
function statusFromStatusCode(statusCode) {
|
|
1016
1034
|
if (typeof statusCode === "number" && Number.isFinite(statusCode) && statusCode >= 400) {
|
|
1017
1035
|
return "failure";
|