(payload: TrackHandlerPayload)
| 118 | } |
| 119 | |
| 120 | async send(payload: TrackHandlerPayload) { |
| 121 | if (this.options.filter && !this.options.filter(payload)) { |
| 122 | return Promise.resolve(); |
| 123 | } |
| 124 | |
| 125 | if (this.shouldQueue(payload)) { |
| 126 | this.addQueue(payload); |
| 127 | return Promise.resolve(); |
| 128 | } |
| 129 | |
| 130 | // Disable keepalive for replay since it has a hard body limit and breaks the request |
| 131 | const result = await this.api.fetch< |
| 132 | TrackHandlerPayload, |
| 133 | { deviceId: string; sessionId: string } |
| 134 | >('/track', payload, { keepalive: payload.type !== 'replay' }); |
| 135 | this.deviceId = result?.deviceId; |
| 136 | const hadSession = !!this.sessionId; |
| 137 | this.sessionId = result?.sessionId; |
| 138 | |
| 139 | // Flush queued items (e.g. replay chunks) when sessionId first arrives |
| 140 | if (!hadSession && this.sessionId) { |
| 141 | this.flush(); |
| 142 | } |
| 143 | |
| 144 | return result; |
| 145 | } |
| 146 | |
| 147 | setGlobalProperties(properties: Record<string, unknown>) { |
| 148 | this.global = { |
no test coverage detected