|
2 | 2 | (function () {
|
3 | 3 | const activityKey = 'webhint-activity';
|
4 | 4 | const storage = window.localStorage;
|
5 |
| - const telemetryApiEndpoint = ''; |
| 5 | + const telemetryApiEndpoint = 'http://localhost:7071/api/webhint-telemetry-ingress-api'; |
6 | 6 | let nameKey = '';
|
7 | 7 | let sendTimeout = null;
|
8 | 8 | let telemetryQueue = [];
|
|
11 | 11 | defaultProperties: {},
|
12 | 12 | enabled: false,
|
13 | 13 | instrumentationKey: '8ef2b55b-2ce9-4c33-a09a-2c3ef605c97d',
|
14 |
| - post: (url, data) => { |
15 |
| - return Promise.resolve(200); |
16 |
| - } |
17 | 14 | };
|
18 | 15 |
|
| 16 | + const post = async (url, data) => { |
| 17 | + const response = await fetch(url, { |
| 18 | + method: 'POST', |
| 19 | + headers: { |
| 20 | + 'Content-Type': 'application/json' |
| 21 | + }, |
| 22 | + body: data |
| 23 | + }); |
| 24 | + return response; |
| 25 | + } |
| 26 | + |
19 | 27 | const sendTelemetry = async () => {
|
20 | 28 | if (sendTimeout) {
|
21 | 29 | clearTimeout(sendTimeout);
|
|
24 | 32 | const data = JSON.stringify(telemetryQueue);
|
25 | 33 | telemetryQueue = [];
|
26 | 34 | try {
|
27 |
| - const status = await options.post(telemetryApiEndpoint, data); |
28 |
| - if (status !== 200) { |
29 |
| - console.warn('Failed to send telemetry: ', status); |
30 |
| - } |
| 35 | + post(telemetryApiEndpoint, data) |
| 36 | + .then(response => { |
| 37 | + if (response.status !== 200) { |
| 38 | + console.warn('Failed to send telemetry: ', status); |
| 39 | + } |
| 40 | + }); |
31 | 41 | }
|
32 | 42 | catch (err) {
|
33 | 43 | console.warn('Failed to send telemetry: ', err);
|
|
60 | 70 | await track('Event', { name, properties });
|
61 | 71 | };
|
62 | 72 |
|
63 |
| - const testAsync = async () => { |
64 |
| - return new Promise(resolve => { |
65 |
| - setTimeout(() => { |
66 |
| - resolve('resolved'); |
67 |
| - }, 2000); |
68 |
| - }); |
69 |
| - } |
70 |
| - |
71 | 73 | const getISODateString = () => {
|
72 | 74 | const date = new Date(Date.now());
|
73 | 75 | date.setUTCHours(0);
|
|
0 commit comments