Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task/WG-191: do not use headers for analytics information due to WG-191 #180

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions angular/src/app/app.interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 of needed) the guestUserID in local storage
nathanfranklin marked this conversation as resolved.
Show resolved Hide resolved
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 (
Expand Down Expand Up @@ -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<any>): 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()
Expand Down
Loading