Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('set', {app_name: 'Pen'});
gtag('config', 'G-T8GEX2GPTP');
</script>

Expand Down
7 changes: 6 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ThemeProvider, createTheme } from '@mui/material/styles';

import "./App.css";

import { gaWatchStore, gaErrorReport } from "./ga";
import { gaWatchStore, gaErrorReport, gaLangChange } from "./ga";
import DocTitle from "./DocTitle";
import Header from "./Header";
import Footer from "./Footer";
Expand All @@ -15,6 +15,11 @@ import i18n from "./i18n";
import store from "./store";
gaWatchStore(store);

i18n.on("languageChanged", (lng) => {
gaLangChange(lng);
window.document.documentElement.setAttribute('lang', lng);
});

const theme = createTheme({
palette: {
primary: {
Expand Down
35 changes: 25 additions & 10 deletions src/ga.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { debounce, partial } from "lodash";
import { reaction } from "mobx";

export const gtagEvent = (action, params) => {
if (window.gtag) {
window.gtag("event", action, {
app_name: "pen",
...params,
});
} else {
console.warn("gtag not available, event not sent", action, params);
}
};

export const trackEvent = (action, label) => {
window.gtag("event", action, {
eventLabel: label
gtagEvent("event", action, {
event_label: label,
});
};

Expand All @@ -15,26 +26,30 @@ export const xHeightChange = partial(trackEvent, "change_x_height");

export const outputAttempt = partial(trackEvent, "output_attempt");

const reactRatio = ratio => {
export const gaLangChange = (lng) => {
gtagEvent("language_change", { language: lng });
};

const reactioRatio = (ratio) => {
presetChange(ratio);
};

const reactRatios = args => {
const reactioRatios = (args) => {
const [ratio, ...ratios] = args;
if (ratio === "custom") ratiosChange(ratios.join(":"));
};

const reactXHeight = height => {
const reactioXHeight = (height) => {
xHeightChange(height);
};

export const gaWatchStore = store => {
reaction(() => store.ratio, reactRatio);
reaction(() => [store.ratio, ...store.ratios], debounce(reactRatios, 500));
reaction(() => store.xHeight, debounce(reactXHeight, 500));
export const gaWatchStore = (store) => {
reaction(() => store.ratio, reactioRatio);
reaction(() => [store.ratio, ...store.ratios], debounce(reactioRatios, 500));
reaction(() => store.xHeight, debounce(reactioXHeight, 500));
};

export const gaErrorReport = e => {
export const gaErrorReport = (e) => {
console.error(e);
window.gtag && window.gtag("exception", { description: e.message });
};