@dynatrace/rum-javascript-sdk 1.337.7 → 1.339.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 +4 -1
- package/dist/api/dynatrace-error.d.ts +18 -0
- package/dist/api/dynatrace-error.js +19 -1
- package/dist/api/index.d.ts +89 -16
- package/dist/api/index.js +89 -20
- package/dist/api/interactions.d.ts +1 -1
- package/dist/api/interactions.js +2 -2
- package/dist/api/promises/index.d.ts +34 -19
- package/dist/api/promises/index.js +34 -22
- package/dist/api/promises/interactions.d.ts +1 -1
- package/dist/api/promises/interactions.js +2 -2
- package/dist/testing/index.d.ts +1 -6
- package/dist/testing/index.js +5 -3
- package/dist/types/api/dynatrace-api-types.d.ts +68 -25
- package/dist/types/api/dynatrace-api-types.js +1 -4
- package/dist/types/api-typedoc.d.ts +5 -0
- package/dist/types/api-typedoc.js +6 -0
- package/dist/types/rum-events/event-context/event-context.d.ts +0 -10
- package/dist/types/rum-events/event-context/event-context.js +1 -1
- package/dist/types/rum-events/open-fields.d.ts +0 -11
- package/dist/types/rum-events/open-fields.js +1 -8
- package/dist/types/rum-events/rum-event-keys.d.ts +3 -1
- package/dist/types/rum-events/rum-event-keys.js +4 -2
- package/dist/types/rum-events/rum-standalone-navigation-event.d.ts +1 -2
- package/dist/types/rum-events/rum-standalone-navigation-event.js +1 -1
- package/dist/types/rum-events/rum-user-action-event.d.ts +15 -20
- package/dist/types/rum-events/rum-user-action-event.js +7 -15
- package/dist/types/rum-events/rum-user-interaction-event.d.ts +12 -12
- package/dist/types/rum-events/rum-user-interaction-event.js +1 -1
- package/dist/types/rum-events/rum-web-request-event.d.ts +2 -3
- package/dist/types/rum-events/rum-web-request-event.js +2 -2
- package/dist/types/rum-events/schema-versions.d.ts +1 -1
- package/dist/types/rum-events/schema-versions.js +2 -2
- package/dist/types/rum-events/shared-namespaces-and-fields/general-rum-event-fields.d.ts +3 -1
- package/dist/types/rum-events/shared-namespaces-and-fields/general-rum-event-fields.js +1 -1
- package/dist/types/rum-events/shared-namespaces-and-fields/index.d.ts +0 -1
- package/dist/types/rum-events/shared-namespaces-and-fields/index.js +1 -2
- package/dist/types/sdk-testing-typedoc.d.ts +26 -0
- package/dist/types/sdk-testing-typedoc.js +6 -0
- package/dist/types/sdk-typedoc.d.ts +5 -0
- package/dist/types/sdk-typedoc.js +9 -0
- package/dist/{testing/types → types/testing}/dynatrace-config.d.ts +3 -0
- package/dist/types/testing/dynatrace-config.js +2 -0
- package/dist/{testing/types → types/testing}/dynatrace-testing-fixtures.d.ts +5 -0
- package/dist/types/testing/dynatrace-testing-fixtures.js +2 -0
- package/dist/{testing/types → types/testing}/dynatrace-testing.d.ts +25 -3
- package/dist/types/testing/dynatrace-testing.js +7 -0
- package/dist/types/testing/index.d.ts +6 -0
- package/dist/types/testing/index.js +3 -0
- package/dist/types/testing/snapshot-defaults.d.ts +25 -0
- package/dist/types/testing/snapshot-defaults.js +64 -0
- package/dist/types/testing/snapshot-options.d.ts +43 -0
- package/dist/types/testing/snapshot-options.js +2 -0
- package/dist/types/user-actions/user-action-end-event.d.ts +1 -5
- package/dist/types/user-actions/user-action-end-event.js +1 -1
- package/docs/1-overview.md +41 -369
- package/docs/{3-types.md → 2-types.md} +5 -5
- package/docs/{4-useractions.md → 3-useractions.md} +24 -124
- package/docs/{5-interactions.md → 4-interactions.md} +11 -7
- package/package.json +11 -9
- package/dist/testing/install.d.ts +0 -15
- package/dist/testing/install.js +0 -22
- package/dist/testing/snapshot.d.ts +0 -129
- package/dist/testing/snapshot.js +0 -385
- package/dist/testing/test.d.ts +0 -2
- package/dist/testing/test.js +0 -397
- package/dist/testing/types/dynatrace-config.js +0 -2
- package/dist/testing/types/dynatrace-testing-fixtures.js +0 -2
- package/dist/testing/types/dynatrace-testing.js +0 -2
- package/dist/types/index-typedoc.d.ts +0 -36
- package/dist/types/index-typedoc.js +0 -37
- package/dist/types/rum-events/shared-namespaces-and-fields/view-source-fields.d.ts +0 -14
- package/dist/types/rum-events/shared-namespaces-and-fields/view-source-fields.js +0 -2
- package/docs/2-testing.md +0 -424
|
@@ -8,7 +8,7 @@ title: User Actions API
|
|
|
8
8
|
The User Actions API provides fine-grained control over user action creation and completion. You can create custom user actions, disable automatic detection, and subscribe to user action events. This is particularly useful when the automatic user action detection interferes with your application's behavior or when you need precise control over action boundaries.
|
|
9
9
|
|
|
10
10
|
:::note
|
|
11
|
-
The User Actions API is experimental and may change in future releases. The `dynatrace.userActions` property is `undefined` if the User Actions module is disabled.
|
|
11
|
+
The User Actions API is experimental and may change in future releases. The {@link API.dynatrace.userActions | `dynatrace.userActions`} property is `undefined` if the User Actions module is disabled.
|
|
12
12
|
:::
|
|
13
13
|
|
|
14
14
|
:::caution Deprecated names
|
|
@@ -20,7 +20,7 @@ The following API names have been renamed to align with the Mobile agent API. Th
|
|
|
20
20
|
| `autoClose` | `completeAutomatically` |
|
|
21
21
|
| `name` | `customName` |
|
|
22
22
|
|
|
23
|
-
The same applies to
|
|
23
|
+
The same applies to {@link Types.UserActionStartOptions}: use `completeAutomatically` instead of `autoClose` and `customName` instead of `name`. If both old and new names are provided, the **new name takes precedence**.
|
|
24
24
|
:::
|
|
25
25
|
|
|
26
26
|
## What you can do
|
|
@@ -42,7 +42,7 @@ Before using the User Actions API, ensure that:
|
|
|
42
42
|
|
|
43
43
|
- RUM JavaScript is properly configured and running
|
|
44
44
|
- The User Actions module is enabled in your configuration
|
|
45
|
-
- You have access to the `dynatrace` global object
|
|
45
|
+
- You have access to the {@link API.dynatrace | `dynatrace`} global object
|
|
46
46
|
|
|
47
47
|
## User Actions
|
|
48
48
|
|
|
@@ -63,9 +63,9 @@ User actions can complete for various reasons, indicated by the `user_action.com
|
|
|
63
63
|
|
|
64
64
|
- **`completed`** - The user action completed normally after the inactivity threshold was reached. This occurs when Dynatrace detects no more activity (DOM mutations, requests, etc.) related to the user interaction.
|
|
65
65
|
|
|
66
|
-
- **`completed_by_api`** - The user action was completed explicitly by calling the `complete()` function through the API.
|
|
66
|
+
- **`completed_by_api`** - The user action was completed explicitly by calling the {@link Types.UserActionTracker.complete | `complete()`} function through the API.
|
|
67
67
|
|
|
68
|
-
- **`interrupted_by_api`** - The user action was interrupted when a new user action was created via the API using `create()
|
|
68
|
+
- **`interrupted_by_api`** - The user action was interrupted when a new user action was created via the API using {@link API.UserActions.create | `create()`}.
|
|
69
69
|
|
|
70
70
|
- **`interrupted_by_navigation`** - The user action was interrupted by a page navigation event, such as clicking a link or using browser navigation buttons.
|
|
71
71
|
|
|
@@ -83,7 +83,7 @@ You can use the User Actions API directly, or via its synchronous or asynchronou
|
|
|
83
83
|
|
|
84
84
|
### Direct API (via `dynatrace.userActions`)
|
|
85
85
|
|
|
86
|
-
Access the API directly through the global `dynatrace.userActions` namespace:
|
|
86
|
+
Access the API directly through the global {@link API.dynatrace.userActions | `dynatrace.userActions`} namespace:
|
|
87
87
|
|
|
88
88
|
```typescript
|
|
89
89
|
const userAction = dynatrace?.userActions?.create();
|
|
@@ -94,7 +94,7 @@ This approach requires optional chaining (`?.`) to handle cases where RUM JavaSc
|
|
|
94
94
|
|
|
95
95
|
### Safe Wrapper API (recommended)
|
|
96
96
|
|
|
97
|
-
Use the safe wrapper functions from `@dynatrace/rum-javascript-sdk/api` that gracefully handle missing modules:
|
|
97
|
+
Use the safe wrapper functions from {@link SDK.userActions} (`@dynatrace/rum-javascript-sdk/api/user-actions`) that gracefully handle missing modules:
|
|
98
98
|
|
|
99
99
|
```typescript
|
|
100
100
|
import { create } from '@dynatrace/rum-javascript-sdk/api/user-actions';
|
|
@@ -106,7 +106,7 @@ userAction?.complete();
|
|
|
106
106
|
|
|
107
107
|
### Async API
|
|
108
108
|
|
|
109
|
-
Use the promise-based API from `@dynatrace/rum-javascript-sdk/api/promises` when you need to ensure the module is available:
|
|
109
|
+
Use the promise-based API from {@link SDK.promises.userActions} (`@dynatrace/rum-javascript-sdk/api/promises/user-actions`) when you need to ensure the module is available:
|
|
110
110
|
|
|
111
111
|
```typescript
|
|
112
112
|
import { create } from '@dynatrace/rum-javascript-sdk/api/promises/user-actions';
|
|
@@ -168,7 +168,7 @@ userAction?.complete();
|
|
|
168
168
|
```
|
|
169
169
|
|
|
170
170
|
:::warning
|
|
171
|
-
When `completeAutomatically` is set to `false`, you must call `complete()` manually. Otherwise, the user action will remain open until the next user action is created or the maximum duration is reached, which may lead to incorrect timing measurements.
|
|
171
|
+
When {@link Types.UserActionTracker.completeAutomatically | `completeAutomatically`} is set to `false`, you must call {@link Types.UserActionTracker.complete | `complete()`} manually. Otherwise, the user action will remain open until the next user action is created or the maximum duration is reached, which may lead to incorrect timing measurements.
|
|
172
172
|
:::
|
|
173
173
|
|
|
174
174
|
### Track user action completion
|
|
@@ -231,7 +231,7 @@ if (userAction) {
|
|
|
231
231
|
}
|
|
232
232
|
```
|
|
233
233
|
|
|
234
|
-
Or use the `addEventModifier` API to attach them to events directly:
|
|
234
|
+
Or use the {@link API.dynatrace.addEventModifier | `addEventModifier`} API to attach them to events directly:
|
|
235
235
|
```typescript
|
|
236
236
|
dynatrace.addEventModifier(evt => {
|
|
237
237
|
if (evt.has_user_action) {
|
|
@@ -354,7 +354,7 @@ async function handleNavigation(route) {
|
|
|
354
354
|
```
|
|
355
355
|
|
|
356
356
|
:::caution
|
|
357
|
-
When automatic detection is disabled, no user actions are created automatically. You must create all user actions manually using the `create()` function.
|
|
357
|
+
When automatic detection is disabled, no user actions are created automatically. You must create all user actions manually using the {@link API.UserActions.create | `create()`} function.
|
|
358
358
|
:::
|
|
359
359
|
|
|
360
360
|
### Re-enable automatic detection
|
|
@@ -366,7 +366,7 @@ dynatrace.userActions?.setAutomaticDetection(true);
|
|
|
366
366
|
|
|
367
367
|
## Access current user action
|
|
368
368
|
|
|
369
|
-
The `current` property provides access to the currently active user action. This is useful when you need to modify an ongoing action or prevent its automatic completion.
|
|
369
|
+
The {@link API.UserActions.current | `current`} property provides access to the currently active user action. This is useful when you need to modify an ongoing action or prevent its automatic completion.
|
|
370
370
|
|
|
371
371
|
### Basic usage
|
|
372
372
|
|
|
@@ -709,7 +709,7 @@ function createTrackedAction() {
|
|
|
709
709
|
|
|
710
710
|
### Finish user actions in finally blocks
|
|
711
711
|
|
|
712
|
-
Ensure user actions are always completed if `completeAutomatically` is `false`, even when errors occur:
|
|
712
|
+
Ensure user actions are always completed if {@link Types.UserActionTracker.completeAutomatically | `completeAutomatically`} is `false`, even when errors occur:
|
|
713
713
|
|
|
714
714
|
```typescript
|
|
715
715
|
async function performTrackedOperation() {
|
|
@@ -790,7 +790,7 @@ if (userAction) {
|
|
|
790
790
|
|
|
791
791
|
### Don't set startTime in the future
|
|
792
792
|
|
|
793
|
-
The `startTime` must not be set to a future timestamp:
|
|
793
|
+
The {@link Types.UserActionTracker.startTime | `startTime`} must not be set to a future timestamp:
|
|
794
794
|
|
|
795
795
|
```typescript
|
|
796
796
|
// ❌ Bad: Setting future timestamp
|
|
@@ -816,8 +816,8 @@ if (userAction) {
|
|
|
816
816
|
If your user actions aren't appearing in Dynatrace:
|
|
817
817
|
|
|
818
818
|
1. Verify that the User Actions module is enabled
|
|
819
|
-
2. Check that `dynatrace.userActions` is defined
|
|
820
|
-
3. Ensure you're calling `complete()` on user actions with `completeAutomatically: false`
|
|
819
|
+
2. Check that {@link API.dynatrace.userActions | `dynatrace.userActions`} is defined
|
|
820
|
+
3. Ensure you're calling {@link Types.UserActionTracker.complete | `complete()`} on user actions with `completeAutomatically: false`
|
|
821
821
|
4. Check browser console for any errors
|
|
822
822
|
|
|
823
823
|
### User actions completing too early
|
|
@@ -861,7 +861,7 @@ If custom properties aren't showing up:
|
|
|
861
861
|
1. Check the console logs in your browser for any issues related to Dynatrace SDK usage.
|
|
862
862
|
2. Ensure property keys start with `event_properties.` prefix
|
|
863
863
|
3. Verify the property values are of supported types (string, number, boolean)
|
|
864
|
-
4. Check that properties are set before calling `complete()`
|
|
864
|
+
4. Check that properties are set before calling {@link Types.UserActionTracker.complete | `complete()`}
|
|
865
865
|
5. Make sure the user action state is `'active'` when setting properties
|
|
866
866
|
|
|
867
867
|
```typescript
|
|
@@ -886,122 +886,22 @@ if (userAction) {
|
|
|
886
886
|
|
|
887
887
|
## API Reference
|
|
888
888
|
|
|
889
|
-
For complete API documentation, see the [RUM JavaScript Typedoc](https://www.dynatrace.com/support/doc/javascriptapi/doc-latest/).
|
|
890
|
-
|
|
891
889
|
### Safe Wrapper Functions
|
|
892
890
|
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
Safe wrappers that gracefully handle cases where the RUM JavaScript or User Actions module is not available:
|
|
896
|
-
|
|
897
|
-
**`create(options?): UserActionTracker | undefined`**
|
|
898
|
-
|
|
899
|
-
Creates a new user action. Returns `undefined` if the module is not available.
|
|
900
|
-
|
|
901
|
-
```typescript
|
|
902
|
-
import { create } from '@dynatrace/rum-javascript-sdk/api/user-actions';
|
|
903
|
-
|
|
904
|
-
const userAction = create({ completeAutomatically: false });
|
|
905
|
-
userAction?.complete();
|
|
906
|
-
```
|
|
907
|
-
|
|
908
|
-
**`subscribe(subscriber): Unsubscriber | undefined`**
|
|
909
|
-
|
|
910
|
-
Subscribes to all user action creation events. Returns `undefined` if the module is not available.
|
|
911
|
-
|
|
912
|
-
```typescript
|
|
913
|
-
import { subscribe } from '@dynatrace/rum-javascript-sdk/api/user-actions';
|
|
914
|
-
|
|
915
|
-
const unsubscribe = subscribe((userAction) => {
|
|
916
|
-
console.log('User action created');
|
|
917
|
-
});
|
|
918
|
-
unsubscribe?.();
|
|
919
|
-
```
|
|
920
|
-
|
|
921
|
-
**`setAutomaticDetection(enabled): void`**
|
|
922
|
-
|
|
923
|
-
Enables or disables automatic user action detection. No-op if the module is not available.
|
|
924
|
-
|
|
925
|
-
```typescript
|
|
926
|
-
import { setAutomaticDetection } from '@dynatrace/rum-javascript-sdk/api/user-actions';
|
|
927
|
-
|
|
928
|
-
setAutomaticDetection(false);
|
|
929
|
-
```
|
|
930
|
-
|
|
931
|
-
**`getCurrent(): UserActionTracker | undefined`**
|
|
932
|
-
|
|
933
|
-
Returns the currently active user action, or `undefined` if none is active or the module is not available.
|
|
934
|
-
|
|
935
|
-
```typescript
|
|
936
|
-
import { getCurrent } from '@dynatrace/rum-javascript-sdk/api/user-actions';
|
|
937
|
-
|
|
938
|
-
const current = getCurrent();
|
|
939
|
-
if (current) {
|
|
940
|
-
current.completeAutomatically = false;
|
|
941
|
-
}
|
|
942
|
-
```
|
|
943
|
-
|
|
944
|
-
#### Asynchronous API (`@dynatrace/rum-javascript-sdk/api/promises/user-actions`)
|
|
945
|
-
|
|
946
|
-
Promise-based wrappers that wait for the module to become available or throw a `DynatraceError`:
|
|
947
|
-
|
|
948
|
-
**`create(options?, timeout?): Promise<UserActionTracker>`**
|
|
949
|
-
|
|
950
|
-
Creates a new user action, waiting up to `timeout` ms (default: 10000) for the module to be available.
|
|
951
|
-
|
|
952
|
-
```typescript
|
|
953
|
-
import { create } from '@dynatrace/rum-javascript-sdk/api/promises/user-actions';
|
|
954
|
-
|
|
955
|
-
try {
|
|
956
|
-
const userAction = await create({ completeAutomatically: false });
|
|
957
|
-
userAction.complete();
|
|
958
|
-
} catch (error) {
|
|
959
|
-
console.error('User Actions module not available');
|
|
960
|
-
}
|
|
961
|
-
```
|
|
962
|
-
|
|
963
|
-
**`subscribe(subscriber, timeout?): Promise<Unsubscriber>`**
|
|
964
|
-
|
|
965
|
-
**`setAutomaticDetection(enabled, timeout?): Promise<void>`**
|
|
966
|
-
|
|
967
|
-
**`getCurrent(timeout?): Promise<UserActionTracker | undefined>`**
|
|
968
|
-
|
|
969
|
-
All async functions follow the same pattern, accepting an optional `timeout` parameter.
|
|
970
|
-
|
|
971
|
-
### UserActionTracker properties
|
|
891
|
+
The synchronous safe wrappers ({@link SDK.userActions}) gracefully handle cases where the RUM JavaScript or User Actions module is not available.
|
|
972
892
|
|
|
973
|
-
|
|
974
|
-
|----------|-----------------------------------------------|--------|-------------|
|
|
975
|
-
| `complete()` | Function | - | Completes the user action and sends the event |
|
|
976
|
-
| `finish()` | Function | - | **Deprecated.** Use `complete()` instead |
|
|
977
|
-
| `subscribe(callback)` | Function | - | Subscribes to automatic completion events |
|
|
978
|
-
| `completeAutomatically` | `boolean` | Get/Set | Controls whether the action completes automatically |
|
|
979
|
-
| `autoClose` | `boolean` | Get/Set | **Deprecated.** Use `completeAutomatically` instead |
|
|
980
|
-
| `state` | `'active' \| 'complete'` | Get | Returns the current state of the user action |
|
|
981
|
-
| `event_properties` | `Record<string, string \| number \| boolean>` | Get/Set | Custom properties for business context |
|
|
982
|
-
| `startTime` | `number` | Get/Set | Start time in milliseconds (must not be in future) |
|
|
983
|
-
| `customName` | `string \| undefined` | Get/Set | Display name for the user action |
|
|
984
|
-
| `name` | `string \| undefined` | Get/Set | **Deprecated.** Use `customName` instead |
|
|
893
|
+
The asynchronous wrappers ({@link SDK.promises.userActions}) wait for the module to become available or throw a {@link SDK.DynatraceError}.
|
|
985
894
|
|
|
986
|
-
### Key
|
|
895
|
+
### Key Types
|
|
987
896
|
|
|
988
|
-
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
- `setAutomaticDetection(enabled)` - Enables or disables automatic detection
|
|
992
|
-
- `current` - Access the currently active user action
|
|
993
|
-
- `UserActionTracker` - Represents an individual user action (see properties table above)
|
|
994
|
-
- `UserActionStartOptions` - Configuration options for creating user actions
|
|
995
|
-
- `completeAutomatically?: boolean` - Whether the action should complete automatically (default: `true`)
|
|
996
|
-
- `autoClose?: boolean` - **Deprecated.** Use `completeAutomatically` instead
|
|
997
|
-
- `customName?: string` - A human-readable custom name to identify the user action
|
|
998
|
-
- `name?: string` - **Deprecated.** Use `customName` instead
|
|
999
|
-
- `Unsubscriber` - Function type `() => void` for unsubscribing from events
|
|
897
|
+
- {@link API.UserActions} — The main interface for user action management (`create`, `subscribe`, `setAutomaticDetection`, `current`)
|
|
898
|
+
- {@link Types.UserActionTracker} — Represents an individual user action with properties like `complete()`, `completeAutomatically`, `state`, `event_properties`, `startTime`, and `customName`
|
|
899
|
+
- {@link Types.UserActionStartOptions} — Configuration options for creating user actions
|
|
1000
900
|
|
|
1001
901
|
## Additional resources
|
|
1002
902
|
|
|
1003
903
|
- [RUM JavaScript SDK Overview](./1-overview.md)
|
|
1004
|
-
- {@link dynatrace
|
|
904
|
+
- {@link API.dynatrace | dynatrace API} — For modifying user action events
|
|
1005
905
|
|
|
1006
906
|
---
|
|
1007
907
|
|
|
@@ -7,7 +7,7 @@ This guide explains how to report custom interaction events that are not automat
|
|
|
7
7
|
|
|
8
8
|
## What you can do
|
|
9
9
|
|
|
10
|
-
- Report custom keyboard shortcuts or key combinations via `sendKeyPressEvent`
|
|
10
|
+
- Report custom keyboard shortcuts or key combinations via {@link API.Interactions.sendKeyPressEvent | `sendKeyPressEvent`}
|
|
11
11
|
- Attach `ui_element.custom_name` and `event_properties.*` fields
|
|
12
12
|
- Provide an `Element` or `KeyboardEvent` to capture UI element fields
|
|
13
13
|
|
|
@@ -21,6 +21,8 @@ You can use the Interactions API directly, or via its synchronous or asynchronou
|
|
|
21
21
|
|
|
22
22
|
### Direct API (via `dynatrace.interactions`)
|
|
23
23
|
|
|
24
|
+
Access the API directly through the global {@link API.dynatrace.interactions | `dynatrace.interactions`} namespace:
|
|
25
|
+
|
|
24
26
|
```typescript
|
|
25
27
|
dynatrace?.interactions?.sendKeyPressEvent({
|
|
26
28
|
keys: ["A"]
|
|
@@ -29,6 +31,8 @@ dynatrace?.interactions?.sendKeyPressEvent({
|
|
|
29
31
|
|
|
30
32
|
### Safe Wrapper API (recommended)
|
|
31
33
|
|
|
34
|
+
Use the safe wrapper from {@link SDK.interactions} (`@dynatrace/rum-javascript-sdk/api/interactions`):
|
|
35
|
+
|
|
32
36
|
```typescript
|
|
33
37
|
import * as interactions from "@dynatrace/rum-javascript-sdk/api/interactions";
|
|
34
38
|
import { UserInteractionSpecialKey } from "@dynatrace/rum-javascript-sdk/types/rum-events";
|
|
@@ -41,6 +45,8 @@ interactions.sendKeyPressEvent({
|
|
|
41
45
|
|
|
42
46
|
### Async API
|
|
43
47
|
|
|
48
|
+
Use the promise-based wrapper from {@link SDK.promises.interactions} (`@dynatrace/rum-javascript-sdk/api/promises/interactions`):
|
|
49
|
+
|
|
44
50
|
```typescript
|
|
45
51
|
import { sendKeyPressEvent } from "@dynatrace/rum-javascript-sdk/api/promises/interactions";
|
|
46
52
|
import { UserInteractionSpecialKey } from "@dynatrace/rum-javascript-sdk/types/rum-events";
|
|
@@ -52,7 +58,7 @@ await sendKeyPressEvent({
|
|
|
52
58
|
|
|
53
59
|
## `UserInteractionSpecialKey`
|
|
54
60
|
|
|
55
|
-
The {@link UserInteractionSpecialKey} enum provides normalized string representations for specific [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) values (e.g. `" "` → `"space"`, `"Control"` → `"ctrl"`, `"Escape"` → `"esc"`, `"ArrowUp"` → `"arrow_up"`).
|
|
61
|
+
The {@link Types.UserInteractionSpecialKey} enum provides normalized string representations for specific [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) values (e.g. `" "` → `"space"`, `"Control"` → `"ctrl"`, `"Escape"` → `"esc"`, `"ArrowUp"` → `"arrow_up"`).
|
|
56
62
|
|
|
57
63
|
Using this enum is **optional** — raw [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) values are also accepted and normalized internally. The enum is a convenience for readability, especially when constructing key arrays manually without a real keyboard event.
|
|
58
64
|
|
|
@@ -77,9 +83,7 @@ dynatrace.interactions?.sendKeyPressEvent({
|
|
|
77
83
|
|
|
78
84
|
## sendKeyPressEvent
|
|
79
85
|
|
|
80
|
-
`
|
|
86
|
+
See the {@link API.Interactions | Interactions API reference} for full parameter details. The function accepts a {@link API.SendUserInteractionFields} object with a non-empty `keys` array, and an optional `Element` or `KeyboardEvent` to derive UI element fields.
|
|
87
|
+
|
|
88
|
+
Safe wrapper: {@link SDK.interactions} • Async wrapper: {@link SDK.promises.interactions}
|
|
81
89
|
|
|
82
|
-
- `fields` must be a JSON-serializable object with a non-empty `keys` array.
|
|
83
|
-
- Keys can be [`UserInteractionSpecialKey`](#userinteractionspecialkey) members or raw [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) strings — raw values are normalized internally.
|
|
84
|
-
- Optional `ui_element.custom_name` and `event_properties.*` entries are allowed.
|
|
85
|
-
- `elementOrEvent` may be an [`Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element) or [`KeyboardEvent`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent) to derive UI element fields. If omitted, no UI element fields are added.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynatrace/rum-javascript-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.339.1",
|
|
4
4
|
"description": "JavaScript API for Real User Monitoring (RUM)",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -45,6 +45,9 @@
|
|
|
45
45
|
],
|
|
46
46
|
"types/rum-events/shared-namespaces-and-fields": [
|
|
47
47
|
"./dist/types/rum-events/shared-namespaces-and-fields/index.d.ts"
|
|
48
|
+
],
|
|
49
|
+
"types/testing": [
|
|
50
|
+
"./dist/types/testing/index.d.ts"
|
|
48
51
|
]
|
|
49
52
|
}
|
|
50
53
|
},
|
|
@@ -128,6 +131,11 @@
|
|
|
128
131
|
"types": "./dist/types/rum-events/shared-namespaces-and-fields/index.d.ts",
|
|
129
132
|
"import": "./dist/types/rum-events/shared-namespaces-and-fields/index.js",
|
|
130
133
|
"default": "./dist/types/rum-events/shared-namespaces-and-fields/index.js"
|
|
134
|
+
},
|
|
135
|
+
"./types/testing": {
|
|
136
|
+
"types": "./dist/types/testing/index.d.ts",
|
|
137
|
+
"import": "./dist/types/testing/index.js",
|
|
138
|
+
"default": "./dist/types/testing/index.js"
|
|
131
139
|
}
|
|
132
140
|
},
|
|
133
141
|
"keywords": [
|
|
@@ -137,12 +145,6 @@
|
|
|
137
145
|
"javascript",
|
|
138
146
|
"api"
|
|
139
147
|
],
|
|
140
|
-
"dependencies": {
|
|
141
|
-
"snappyjs": "0.7.0"
|
|
142
|
-
},
|
|
143
|
-
"peerDependencies": {
|
|
144
|
-
"@playwright/test": "^1.52.0"
|
|
145
|
-
},
|
|
146
148
|
"author": "Dynatrace",
|
|
147
149
|
"license": "ISC",
|
|
148
150
|
"devDependencies": {
|
|
@@ -152,9 +154,9 @@
|
|
|
152
154
|
"eslint": "9.38.0",
|
|
153
155
|
"jsdom": "29.0.1",
|
|
154
156
|
"knip": "5.85.0",
|
|
155
|
-
"typedoc": "0.28.
|
|
157
|
+
"typedoc": "0.28.18",
|
|
156
158
|
"typedoc-plugin-mdn-links": "5.1.1",
|
|
157
|
-
"typescript": "
|
|
159
|
+
"typescript": "6.0.2",
|
|
158
160
|
"vitest": "4.1.0"
|
|
159
161
|
},
|
|
160
162
|
"scripts": {
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fetches the RUM JavaScript from the given environment.
|
|
3
|
-
*
|
|
4
|
-
* @param endpointUrl The location to fetch the script from, e.g. "https://{your-environment-id}.live.dynatrace.com" or "https://{your-activegate-domain}:9999/e/{your-environment-id}".
|
|
5
|
-
* @param appId The RUM application ID to fetch the configuration.
|
|
6
|
-
* @param token The authentication token to access the API.
|
|
7
|
-
* @returns A promise that resolves with an HTML string containing the RUM JavaScript for insertion into a page.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* const rumJavaScriptHtml = await fetchRumJavaScript("https://myenv.live.dynatrace.com","APPLICATION-EA7C4B59F27D43EB", "dt0c01.abcd.efghijk");
|
|
11
|
-
* // use the result to write your javascript, e.g. with cheerio:
|
|
12
|
-
* const $ = cheerio.load(myHtml);
|
|
13
|
-
* $("head").append(rumJavaScriptHtml);
|
|
14
|
-
*/
|
|
15
|
-
export declare function fetchRumJavaScript(endpointUrl: string, appId: string, token: string): Promise<string>;
|
package/dist/testing/install.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fetches the RUM JavaScript from the given environment.
|
|
3
|
-
*
|
|
4
|
-
* @param endpointUrl The location to fetch the script from, e.g. "https://{your-environment-id}.live.dynatrace.com" or "https://{your-activegate-domain}:9999/e/{your-environment-id}".
|
|
5
|
-
* @param appId The RUM application ID to fetch the configuration.
|
|
6
|
-
* @param token The authentication token to access the API.
|
|
7
|
-
* @returns A promise that resolves with an HTML string containing the RUM JavaScript for insertion into a page.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* const rumJavaScriptHtml = await fetchRumJavaScript("https://myenv.live.dynatrace.com","APPLICATION-EA7C4B59F27D43EB", "dt0c01.abcd.efghijk");
|
|
11
|
-
* // use the result to write your javascript, e.g. with cheerio:
|
|
12
|
-
* const $ = cheerio.load(myHtml);
|
|
13
|
-
* $("head").append(rumJavaScriptHtml);
|
|
14
|
-
*/
|
|
15
|
-
export async function fetchRumJavaScript(endpointUrl, appId, token) {
|
|
16
|
-
const response = await fetch(`${endpointUrl}/api/v2/rum/javaScriptTag/${appId}`, { headers: { Authorization: `Api-Token ${token}` } });
|
|
17
|
-
if (!response.ok) {
|
|
18
|
-
throw new Error(`Failed to fetch RUM JavaScript: ${response.statusText}`);
|
|
19
|
-
}
|
|
20
|
-
return response.text();
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdGFsbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NvdXJjZS90ZXN0aW5nL2luc3RhbGwudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7Ozs7Ozs7R0FhRztBQUNILE1BQU0sQ0FBQyxLQUFLLFVBQVUsa0JBQWtCLENBQ3BDLFdBQW1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CgpO1xufVxuIl19
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Snapshot testing utilities for Dynatrace RUM event verification.
|
|
3
|
-
* Provides mechanisms to compare captured events against stored snapshots
|
|
4
|
-
* with support for masking volatile fields.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Result of reading a snapshot file.
|
|
8
|
-
*/
|
|
9
|
-
interface SnapshotReadResult {
|
|
10
|
-
/**
|
|
11
|
-
* Whether the snapshot file exists.
|
|
12
|
-
*/
|
|
13
|
-
exists: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* The parsed snapshot data, or undefined if the file doesn't exist.
|
|
16
|
-
*/
|
|
17
|
-
data?: Record<string, unknown>[];
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Pattern to match events that should be completely ignored during snapshot comparison.
|
|
21
|
-
* Events matching any of these patterns will be filtered out before comparison.
|
|
22
|
-
*/
|
|
23
|
-
export type EventIgnorePattern = Record<string, unknown>;
|
|
24
|
-
/**
|
|
25
|
-
* Options for configuring snapshot comparison behavior.
|
|
26
|
-
*/
|
|
27
|
-
export interface SnapshotOptions {
|
|
28
|
-
/**
|
|
29
|
-
* Properties to ignore before comparison. Values are replaced with "[IGNORED]" placeholder.
|
|
30
|
-
* Supports exact field names and wildcard patterns (`prefix.*`).
|
|
31
|
-
*
|
|
32
|
-
* Examples:
|
|
33
|
-
* - `"start_time"` → value replaced with "[IGNORED]"
|
|
34
|
-
* - `"inp.*"` → all fields starting with `inp.` have values replaced with "[IGNORED]"
|
|
35
|
-
*
|
|
36
|
-
* Default: DEFAULT_IGNORED_FIELDS
|
|
37
|
-
*/
|
|
38
|
-
ignoredFields?: string[];
|
|
39
|
-
/**
|
|
40
|
-
* Properties to remove entirely before comparison.
|
|
41
|
-
* Supports exact field names and wildcard patterns (`prefix.*`).
|
|
42
|
-
*
|
|
43
|
-
* Examples:
|
|
44
|
-
* - `"start_time"` → field is removed from the event
|
|
45
|
-
* - `"inp.*"` → all fields starting with `inp.` are removed
|
|
46
|
-
*
|
|
47
|
-
* Default: DEFAULT_REMOVED_FIELDS
|
|
48
|
-
*/
|
|
49
|
-
removedFields?: string[];
|
|
50
|
-
/**
|
|
51
|
-
* Event patterns to completely ignore during snapshot comparison.
|
|
52
|
-
* Events matching any of these patterns will be filtered out.
|
|
53
|
-
* Default: DEFAULT_IGNORED_EVENTS
|
|
54
|
-
*/
|
|
55
|
-
ignoreEvents?: EventIgnorePattern[];
|
|
56
|
-
/**
|
|
57
|
-
* Custom snapshot name. If not provided, auto-generated from test name.
|
|
58
|
-
*/
|
|
59
|
-
name?: string;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Default properties that are ignored (replaced with "[IGNORED]") in snapshots to prevent flaky tests.
|
|
63
|
-
* These fields typically contain volatile values like timestamps, IDs, and durations
|
|
64
|
-
* that change between test runs.
|
|
65
|
-
*/
|
|
66
|
-
export declare const DEFAULT_IGNORED_FIELDS: readonly string[];
|
|
67
|
-
/**
|
|
68
|
-
* Default properties that are removed entirely from snapshots to prevent flaky tests.
|
|
69
|
-
* These fields vary in count or presence between test runs.
|
|
70
|
-
*/
|
|
71
|
-
export declare const DEFAULT_REMOVED_FIELDS: readonly string[];
|
|
72
|
-
/**
|
|
73
|
-
* Default event patterns that are ignored during snapshot comparison.
|
|
74
|
-
* These events are volatile and may or may not be recorded depending on browser performance.
|
|
75
|
-
*/
|
|
76
|
-
export declare const DEFAULT_IGNORED_EVENTS: readonly EventIgnorePattern[];
|
|
77
|
-
/**
|
|
78
|
-
* Placeholder value used to replace ignored property values.
|
|
79
|
-
*/
|
|
80
|
-
export declare const IGNORED_PLACEHOLDER = "[IGNORED]";
|
|
81
|
-
/**
|
|
82
|
-
* Processes events by ignoring and removing specified properties.
|
|
83
|
-
* - Ignored properties have their values replaced with "[IGNORED]" placeholder
|
|
84
|
-
* - Removed properties are deleted entirely from the event
|
|
85
|
-
*
|
|
86
|
-
* @param events Array of event objects to process
|
|
87
|
-
* @param ignoredFields Array of field paths to ignore (values replaced with placeholder)
|
|
88
|
-
* @param removedFields Array of field paths to remove entirely
|
|
89
|
-
* @returns Deep copy of events with specified fields processed
|
|
90
|
-
*/
|
|
91
|
-
export declare function processEventProperties(events: Record<string, unknown>[], ignoredFields?: readonly string[], removedFields?: readonly string[]): Record<string, unknown>[];
|
|
92
|
-
/**
|
|
93
|
-
* Filters out events that match any of the ignore patterns.
|
|
94
|
-
* An event matches a pattern if all properties in the pattern exist in the event with the same values.
|
|
95
|
-
*
|
|
96
|
-
* @param events Array of events to filter
|
|
97
|
-
* @param ignorePatterns Array of patterns to match against
|
|
98
|
-
* @returns Filtered array excluding events that match any pattern
|
|
99
|
-
*/
|
|
100
|
-
export declare function filterIgnoredEvents(events: Record<string, unknown>[], ignorePatterns?: readonly EventIgnorePattern[]): Record<string, unknown>[];
|
|
101
|
-
/**
|
|
102
|
-
* Reads a snapshot file from disk.
|
|
103
|
-
* Returns an object indicating whether the file exists and its parsed contents.
|
|
104
|
-
*
|
|
105
|
-
* @param snapshotPath Absolute path to the snapshot file
|
|
106
|
-
* @returns Object with exists flag and parsed data
|
|
107
|
-
* @throws Error if the file contains invalid JSON or is not an array of records
|
|
108
|
-
*/
|
|
109
|
-
export declare function readSnapshot(snapshotPath: string): SnapshotReadResult;
|
|
110
|
-
/**
|
|
111
|
-
* Writes snapshot data to disk.
|
|
112
|
-
* Creates parent directories if they don't exist.
|
|
113
|
-
* Events are sorted by characteristics for consistent ordering.
|
|
114
|
-
* Uses deterministic JSON serialization with sorted keys for consistent diffs.
|
|
115
|
-
*
|
|
116
|
-
* @param snapshotPath Absolute path to the snapshot file
|
|
117
|
-
* @param data Array of events to write
|
|
118
|
-
*/
|
|
119
|
-
export declare function writeSnapshot(snapshotPath: string, data: Record<string, unknown>[]): void;
|
|
120
|
-
/**
|
|
121
|
-
* Sorts events by their characteristics signature for order-independent comparison.
|
|
122
|
-
* Events with the same characteristics are further sorted by other stable properties.
|
|
123
|
-
* This ensures consistent ordering regardless of event arrival order.
|
|
124
|
-
*
|
|
125
|
-
* @param events Array of events to sort
|
|
126
|
-
* @returns New array with events sorted by characteristics
|
|
127
|
-
*/
|
|
128
|
-
export declare function sortEventsByCharacteristics(events: Record<string, unknown>[]): Record<string, unknown>[];
|
|
129
|
-
export {};
|