@robotical/appv2-analytics-gatherer
Version:
A tool that gathers data from the Apps and sends it to the Analytics server
22 lines (21 loc) • 791 B
JavaScript
import Logger from "../services/Logger";
import Transport from "../transport/server";
import { ServerEndpoints } from "../types/types";
const SHOW_LOGS = true;
const TAG = 'core/consent';
export const trackConsentRatio = async (consent) => {
Logger.info(SHOW_LOGS, TAG, `Tracking consent: ${consent}`);
try {
const response = await Transport.post(ServerEndpoints.TRACK_CONSENT, { consent });
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;
}
};