@robotical/appv2-analytics-gatherer
Version:
A tool that gathers data from the Apps and sends it to the Analytics server
23 lines (22 loc) • 914 B
JavaScript
import Logger from "../services/Logger";
import Transport from "../transport/server";
import { ServerEndpoints } from "../types/types";
const SHOW_LOGS = true;
const TAG = 'core/screenVisits';
export const captureScreenVisit = async (screen, sessionId, deviceId, raftType, robotId) => {
Logger.info(SHOW_LOGS, TAG, `Capturing screen visit of type: ${screen}`);
try {
const data = { screen, sessionId, deviceId, raftType, robotId };
const response = await Transport.post(ServerEndpoints.SCREEN_VISIT, data);
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Error response from server: ${errorText}`);
}
Logger.info(SHOW_LOGS, TAG, 'Consent tracked successfully');
return true;
}
catch (error) {
Logger.error(SHOW_LOGS, TAG, 'Failed to track consent', error);
return false;
}
};