Feature(analytics): Add redux logic for analytics
Add(nav): Add event tracking to nav bar Add(Drawer): Add event tracking to chat/map drawer
This commit is contained in:
6
client/utils/send-page-analytics.js
Normal file
6
client/utils/send-page-analytics.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default function sendPageAnalytics(history, ga) {
|
||||
history.listen(location => {
|
||||
ga('set', 'page', location.pathname + location.search);
|
||||
ga('send', 'pageview');
|
||||
});
|
||||
}
|
44
client/utils/use-lang-routes.js
Normal file
44
client/utils/use-lang-routes.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import { addLang, getLangFromPath } from '../../common/app/utils/lang.js';
|
||||
|
||||
function addLangToLocation(location, lang) {
|
||||
if (!location) {
|
||||
return location;
|
||||
}
|
||||
if (typeof location === 'string') {
|
||||
return addLang(location, lang);
|
||||
}
|
||||
return {
|
||||
...location,
|
||||
pathname: addLang(location.pathname, lang)
|
||||
};
|
||||
}
|
||||
|
||||
function getLangFromLocation(location) {
|
||||
if (!location) {
|
||||
return location;
|
||||
}
|
||||
if (typeof location === 'string') {
|
||||
return getLangFromPath(location);
|
||||
}
|
||||
return getLangFromPath(location.pathname);
|
||||
}
|
||||
|
||||
export default function useLangRoutes(createHistory) {
|
||||
return (options = {}) => {
|
||||
let lang = 'en';
|
||||
const history = createHistory(options);
|
||||
const unsubscribeFromHistory = history.listen(nextLocation => {
|
||||
lang = getLangFromLocation(nextLocation);
|
||||
});
|
||||
const push = location => history.push(addLangToLocation(location, lang));
|
||||
const replace = location => history.replace(
|
||||
addLangToLocation(location, lang)
|
||||
);
|
||||
return {
|
||||
...history,
|
||||
push,
|
||||
replace,
|
||||
unsubscribe() { unsubscribeFromHistory(); }
|
||||
};
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user