-
Notifications
You must be signed in to change notification settings - Fork 7
fix(glean): add user opt-out setting #70
Changes from all commits
f65d511
c8681c1
af02f86
0652ddb
2b848b8
692f38e
db908d2
a4ba26a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,13 @@ export default defineNuxtPlugin((nuxtApp) => { | |
log.info('Glean: App mounted, start initing glean') | ||
|
||
const GLEAN_APP_ID = 'mozilla-social-web' | ||
const devMode = useAppConfig().env === ('dev' || 'canary' || 'preview') | ||
const uploadEnabled = devMode // this will eventually be a setting that the user can toggle | ||
const env = useAppConfig().env | ||
const devMode = env === ('dev' || 'canary' || 'preview') | ||
const userSettings = useUserSettings() | ||
const allowGlean = getPreferences(userSettings.value, 'allowGlean') | ||
const uploadEnabled = devMode && allowGlean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be an OR instead of AND? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, no - keeping the |
||
|
||
Glean.initialize(GLEAN_APP_ID, uploadEnabled, {}) | ||
Glean.initialize(GLEAN_APP_ID, uploadEnabled, { channel: env }) | ||
Comment on lines
+14
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
userAgent.set(navigator.userAgent) | ||
|
||
// Debugging | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<script setup lang="ts"> | ||
import Glean from '@mozilla/glean/web' | ||
import { mastodonAccountHandle, mastodonAccountId } from '~/telemetry/generated/identifiers' | ||
import { userAgent } from '~~/telemetry/generated/identifiers' | ||
|
||
const user = currentUser.value | ||
|
||
const { t } = useI18n() | ||
|
||
useHydratedHead({ | ||
title: () => `${t('settings.privacy.label')} | ${t('nav.settings')}`, | ||
}) | ||
const userSettings = useUserSettings() | ||
|
||
function toggleOptOut() { | ||
const allowGlean = togglePreferences('allowGlean') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where I'm using that explicit return from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering, did you try calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes! and it frustratingly returns the same value both before the toggle and after the toggle. |
||
Glean.setUploadEnabled(allowGlean) | ||
|
||
// reset identifiers if user opts back in | ||
if (user && allowGlean) { | ||
mastodonAccountHandle.set(user.account.acct) | ||
mastodonAccountId.set(user.account.id) | ||
userAgent.set(navigator.userAgent) | ||
} | ||
Comment on lines
+19
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed to add this because these identifiers were not getting reset when the user would opt out and then opt back in again. |
||
} | ||
</script> | ||
|
||
<template> | ||
<MainContent back-on-small-screen no-beta-label> | ||
<template #title> | ||
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop"> | ||
<span>{{ $t('settings.privacy.label') }}</span> | ||
</div> | ||
</template> | ||
<div p6 flex="~ col gap6"> | ||
<h2 text-xl> | ||
{{ $t('settings.privacy.data_collection') }} | ||
</h2> | ||
<div> | ||
<h3 text-lg> | ||
{{ $t('settings.privacy.opt_out_title') }} | ||
</h3> | ||
<SettingsToggleItem | ||
:checked="getPreferences(userSettings, 'allowGlean')" | ||
@click="toggleOptOut()" | ||
> | ||
{{ $t('settings.privacy.opt_out_description') }} | ||
</SettingsToggleItem> | ||
</div> | ||
</div> | ||
</MainContent> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
|
||
// AUTOGENERATED BY glean_parser v8.1.1. DO NOT EDIT. DO NOT COMMIT. | ||
|
||
import EventMetricType from "@mozilla/glean/private/metrics/event"; | ||
import StringMetricType from "@mozilla/glean/private/metrics/string"; | ||
import EventMetricType from "@mozilla/glean/private/metrics/event"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I swear these two generated files keep flipping back and forth even though they are supposed to be being ignored by eslint. A problem for another day... |
||
|
||
/** | ||
* Event triggered when a user clicks a link on a web page. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this explicit return so that I could use it in the
toggleOptOut()
function later, will call it outThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning a variable assignment expression is a new one to me. Buut if it works, it works 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm such a rubyist at heart. In Ruby, every method (function) returns the evaluated result of the last line that is executed. And it was my first modern language, so I often forget that javascript doesn't do what I think it should do sometimes, but really I'm just remembering back to my ruby days.