web/satellite/src/api: Absorb analytics errors

On more privacy-sensitive browsers, attempts to notify the satellite
about client-side events might be blocked, because the API endpoint on
the satellite contains the word "analytics".

We want to respect the privacy of these types of visitors, so rather
than changing the name of the endpoint to something else, this change
catches errors that are caused by attempting to use the analytics API,
and logs them to the console without interrupting the user's experience
of the website. These errors do not affect any essential behavior, so it
is okay if the user is not aware of them.

Change-Id: I6f49e0abcd64fd69802e4efa71a8d307cc5a3aee
This commit is contained in:
Moby von Briesen 2021-04-14 21:00:53 +02:00 committed by Maximillian von Briesen
parent 031206e453
commit 569942c04d

View File

@ -12,12 +12,13 @@ export class AnalyticsHttpApi {
private readonly ROOT_PATH: string = '/api/v0/analytics';
/**
* Used to get authentication token.
* Used to notify the satellite about arbitrary events that occur.
* Does not throw any errors so that expected UI behavior is not interrupted if the API call fails.
*
* @param eventName - name of the event
* @throws Error
*/
public async eventTriggered(eventName: string): Promise<void> {
try {
const path = `${this.ROOT_PATH}/event`;
const body = {
eventName: eventName,
@ -26,11 +27,21 @@ export class AnalyticsHttpApi {
if (response.ok) {
return;
}
throw new Error('Can not track event');
console.error("Attempted to notify Satellite that " + eventName + " occurred. Got bad response status code: " + response.status)
} catch(error) {
console.error("Could not notify satellite about " + eventName + " event occurrence (most likely blocked by browser).")
}
}
/**
* Used to notify the satellite about arbitrary external link clicked events that occur.
* Does not throw any errors so that expected UI behavior is not interrupted if the API call fails.
*
* @param eventName - name of the event
* @param link - link that was clicked
*/
public async linkEventTriggered(eventName: string, link: string): Promise<void> {
try {
const path = `${this.ROOT_PATH}/event`;
const body = {
eventName: eventName,
@ -40,6 +51,9 @@ export class AnalyticsHttpApi {
if (response.ok) {
return;
}
throw new Error('Can not track event');
console.error("Attempted to notify Satellite that " + eventName + " occurred. Got bad response status code: " + response.status)
} catch(error) {
console.error("Could not notify satellite about " + eventName + " event occurrence (most likely blocked by browser).")
}
}
}