From 60430b5267efe1f8243a8a34bd0e1eb371bf92b7 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Wed, 29 Dec 2021 13:26:28 -0600 Subject: [PATCH] clean up dupe code + make sure failing analytics doesn't throw subscription error. --- .../use-browser-notifications.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/web/component/browserNotificationSettings/use-browser-notifications.js b/web/component/browserNotificationSettings/use-browser-notifications.js index be42eaa57..f4a204971 100644 --- a/web/component/browserNotificationSettings/use-browser-notifications.js +++ b/web/component/browserNotificationSettings/use-browser-notifications.js @@ -35,19 +35,16 @@ export default () => { if (!user) return; setEncounteredError(false); try { - if (await pushNotifications.subscribe(user.id)) { + const subscribed = await pushNotifications.subscribe(user.id); + if (subscribed) { setSubscribed(true); setPushPermission(window.Notification?.permission); - analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'subscribed' }); - return true; - } else { - setEncounteredError(true); - analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'subscribe_failed' }); } } catch { setEncounteredError(true); analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'subscribe_failed' }); } + analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'subscribed' }); }; const unsubscribe = async () => {