|
62 | 62 | // #functionsBaseUrl = 'http://localhost:7071/api/'; // Local testing
|
63 | 63 | #functionsBaseUrl = 'https://cc-awards.azurewebsites.net/api/'; // Production
|
64 | 64 |
|
| 65 | + #badgeClaimedTrackingUrl = 'https://m365-visitor-stats.azurewebsites.net/copilot-camp/badge-claimed/'; // Badge claimed tracking URL |
| 66 | + |
65 | 67 | #debugMode = false; // Debug mode
|
66 | 68 |
|
67 | 69 | constructor() {
|
|
101 | 103 | awardButton.className = 'award-button';
|
102 | 104 | awardButton.onclick = this.#clickHandler;
|
103 | 105 | this.#containerElement.appendChild(awardButton);
|
104 |
| - |
| 106 | + |
105 | 107 | // Hide the container by default
|
106 | 108 | this.#containerElement.style.display = 'none';
|
107 | 109 |
|
|
184 | 186 | }
|
185 | 187 |
|
186 | 188 | async #updateAwardStatus(pathName, isEligible) {
|
187 |
| - // Update the award status for the current user |
188 |
| - const uniqueId = this.#ensureAwardUniqueId(); |
189 |
| - const awardStatusUrl = `${this.#functionsBaseUrl}assignAward/${uniqueId}/${pathName}`; |
190 |
| - const response = await fetch(awardStatusUrl, { |
191 |
| - method: 'POST', |
192 |
| - headers: { |
193 |
| - 'Content-Type': 'application/json' |
194 |
| - }, |
195 |
| - body: JSON.stringify({ status: isEligible }) |
196 |
| - }); |
197 |
| - if (!response.ok) { |
198 |
| - console.error('Failed to update award status:', response.status, response.statusText); |
| 189 | + |
| 190 | + try { |
| 191 | + // Update the award status for the current user |
| 192 | + const uniqueId = this.#ensureAwardUniqueId(); |
| 193 | + const awardStatusUrl = `${this.#functionsBaseUrl}assignAward/${uniqueId}/${pathName}`; |
| 194 | + const awardStatusResponse = await fetch(awardStatusUrl, { |
| 195 | + method: 'POST', |
| 196 | + headers: { |
| 197 | + 'Content-Type': 'application/json' |
| 198 | + }, |
| 199 | + body: JSON.stringify({ status: isEligible }) |
| 200 | + }); |
| 201 | + if (!awardStatusResponse.ok) { |
| 202 | + console.error('Failed to update award status via API:', awardStatusResponse.status, awardStatusResponse.statusText); |
| 203 | + } |
| 204 | + } catch (error) { |
| 205 | + console.error('Failed to update award status:', error); |
| 206 | + } |
| 207 | + |
| 208 | + try { |
| 209 | + if (isEligible) { |
| 210 | + // Track the award status on telemetry |
| 211 | + const awardTrackingUrl = `${this.#badgeClaimedTrackingUrl}${pathName}`; |
| 212 | + const trackingResponse = await fetch(awardTrackingUrl, { |
| 213 | + method: 'GET' |
| 214 | + }); |
| 215 | + if (!trackingResponse.ok) { |
| 216 | + console.error('Failed to track award status via telemetry:', response.status, response.statusText); |
| 217 | + } |
| 218 | + } |
| 219 | + } catch (error) { |
| 220 | + console.error('Failed to track award status:', error); |
199 | 221 | }
|
| 222 | + |
200 | 223 | }
|
201 | 224 |
|
202 | 225 | // Public method to check award eligibility
|
|
0 commit comments