Skip to content

Commit 7ac489a

Browse files
author
Michael Levin
committed
[Feature] Add GA4 metrics to DataLoader methods
1 parent b7db074 commit 7ac489a

37 files changed

Lines changed: 433 additions & 115 deletions

jest_setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ window.fetch = jest.fn(() => {
2525
};
2626
});
2727

28+
window.gas4 = jest.fn();
29+
2830
// Stub Math.random. Used to create random ids for tooltip element.
2931
const mockMath = Object.create(global.Math);
3032
mockMath.random = () => 0.5;

js/components/dashboard_content/AverageEngagementDuration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function AverageEngagementDuration({ dataHrefBase }) {
2626
useEffect(() => {
2727
const initEngagementDurationsChart = async () => {
2828
if (!engagementDurationData) {
29-
const data = await DataLoader.loadJSON(jsonDataURL);
29+
const data = await DataLoader.loadDailyReportJSON(jsonDataURL);
3030
await setEngagementDurationData(data);
3131
} else {
3232
const chartBuilder = new ChartBuilder();

js/components/dashboard_content/BrowsersChart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function BrowsersChart({ dataHrefBase }) {
4040
let data;
4141

4242
try {
43-
data = await DataLoader.loadJSON(
43+
data = await DataLoader.loadDailyReportJSON(
4444
`${dataHrefBase}/${currentFilter[1]}.json`,
4545
);
4646
} catch (e) {

js/components/dashboard_content/DevicesChart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function DevicesChart({ dataHrefBase }) {
4141
let data;
4242

4343
try {
44-
data = await DataLoader.loadJSON(
44+
data = await DataLoader.loadDailyReportJSON(
4545
`${dataHrefBase}/${currentFilter[1]}.json`,
4646
);
4747
} catch (e) {

js/components/dashboard_content/EngagementRate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function EngagementRate({ dataHrefBase }) {
2525
useEffect(() => {
2626
const initEngagementRateChart = async () => {
2727
if (!engagementRateData) {
28-
const data = await DataLoader.loadJSON(jsonDataURL);
28+
const data = await DataLoader.loadDailyReportJSON(jsonDataURL);
2929
await setEngagementRateData(data);
3030
} else {
3131
const chartBuilder = new ChartBuilder();

js/components/dashboard_content/OperatingSystemsChart.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function OperatingSystemsChart({ dataHrefBase }) {
4444
let windowsData;
4545

4646
try {
47-
osData = await DataLoader.loadJSON(
47+
osData = await DataLoader.loadDailyReportJSON(
4848
`${dataHrefBase}/os-${currentFilter[1]}.json`,
4949
);
5050
} catch (e) {
@@ -53,7 +53,7 @@ function OperatingSystemsChart({ dataHrefBase }) {
5353
await buildOsChartForData(osData);
5454

5555
try {
56-
windowsData = await DataLoader.loadJSON(
56+
windowsData = await DataLoader.loadDailyReportJSON(
5757
`${dataHrefBase}/windows-${currentFilter[1]}.json`,
5858
);
5959
} catch (e) {

js/components/dashboard_content/RealtimeVisitors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ function RealtimeVisitors({ dataHrefBase, agency, refreshSeconds }) {
2626
useEffect(() => {
2727
const initRealtimeVisitorsChart = async () => {
2828
if (!realtimeVisitorData) {
29-
const data = await DataLoader.loadJSON(dataURL);
29+
const data = await DataLoader.loadRealtimeReportJSON(dataURL);
3030
await setRealtimeVisitorData(data);
3131
// Refresh data every interval. useEffect will run and update the chart
3232
// when the state is changed.
3333
setInterval(() => {
34-
DataLoader.loadJSON(dataURL).then((data) => {
34+
DataLoader.loadRealtimeReportJSON(dataURL).then((data) => {
3535
setRealtimeVisitorData(data);
3636
});
3737
}, refreshSeconds * 1000);

js/components/dashboard_content/ScreenResolutionsChart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function ScreenResolutionsChart({ dataHrefBase }) {
4040
let data;
4141

4242
try {
43-
data = await DataLoader.loadJSON(
43+
data = await DataLoader.loadDailyReportJSON(
4444
`${dataHrefBase}/${currentFilter[1]}.json`,
4545
);
4646
} catch (e) {

js/components/dashboard_content/Sessions30Days.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function Sessions30Days({ dataHrefBase }) {
2626
useEffect(() => {
2727
const initSessionsChart = async () => {
2828
if (!sessionData) {
29-
const data = await DataLoader.loadJSON(jsonDataURL);
29+
const data = await DataLoader.loadDailyReportJSON(jsonDataURL);
3030
await setSessionData(data);
3131
} else {
3232
const chartBuilder = new ChartBuilder();

js/components/dashboard_content/TopCities.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ function TopCities({ dataHrefBase, refreshSeconds }) {
5858
let data;
5959

6060
try {
61-
data = await DataLoader.loadJSON(
62-
`${dataHrefBase}/${currentFilter[1]}.json`,
63-
);
61+
const url = `${dataHrefBase}/${currentFilter[1]}.json`;
62+
63+
if (isRealtime) {
64+
data = await DataLoader.loadRealtimeReportJSON(url);
65+
} else {
66+
data = await DataLoader.loadDailyReportJSON(url);
67+
}
6468
} catch (e) {
6569
data = { data: [], totals: {} };
6670
}

0 commit comments

Comments
 (0)