Skip to content

Commit

Permalink
feat: log missing Google analytics ID
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Dec 20, 2023
1 parent 8b757e8 commit 59a63b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/runtime/composables/useGtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export function useGtag() {
const hasConsent = options.hasConsent ?? true
const id = options.id || defaultId

if (!id) {
console.error('[nuxt-gtag] Missing Google Analytics ID')
return
}

if (!hasConsent) {
disableGtag(id)
return
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/plugin.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { initGtag } from './gtag'
import { defineNuxtPlugin, useHead, useRuntimeConfig } from '#imports'

export default defineNuxtPlugin(() => {
const { id, config, initialConsent, loadingStrategy }
= useRuntimeConfig().public.gtag as Required<ModuleOptions>
const { id, config, initialConsent, loadingStrategy } = useRuntimeConfig().public.gtag as Required<ModuleOptions>

if (!id)
return
Expand Down

0 comments on commit 59a63b3

Please sign in to comment.