gtag.js consent management
Built-in GDPR-complaint composable
Last updated
// main.ts
import { createGtag } from "vue-gtag";
createGtag({
tagId: 'GA_MEASUREMENT_ID',
initMode: 'manual'
})<script setup lang="ts">
// component.vue
import { useConsent } from "vue-gtag";
const { acceptAll, rejectAll, hasConsent } = useConsent();
</script>
<template>
<div v-if="hasConsent">I have consent</div>
<div v-else>
<button @click="rejectAll">Reject all</button>
<button @click="acceptAll">Accept All</button>
</div>
</template>