GA: browser notification subscription

This commit is contained in:
infinite-persistence 2021-11-24 19:38:21 +08:00 committed by infinite-persistence
parent 7ea74cfa0d
commit 6bbf310348

View file

@ -6,6 +6,7 @@ import { BrowserNotificationErrorModal } from '$web/component/browserNotificatio
// @todo: Once we are on Redux 7 we should have proper hooks we can use here for store access. // @todo: Once we are on Redux 7 we should have proper hooks we can use here for store access.
import { store } from '$ui/store'; import { store } from '$ui/store';
import { selectUser } from 'redux/selectors/user'; import { selectUser } from 'redux/selectors/user';
import analytics, { GA_DIMENSIONS } from 'analytics';
export default () => { export default () => {
const [pushPermission, setPushPermission] = useState(window.Notification?.permission); const [pushPermission, setPushPermission] = useState(window.Notification?.permission);
@ -35,18 +36,22 @@ export default () => {
if (await pushNotifications.subscribe(user.id)) { if (await pushNotifications.subscribe(user.id)) {
setSubscribed(true); setSubscribed(true);
setPushPermission(window.Notification?.permission); setPushPermission(window.Notification?.permission);
analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'subscribed' });
return true; return true;
} else { } else {
setEncounteredError(true); setEncounteredError(true);
analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'subscribe_failed' });
} }
} catch { } catch {
setEncounteredError(true); setEncounteredError(true);
analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'subscribe_failed' });
} }
}; };
const unsubscribe = async () => { const unsubscribe = async () => {
if (await pushNotifications.unsubscribe(user.id)) { if (await pushNotifications.unsubscribe(user.id)) {
setSubscribed(false); setSubscribed(false);
analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'unsubscribed' });
} }
}; };