storj/web/satellite/src/api/analytics.ts
Moby von Briesen 7e4e1040f2 satellite/console: Add endpoint for clientside analytics events
This is a very simple endpoint which allows the satellite UI client to
notify the console server that an event has occurred. We will use this
to track when users have completed certain tasks that can't be tracked
server-side (e.g. generating gateway credentials, setting a passphrase)

As part of this change, one client side event is implemented to use the
endpoint - when the user clicks the button to create gateway credentials
after making a new access grant.

Change-Id: Ic8fa729f1c84474788e1de84c18532aef8e8fa3c
2021-04-07 14:23:26 +00:00

32 lines
887 B
TypeScript

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
import { HttpClient } from '@/utils/httpClient';
/**
* AnalyticsHttpApi is a console Analytics API.
* Exposes all analytics-related functionality
*/
export class AnalyticsHttpApi {
private readonly http: HttpClient = new HttpClient();
private readonly ROOT_PATH: string = '/api/v0/analytics';
/**
* Used to get authentication token.
*
* @param eventName - name of the event
* @throws Error
*/
public async eventTriggered(eventName: string): Promise<void> {
const path = `${this.ROOT_PATH}/event`;
const body = {
eventName: eventName,
};
const response = await this.http.post(path, JSON.stringify(body));
if (response.ok) {
return;
}
throw new Error('Can not track event');
}
}