* Reorganize PageViewsController * Add domain and path to PageView model * Add before_create callback to populate domain and path * Add list of referrers to AnalyticsService * Add referrers to the UI * Remove useless referrers card and tweak table line height * Add referrer stats to article stats page * Add not null and empty default to domain and path * Refactor JS analytics client * create_list is a step back here * Revert "Add not null and empty default to domain and path" This reverts commit bc02440076047a887c65d300bccd4661ecc8ffd0. * Add index on domain concurrently * Make the script more robust
45 lines
1,016 B
JavaScript
45 lines
1,016 B
JavaScript
import handleFetchAPIErrors from '../src/utils/errors';
|
|
|
|
function callAnalyticsAPI(path, date, { organizationId, articleId }, callback) {
|
|
let url = `${path}?start=${date.toISOString().split('T')[0]}`;
|
|
|
|
if (organizationId) {
|
|
url = `${url}&organization_id=${organizationId}`;
|
|
}
|
|
if (articleId) {
|
|
url = `${url}&article_id=${articleId}`;
|
|
}
|
|
|
|
fetch(url)
|
|
.then(handleFetchAPIErrors)
|
|
.then(response => response.json())
|
|
.then(callback)
|
|
// eslint-disable-next-line no-console
|
|
.catch(error => console.error(error)); // we should come up with better error handling
|
|
}
|
|
|
|
export function callHistoricalAPI(
|
|
date,
|
|
{ organizationId, articleId },
|
|
callback,
|
|
) {
|
|
callAnalyticsAPI(
|
|
'/api/analytics/historical',
|
|
date,
|
|
{ organizationId, articleId },
|
|
callback,
|
|
);
|
|
}
|
|
|
|
export function callReferrersAPI(
|
|
date,
|
|
{ organizationId, articleId },
|
|
callback,
|
|
) {
|
|
callAnalyticsAPI(
|
|
'/api/analytics/referrers',
|
|
date,
|
|
{ organizationId, articleId },
|
|
callback,
|
|
);
|
|
}
|