Skip to content

Commit

Permalink
feat(cookie-control): migrate to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
dargmuesli committed Jan 16, 2023
1 parent 8f23c43 commit 5a53542
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
20 changes: 20 additions & 0 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@
<NuxtPage />
</NuxtLayout>
</template>

<script setup lang="ts">
const cookieControl = useCookieControl()
// lifecycle
watch(
() => cookieControl.cookiesEnabledIds.value,
(current, previous) => {
if (
(!previous?.includes('google-analytics') &&
current?.includes('google-analytics')) ||
(previous?.includes('google-analytics') &&
!current?.includes('google-analytics'))
) {
window.location.reload()
}
},
{ deep: true }
)
</script>
2 changes: 1 addition & 1 deletion cypress/e2e/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('index page', () => {

context('visual regression', () => {
it('looks as before', () => {
cy.setCookie('cookie_control_consent', 'true')
cy.setCookie('cookie_control_is_consent_given', 'true')
cy.visit('/')
cy.get('[data-is-loading="false"]').should('be.visible')
cy.get('[data-testid="nuxt-cookie-control-control-button"]').should(
Expand Down
4 changes: 2 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default defineNuxtConfig({
en: 'Cookie Preferences',
},
targetCookieIds: [
'cookie_control_consent',
'cookie_control_enabled_cookies',
'cookie_control_is_consent_given',
'cookie_control_cookies_enabled_ids',
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/gtag.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineNuxtPlugin((nuxtApp) => {
VueGtag,
{
bootstrap:
cookieControl.cookiesEnabledIds.value.includes('google-analytics'),
!!cookieControl.cookiesEnabledIds.value?.includes('google-analytics'),
config: {
id: config.public.googleAnalyticsId,
},
Expand Down

0 comments on commit 5a53542

Please sign in to comment.