@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
package/docs/1-overview.md
CHANGED
|
@@ -3,7 +3,7 @@ title: RUM JavaScript SDK Overview
|
|
|
3
3
|
---
|
|
4
4
|
# @dynatrace/rum-javascript-sdk
|
|
5
5
|
|
|
6
|
-
A JavaScript API for interacting with the Dynatrace Real User Monitoring (RUM) JavaScript. This package provides both synchronous and asynchronous wrappers for the Dynatrace RUM API, along with TypeScript support
|
|
6
|
+
A JavaScript API for interacting with the Dynatrace Real User Monitoring (RUM) JavaScript. This package provides both synchronous and asynchronous wrappers for the Dynatrace RUM API, along with TypeScript support.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
@@ -13,14 +13,14 @@ npm install @dynatrace/rum-javascript-sdk
|
|
|
13
13
|
|
|
14
14
|
## Overview
|
|
15
15
|
|
|
16
|
-
This package provides two main API approaches for interacting with the Dynatrace RUM JavaScript, as well as types
|
|
16
|
+
This package provides two main API approaches for interacting with the Dynatrace RUM JavaScript, as well as types:
|
|
17
17
|
|
|
18
|
-
- **Synchronous API**: Safe wrapper functions that gracefully handle cases where the RUM JavaScript is not available
|
|
19
|
-
- **Asynchronous API**: Promise-based functions that wait for the RUM JavaScript to become available
|
|
20
|
-
- **User Actions API**: Manual control over user action creation and lifecycle (see [User Actions API](./
|
|
21
|
-
- **Interactions API**: Report custom user interaction events (see [Interactions API](./
|
|
18
|
+
- **Synchronous API**: Safe wrapper functions that gracefully handle cases where the RUM JavaScript is not available (see the {@link SDK | SDK API reference})
|
|
19
|
+
- **Asynchronous API**: Promise-based functions that wait for the RUM JavaScript to become available (see the {@link SDK.promises | SDK.promises API reference})
|
|
20
|
+
- **User Actions API**: Manual control over user action creation and lifecycle (see [User Actions API](./3-useractions.md))
|
|
21
|
+
- **Interactions API**: Report custom user interaction events (see [Interactions API](./4-interactions.md))
|
|
22
22
|
- **TypeScript Support**: Comprehensive type definitions for all RUM API functions
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
|
|
25
25
|
## Quick Start
|
|
26
26
|
|
|
@@ -61,377 +61,31 @@ try {
|
|
|
61
61
|
|
|
62
62
|
### Synchronous API (`@dynatrace/rum-javascript-sdk/api`)
|
|
63
63
|
|
|
64
|
-
The synchronous API provides safe wrapper functions that gracefully handle cases where the Dynatrace RUM JavaScript is not available. These functions
|
|
65
|
-
|
|
66
|
-
#### `sendEvent(fields, eventContext?): void`
|
|
67
|
-
|
|
68
|
-
Sends a custom event to Dynatrace RUM.
|
|
69
|
-
|
|
70
|
-
**Parameters:**
|
|
71
|
-
- `fields: ApiCreatedEventPropertiesEvent` - Event properties object. Must be serializable JSON with properties prefixed with `event_properties.`, plus optional `duration` and `start_time` properties.
|
|
72
|
-
- `eventContext?: unknown` - Optional context for event modification callbacks.
|
|
73
|
-
|
|
74
|
-
**Example:**
|
|
75
|
-
```typescript
|
|
76
|
-
import { sendEvent } from '@dynatrace/rum-javascript-sdk/api';
|
|
77
|
-
|
|
78
|
-
sendEvent({
|
|
79
|
-
'event_properties.page_name': 'checkout',
|
|
80
|
-
'event_properties.step': 'payment',
|
|
81
|
-
'event_properties.amount': 99.99,
|
|
82
|
-
'duration': 1500,
|
|
83
|
-
'start_time': Date.now()
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
#### `addEventModifier(eventModifier): Unsubscriber | undefined`
|
|
88
|
-
|
|
89
|
-
Registers a function to modify events before they are sent to Dynatrace.
|
|
90
|
-
|
|
91
|
-
**Parameters:**
|
|
92
|
-
- `eventModifier: (jsonEvent: Readonly<JSONEvent>, eventContext?: EventContext) => JSONEvent | null` - Function that receives an event and returns a modified version or null to cancel the event.
|
|
93
|
-
|
|
94
|
-
**Returns:**
|
|
95
|
-
- `Unsubscriber | undefined` - Function to remove the modifier, or undefined if the RUM JavaScript is not available.
|
|
96
|
-
|
|
97
|
-
**Example:**
|
|
98
|
-
```typescript
|
|
99
|
-
import { addEventModifier } from '@dynatrace/rum-javascript-sdk/api';
|
|
100
|
-
|
|
101
|
-
const unsubscribe = addEventModifier((event, context) => {
|
|
102
|
-
// Add user context to all events
|
|
103
|
-
return {
|
|
104
|
-
...event,
|
|
105
|
-
'event_properties.user_tier': 'premium'
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// Later, remove the modifier
|
|
110
|
-
unsubscribe?.();
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
#### `runHealthCheck(config?): Promise<unknown[] | undefined> | undefined`
|
|
114
|
-
|
|
115
|
-
Runs a health check on the RUM JavaScript to diagnose potential issues.
|
|
116
|
-
|
|
117
|
-
**Parameters:**
|
|
118
|
-
- `config?: HealthCheckConfig` - Optional configuration object:
|
|
119
|
-
- `logVerbose?: boolean` - Include verbose information in the health check
|
|
120
|
-
- `returnDiagnosticData?: boolean` - Return diagnostic data as array instead of just logging
|
|
121
|
-
- `runDetailedOverrideCheck?: boolean` - Log additional information about overridden native APIs
|
|
122
|
-
|
|
123
|
-
**Returns:**
|
|
124
|
-
- `Promise<unknown[] | undefined> | undefined` - Promise resolving to diagnostic data (if requested), or undefined if the RUM JavaScript is not available.
|
|
125
|
-
|
|
126
|
-
**Example:**
|
|
127
|
-
```typescript
|
|
128
|
-
import { runHealthCheck } from '@dynatrace/rum-javascript-sdk/api';
|
|
129
|
-
|
|
130
|
-
const diagnostics = await runHealthCheck({
|
|
131
|
-
logVerbose: true,
|
|
132
|
-
returnDiagnosticData: true
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
if (diagnostics) {
|
|
136
|
-
console.log('RUM Health Check Results:', diagnostics);
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
#### `identifyUser(value): void`
|
|
141
|
-
|
|
142
|
-
Associates the current session with a specific user identifier.
|
|
143
|
-
|
|
144
|
-
**Parameters:**
|
|
145
|
-
- `value: string` - User identifier (name, email, user ID, etc.)
|
|
146
|
-
|
|
147
|
-
**Example:**
|
|
148
|
-
```typescript
|
|
149
|
-
import { identifyUser } from '@dynatrace/rum-javascript-sdk/api';
|
|
150
|
-
|
|
151
|
-
// Identify user after login
|
|
152
|
-
identifyUser('john.doe@example.com');
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
#### `userOptIn(): void`
|
|
64
|
+
The synchronous API provides safe wrapper functions that gracefully handle cases where the Dynatrace RUM JavaScript is not available. These functions execute as no-ops if the JavaScript is not loaded, making them safe to use in any environment.
|
|
156
65
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
**Example:**
|
|
160
|
-
```typescript
|
|
161
|
-
import { userOptIn } from '@dynatrace/rum-javascript-sdk/api';
|
|
162
|
-
|
|
163
|
-
// Grant consent after the user accepts the cookie banner
|
|
164
|
-
userOptIn();
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
#### `userOptOut(): void`
|
|
168
|
-
|
|
169
|
-
Revokes consent for data collection. When opted out, no events or beacons are sent, but consent APIs remain callable.
|
|
170
|
-
|
|
171
|
-
**Example:**
|
|
172
|
-
```typescript
|
|
173
|
-
import { userOptOut } from '@dynatrace/rum-javascript-sdk/api';
|
|
174
|
-
|
|
175
|
-
// Revoke consent when the user opts out
|
|
176
|
-
userOptOut();
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
#### `sendSessionPropertyEvent(fields): void`
|
|
180
|
-
|
|
181
|
-
Sends session-level properties that will be attached to all subsequent events in the session.
|
|
182
|
-
|
|
183
|
-
**Parameters:**
|
|
184
|
-
- `fields: ApiCreatedSessionPropertiesEvent` - Session properties object. All keys must be prefixed with `session_properties.` and follow naming conventions (lowercase, numbers, underscores, dots).
|
|
185
|
-
|
|
186
|
-
**Example:**
|
|
187
|
-
```typescript
|
|
188
|
-
import { sendSessionPropertyEvent } from '@dynatrace/rum-javascript-sdk/api';
|
|
189
|
-
|
|
190
|
-
sendSessionPropertyEvent({
|
|
191
|
-
'session_properties.user_type': 'premium',
|
|
192
|
-
'session_properties.subscription_tier': 'gold',
|
|
193
|
-
'session_properties.region': 'us_east'
|
|
194
|
-
});
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
#### `sendExceptionEvent(error, fields?): void`
|
|
198
|
-
|
|
199
|
-
Sends an exception event. Marks the exception event with `characteristics.is_api_reported` and `error.source` = `api` to make it clear on DQL side where errors are coming from.
|
|
200
|
-
Only available if the Errors module is enabled.
|
|
201
|
-
|
|
202
|
-
**Parameters:**
|
|
203
|
-
|
|
204
|
-
- `error: Error` - The error object to report. Must be an instance of the standard JavaScript `Error` class.
|
|
205
|
-
- `fields: ApiCreatedEventPropertiesEvent` - Optional Event properties object. Must be serializable JSON with properties prefixed with `event_properties.`, plus optional `duration` and `start_time` properties.
|
|
206
|
-
|
|
207
|
-
**Example:**
|
|
208
|
-
```typescript
|
|
209
|
-
import { sendExceptionEvent } from '@dynatrace/rum-javascript-sdk/api';
|
|
210
|
-
|
|
211
|
-
const yourError = new Error("Your Error Message");
|
|
212
|
-
|
|
213
|
-
sendExceptionEvent(yourError);
|
|
214
|
-
```
|
|
215
|
-
```typescript
|
|
216
|
-
import { sendExceptionEvent } from '@dynatrace/rum-javascript-sdk/api';
|
|
217
|
-
|
|
218
|
-
const yourError = new Error("Your Error Message");
|
|
219
|
-
|
|
220
|
-
sendExceptionEvent(yourError, { "event_properties.component": "myExampleComponent" });
|
|
221
|
-
```
|
|
66
|
+
See the {@link SDK | SDK API reference} for the full list of available functions.
|
|
222
67
|
|
|
223
68
|
### Interactions API (`@dynatrace/rum-javascript-sdk/api/interactions`)
|
|
224
69
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
Sends a user interaction event to report custom keyboard shortcuts or key combinations.
|
|
228
|
-
Only available if the User Interaction module is enabled.
|
|
229
|
-
|
|
230
|
-
**Parameters:**
|
|
70
|
+
Report custom user interaction events via {@link API.Interactions}. See [Interactions API](./4-interactions.md) for detailed documentation and examples.
|
|
231
71
|
|
|
232
|
-
|
|
233
|
-
Keys can be `UserInteractionSpecialKey` members or raw [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) strings — raw values are normalized internally.
|
|
234
|
-
Optional `ui_element.custom_name` and `event_properties.*` entries are allowed.
|
|
235
|
-
- `elementOrEvent?: Element | KeyboardEvent` - Optional Element or KeyboardEvent to auto-capture UI element fields.
|
|
72
|
+
### Asynchronous API (`@dynatrace/rum-javascript-sdk/api/promises`)
|
|
236
73
|
|
|
237
|
-
|
|
238
|
-
```typescript
|
|
239
|
-
import * as interactions from '@dynatrace/rum-javascript-sdk/api/interactions';
|
|
240
|
-
import { UserInteractionSpecialKey } from '@dynatrace/rum-javascript-sdk/types/rum-events';
|
|
241
|
-
|
|
242
|
-
interactions.sendKeyPressEvent({
|
|
243
|
-
keys: [UserInteractionSpecialKey.CTRL, "S"],
|
|
244
|
-
"event_properties.context": "editor"
|
|
245
|
-
});
|
|
246
|
-
```
|
|
74
|
+
The {@link SDK.promises} namespace provides Promise-based functions that wait for the Dynatrace RUM JavaScript to become available. These functions throw a {@link SDK.DynatraceError} if the RUM JavaScript is not available within the specified timeout. This is useful for scenarios where you don't want to enable the RUM JavaScript before the user gives their consent.
|
|
247
75
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
### Asynchronous API (`@dynatrace/rum-javascript-sdk/promises`)
|
|
251
|
-
|
|
252
|
-
The asynchronous API provides Promise-based functions that wait for the Dynatrace RUM JavaScript to become available. These functions will throw a `DynatraceError` if the RUM JavaScript is not available within the specified timeout. This is useful for scenarios where you don't want to
|
|
253
|
-
enable the RUM JavaScript before the user gives their consent.
|
|
254
|
-
|
|
255
|
-
#### `sendEvent(fields, eventContext?, timeout?): Promise<void>`
|
|
256
|
-
|
|
257
|
-
Async wrapper for sending custom events, with automatic waiting for RUM JavaScript availability.
|
|
258
|
-
|
|
259
|
-
**Parameters:**
|
|
260
|
-
- `fields: ApiCreatedEventPropertiesEvent` - Event properties object
|
|
261
|
-
- `eventContext?: unknown` - Optional context for event modification callbacks
|
|
262
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
263
|
-
|
|
264
|
-
**Throws:**
|
|
265
|
-
- `DynatraceError` - If RUM JavaScript is not available within timeout
|
|
266
|
-
|
|
267
|
-
**Example:**
|
|
268
|
-
```typescript
|
|
269
|
-
import { sendEvent } from '@dynatrace/rum-javascript-sdk/api/promises';
|
|
270
|
-
|
|
271
|
-
try {
|
|
272
|
-
await sendEvent({
|
|
273
|
-
'event_properties.conversion': 'purchase',
|
|
274
|
-
'event_properties.value': 149.99
|
|
275
|
-
}, undefined, 15000); // 15 second timeout
|
|
276
|
-
} catch (error) {
|
|
277
|
-
console.error('Failed to send event:', error.message);
|
|
278
|
-
}
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
#### `addEventModifier(eventModifier, timeout?): Promise<Unsubscriber>`
|
|
282
|
-
|
|
283
|
-
Async wrapper for registering event modifiers, with automatic waiting for RUM JavaScript availability.
|
|
284
|
-
|
|
285
|
-
**Parameters:**
|
|
286
|
-
- `eventModifier: (jsonEvent: Readonly<JSONEvent>, eventContext?: EventContext) => JSONEvent | null` - Event modifier function
|
|
287
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
288
|
-
|
|
289
|
-
**Returns:**
|
|
290
|
-
- `Promise<Unsubscriber>` - Promise resolving to unsubscriber function
|
|
291
|
-
|
|
292
|
-
**Example:**
|
|
293
|
-
```typescript
|
|
294
|
-
import { addEventModifier } from '@dynatrace/rum-javascript-sdk/api/promises';
|
|
295
|
-
|
|
296
|
-
const unsubscribe = await addEventModifier((event) => ({
|
|
297
|
-
...event,
|
|
298
|
-
'event_properties.environment': 'production'
|
|
299
|
-
}));
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
#### `runHealthCheck(config?, timeout?): Promise<unknown[] | undefined>`
|
|
303
|
-
|
|
304
|
-
Async wrapper for running health checks, with automatic waiting for RUM JavaScript availability.
|
|
305
|
-
|
|
306
|
-
**Parameters:**
|
|
307
|
-
- `config?: HealthCheckConfig` - Optional health check configuration
|
|
308
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
309
|
-
|
|
310
|
-
**Returns:**
|
|
311
|
-
- `Promise<unknown[] | undefined>` - Promise resolving to diagnostic data
|
|
312
|
-
|
|
313
|
-
#### `identifyUser(value, timeout?): Promise<void>`
|
|
314
|
-
|
|
315
|
-
Async wrapper for user identification, with automatic waiting for RUM JavaScript availability.
|
|
316
|
-
|
|
317
|
-
**Parameters:**
|
|
318
|
-
- `value: string` - User identifier
|
|
319
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
320
|
-
|
|
321
|
-
#### `userOptIn(timeout?): Promise<void>`
|
|
322
|
-
|
|
323
|
-
Async wrapper for granting consent for data collection, with automatic waiting for RUM JavaScript availability.
|
|
324
|
-
|
|
325
|
-
**Parameters:**
|
|
326
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
327
|
-
|
|
328
|
-
**Example:**
|
|
329
|
-
```typescript
|
|
330
|
-
import { userOptIn } from '@dynatrace/rum-javascript-sdk/api/promises';
|
|
331
|
-
|
|
332
|
-
await userOptIn();
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
#### `userOptOut(timeout?): Promise<void>`
|
|
336
|
-
|
|
337
|
-
Async wrapper for revoking consent for data collection, with automatic waiting for RUM JavaScript availability.
|
|
338
|
-
|
|
339
|
-
**Parameters:**
|
|
340
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
341
|
-
|
|
342
|
-
**Example:**
|
|
343
|
-
```typescript
|
|
344
|
-
import { userOptOut } from '@dynatrace/rum-javascript-sdk/api/promises';
|
|
345
|
-
|
|
346
|
-
await userOptOut();
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
#### `sendSessionPropertyEvent(fields, timeout?): Promise<void>`
|
|
350
|
-
|
|
351
|
-
Async wrapper for sending session properties, with automatic waiting for RUM JavaScript availability.
|
|
352
|
-
|
|
353
|
-
**Parameters:**
|
|
354
|
-
- `fields: ApiCreatedSessionPropertiesEvent` - Session properties object
|
|
355
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
356
|
-
|
|
357
|
-
#### `sendExceptionEvent(error, fields?): void`
|
|
358
|
-
|
|
359
|
-
Async wrapper for sending an exception event, with automatic waiting for RUM JavaScript availability.
|
|
360
|
-
Marks the exception event with `characteristics.is_api_reported` and `error.source` = `api` to make it clear on DQL side where errors are coming from.
|
|
361
|
-
Only available if the Errors module is enabled.
|
|
362
|
-
|
|
363
|
-
**Parameters:**
|
|
364
|
-
|
|
365
|
-
- `error: Error` - The error object to report. Must be an instance of the standard JavaScript `Error` class.
|
|
366
|
-
- `fields: ApiCreatedEventPropertiesEvent` - Optional Event properties object. Must be serializable JSON with properties prefixed with `event_properties.`, plus optional `duration` and `start_time` properties.
|
|
367
|
-
|
|
368
|
-
### Interactions API (`@dynatrace/rum-javascript-sdk/api/promises/interactions`)
|
|
369
|
-
|
|
370
|
-
#### `sendKeyPressEvent(fields, elementOrEvent?, timeout?): Promise<void>`
|
|
371
|
-
|
|
372
|
-
Async wrapper for sending a user interaction event, with automatic waiting for RUM JavaScript availability.
|
|
373
|
-
Only available if the User Interaction module is enabled.
|
|
374
|
-
|
|
375
|
-
**Parameters:**
|
|
376
|
-
|
|
377
|
-
- `fields: SendUserInteractionFields` - Must be a JSON-serializable object with a `keys` array (at least one key).
|
|
378
|
-
Keys can be `UserInteractionSpecialKey` members or raw [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) strings — raw values are normalized internally.
|
|
379
|
-
Optional `ui_element.custom_name` and `event_properties.*` entries are allowed.
|
|
380
|
-
- `elementOrEvent?: Element | KeyboardEvent` - Optional Element or KeyboardEvent to auto-capture UI element fields.
|
|
381
|
-
- `timeout?: number` - Timeout in milliseconds to wait for RUM JavaScript (default: 10,000)
|
|
76
|
+
Each function mirrors its synchronous counterpart with an additional `timeout` parameter (default: {@link SDK.promises.DEFAULT_AGENT_TIMEOUT}).
|
|
382
77
|
|
|
383
78
|
### User Actions API
|
|
384
79
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
**Synchronous API:**
|
|
388
|
-
```typescript
|
|
389
|
-
import {
|
|
390
|
-
createUserAction,
|
|
391
|
-
subscribeToUserActions,
|
|
392
|
-
setAutomaticUserActionDetection,
|
|
393
|
-
getCurrentUserAction
|
|
394
|
-
} from '@dynatrace/rum-javascript-sdk/api';
|
|
395
|
-
|
|
396
|
-
// Create a manual user action
|
|
397
|
-
const userAction = createUserAction({ autoClose: false });
|
|
398
|
-
// perform work
|
|
399
|
-
userAction?.finish();
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
**Asynchronous API:**
|
|
403
|
-
```typescript
|
|
404
|
-
import { createUserAction } from '@dynatrace/rum-javascript-sdk/api/promises';
|
|
405
|
-
|
|
406
|
-
const userAction = await createUserAction({ autoClose: false });
|
|
407
|
-
// perform work
|
|
408
|
-
userAction.finish();
|
|
409
|
-
```
|
|
80
|
+
Manual control over user action creation and lifecycle via {@link API.UserActions}. Both synchronous and asynchronous wrappers are available. See [User Actions API](./3-useractions.md) for detailed documentation and examples.
|
|
410
81
|
|
|
411
82
|
## Error Handling
|
|
412
83
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
Both APIs export a `DynatraceError` class for handling RUM-specific errors:
|
|
416
|
-
|
|
417
|
-
```typescript
|
|
418
|
-
import { sendEvent, DynatraceError } from '@dynatrace/rum-javascript-sdk/promises';
|
|
419
|
-
|
|
420
|
-
try {
|
|
421
|
-
await sendEvent({ 'event_properties.test': 'value' });
|
|
422
|
-
} catch (error) {
|
|
423
|
-
if (error instanceof DynatraceError) {
|
|
424
|
-
console.error('RUM API Error:', error.message);
|
|
425
|
-
// Handle RUM-specific error
|
|
426
|
-
} else {
|
|
427
|
-
console.error('Unexpected error:', error);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
```
|
|
84
|
+
The {@link SDK.DynatraceError} class is thrown by the asynchronous API when the RUM JavaScript is not available within the specified timeout.
|
|
431
85
|
|
|
432
86
|
## TypeScript Support
|
|
433
87
|
|
|
434
|
-
For detailed type information and usage examples, see [Dynatrace Api Types](./
|
|
88
|
+
For detailed type information and usage examples, see [Dynatrace Api Types](./2-types.md).
|
|
435
89
|
|
|
436
90
|
```typescript
|
|
437
91
|
import type {
|
|
@@ -445,12 +99,30 @@ import type {
|
|
|
445
99
|
|
|
446
100
|
## Testing
|
|
447
101
|
|
|
448
|
-
|
|
102
|
+
:::warning
|
|
103
|
+
The Playwright testing framework has been extracted to a separate package:
|
|
104
|
+
**`@dynatrace/rum-javascript-sdk-playwright`**
|
|
105
|
+
|
|
106
|
+
**Migration:**
|
|
107
|
+
|
|
108
|
+
1. Install the new package as a dev dependency:
|
|
109
|
+
```bash
|
|
110
|
+
npm install --save-dev @dynatrace/rum-javascript-sdk-playwright
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
2. Update your imports:
|
|
114
|
+
```typescript
|
|
115
|
+
// Before
|
|
116
|
+
import { test } from "@dynatrace/rum-javascript-sdk/test";
|
|
117
|
+
|
|
118
|
+
// After
|
|
119
|
+
import { test } from "@dynatrace/rum-javascript-sdk-playwright";
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
3. All APIs remain the same — only the import path changes.
|
|
123
|
+
:::
|
|
449
124
|
|
|
450
|
-
-
|
|
451
|
-
- Fixture usage and ordering
|
|
452
|
-
- Event assertion methods
|
|
453
|
-
- Troubleshooting guide
|
|
125
|
+
See the [Testing with Playwright](../../rum-javascript-sdk-playwright/docs/1-testing.md) documentation for setup and usage.
|
|
454
126
|
|
|
455
127
|
## Best Practices
|
|
456
128
|
|
|
@@ -468,7 +140,7 @@ This package includes a Playwright testing framework for validating RUM integrat
|
|
|
468
140
|
|
|
469
141
|
### Event Property Naming
|
|
470
142
|
|
|
471
|
-
Follow prefix custom event properties with `event_properties
|
|
143
|
+
Follow prefix custom event properties with `event_properties.` when calling {@link API.dynatrace.sendEvent | sendEvent}:
|
|
472
144
|
|
|
473
145
|
```typescript
|
|
474
146
|
// ✅ Good - properties with prefix are accepted
|
|
@@ -488,7 +160,7 @@ sendEvent({
|
|
|
488
160
|
|
|
489
161
|
### Session Properties
|
|
490
162
|
|
|
491
|
-
Use session properties for data that applies to the entire user session:
|
|
163
|
+
Use {@link API.dynatrace.sendSessionPropertyEvent | session properties} for data that applies to the entire user session:
|
|
492
164
|
|
|
493
165
|
```typescript
|
|
494
166
|
// Set once per session
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: Dynatrace Api Types
|
|
3
3
|
---
|
|
4
4
|
# Dynatrace Api Types
|
|
5
|
-
This package contains the Typescript type information for the `dynatrace` API of the RUM JavaScript.
|
|
5
|
+
This package contains the Typescript type information for the {@link API.dynatrace | `dynatrace`} API of the RUM JavaScript.
|
|
6
6
|
|
|
7
7
|
Keep in mind that when the RUM JavaScript is updated, this type package also has to be updated to provide accurate types.
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ Keep in mind that when the RUM JavaScript is updated, this type package also has
|
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
npm install --save-dev @dynatrace/rum-javascript-sdk
|
|
13
|
-
|
|
13
|
+
```
|
|
14
14
|
|
|
15
15
|
## Configuration
|
|
16
16
|
Make sure to add these paths to `"typeRoots"` in tsconfig.json under `"compilerOptions"`
|
|
@@ -19,7 +19,7 @@ Make sure to add these paths to `"typeRoots"` in tsconfig.json under `"compilerO
|
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Usage examples
|
|
22
|
-
Type inference works out of the box for dynatrace calls.
|
|
22
|
+
Type inference works out of the box for {@link API.dynatrace | dynatrace} calls.
|
|
23
23
|
```ts
|
|
24
24
|
if (window.dynatrace) {
|
|
25
25
|
window.dynatrace.sendEvent({
|
|
@@ -47,5 +47,5 @@ if (window.dynatrace) {
|
|
|
47
47
|
}
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
Refer to the [User Actions API](./
|
|
51
|
-
Refer to the [Interactions API](./
|
|
50
|
+
Refer to the [User Actions API](./3-useractions.md) for details about {@link API.dynatrace.userActions | `dynatrace.userActions`}.
|
|
51
|
+
Refer to the [Interactions API](./4-interactions.md) for details about {@link API.dynatrace.interactions | `dynatrace.interactions`}.
|