cartodb-4.42/lib/assets/javascripts/new-dashboard/core/metrics.js

28 lines
710 B
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
import store from 'new-dashboard/store';
import MetricsTypes from 'builder/components/metrics/metrics-types';
export { MetricsTypes };
export function sendMetric (eventName, eventProperties) {
const baseURL = store.state.config.base_url;
const requestURL = `${baseURL}/api/v3/metrics`;
const requestData = getJSONMetricsData(eventName, eventProperties);
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(requestData)
};
return fetch(requestURL, requestOptions);
}
function getJSONMetricsData (name, properties) {
return {
name,
properties: {
...properties,
user_id: store.state.user.id
}
};
}