diff --git a/angular/src/app/app.interceptors.ts b/angular/src/app/app.interceptors.ts index e8bd2f23..cbc699e1 100644 --- a/angular/src/app/app.interceptors.ts +++ b/angular/src/app/app.interceptors.ts @@ -38,29 +38,34 @@ export class JwtInterceptor implements HttpInterceptor { }); } - // for guest users, add a custom header with a unique id - if (!this.authSvc.isLoggedIn()) { - // Get (or create of needed) the guestUserID in local storage - let guestUuid = localStorage.getItem('guestUuid'); - - if (!guestUuid) { - guestUuid = uuidv4(); - localStorage.setItem('guestUuid', guestUuid); - } - request = request.clone({ - setHeaders: { - 'X-Guest-UUID': guestUuid, - }, - }); - } - if (request.url.indexOf(this.envService.apiUrl) > -1) { // Add information about what app is making the request - request = request.clone({ - setHeaders: { - 'X-Geoapi-Application': 'hazmapper', - }, - }); + + // Using query params instead of custom headers due to https://tacc-main.atlassian.net/browse/WG-191 + let analytics_params = {}; + + analytics_params = { ...analytics_params, application: 'hazmapper' }; + + // for guest users, add a unique id + if (!this.authSvc.isLoggedIn()) { + // Get (or create if needed) the guestUserID in local storage + let guestUuid = localStorage.getItem('guestUuid'); + + if (!guestUuid) { + guestUuid = uuidv4(); + localStorage.setItem('guestUuid', guestUuid); + } + + analytics_params = { ...analytics_params, guest_uuid: guestUuid }; + } + /* Send analytics-related params to projects endpoint only (until we use headers + again in https://tacc-main.atlassian.net/browse/WG-192) */ + if (this.isProjectFeaturesRequest(request)) { + // Clone the request and add query parameters + request = request.clone({ + setParams: { ...request.params, ...analytics_params }, + }); + } } if ( @@ -89,6 +94,17 @@ export class JwtInterceptor implements HttpInterceptor { return next.handle(request); } + + /** + * Determines whether a given HTTP request targets the features endpoint of a project or public project. + * + * This endpoint is being logged with extra information for analytics purposes. + */ + private isProjectFeaturesRequest(request: HttpRequest): boolean { + // Regular expression to match /projects/{projectId}/features or /public-projects/{projectId}/features + const urlPattern = /\/(projects|public-projects)\/\d+\/features\/?(?:\?.*)?/; + return request.method === 'GET' && urlPattern.test(request.url); + } } @Injectable()