Skip to content
Draft
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
33 changes: 32 additions & 1 deletion src/app/app.vue
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check if there is a way for the app to tell iOS to show the permission dialog again. Alternatively, we should hide the cookie button under the hamburger menu.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<VitePwaManifest />
<ClientOnly>
<!-- TODO: render server side too when styling is improved (https://github.com/dargmuesli/nuxt-cookie-control/discussions/228) -->
<CookieControl :locale="locale" />
<CookieControl v-if="!isIOS" :locale="locale" />
</ClientOnly>
<!-- <div
class="absolute inset-x-0 -top-16 -z-10 flex max-h-screen transform-gpu items-start justify-center overflow-hidden blur-3xl"
Expand All @@ -61,6 +61,7 @@ const timezone = useTimezone()
const localePath = useLocalePath()
const store = useStore()
const route = useRoute()
const cookieControl = useCookieControl()

// i18n
const { t, locale } = useI18n()
Expand Down Expand Up @@ -128,6 +129,36 @@ watch(
},
)

const handleTrackingPermissionResult = (event: Event) => {
const customEvent = event as CustomEvent<string>
if (customEvent.detail === 'authorized') {
cookieControl.cookiesEnabledIds.value = [GTAG_COOKIE_ID]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can dynamically load the full list of optional cookies, something like:

const { moduleOptions } = useCookieControl()
moduleOptions.cookies.optional.map((x) => id.id)

It would be best to have this utility function exported, but I don't find time to work on the cookie module currently, will maybe do this soon.

cookieControl.isConsentGiven.value = true
}
}

onMounted(() => {
if (import.meta.client) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onMounted should only be run on the client, so import.meta.client is not needed I'd say

window.addEventListener(
'tracking-permission-result',
handleTrackingPermissionResult,
)
}
})

onUnmounted(() => {
if (import.meta.client) {
window.removeEventListener(
'tracking-permission-result',
handleTrackingPermissionResult,
)
}
})
Comment on lines +149 to +156
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using https://vueuse.org/core/useEventListener/ would simplify the mount/unmount logic, just an idea.


const isIOS = computed(() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use isAppIos from usePlatform() instead?

return /iPhone|iPad|iPod/i.test(navigator.userAgent)
})

// initialization
defineOgImageComponent(
'Default',
Expand Down
6 changes: 6 additions & 0 deletions src/app/composables/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ export const usePlatform = () => {
? ['android', 'ios', 'iOS App Store'].includes(platform.value)
: undefined,
)
const isAppIos = ref<boolean | undefined>(
platform.value
? ['ios', 'iOS App Store'].includes(platform.value)
: undefined,
)

return {
isApp,
isAppIos,
platform,
}
}
Loading