Skip to content

Commit

Permalink
fix: resolve initCommands option (closes #50)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Feb 28, 2024
1 parent 726d0b2 commit e83d210
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 11 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ export default defineNuxtConfig({
modules: ['../src/module.ts'],

gtag: {
id: 'G-ZZZZZZZZZZ',
enabled: false,
tags: ['G-ZZZZZZZZZZ'],
initCommands: [
// Setup up consent mode
['consent', 'default', {
ad_user_data: 'denied',
ad_personalization: 'denied',
ad_storage: 'denied',
analytics_storage: 'denied',
wait_for_update: 500,
}],
],
},

typescript: {
Expand Down
6 changes: 4 additions & 2 deletions src/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ export function resolveTags(options: Required<ModuleOptions>) {
const tags: GoogleTagOptions[] = [...options.tags].filter(Boolean)
.map(i => typeof i === 'string' ? { id: i } : i)

if (options.id)
tags.unshift({ id: options.id, config: options.config })
if (options.id) {
const { id, config, initCommands } = options
tags.unshift({ id, config, initCommands })
}

return tags
}

0 comments on commit e83d210

Please sign in to comment.