Skip to content

Property 'gtag' does not exist on type 'Window & typeof globalThis' #545

@stufffancy

Description

@stufffancy

🆒 Your use case

window.gtag exists but lacks a type declaration.

useScriptGoogleTagManager({
  id: "GTM-xxxxxxxxx",
});

onMounted(() => {
  console.log(window.fbq); // ok
  console.log(window.gtag); // error: Property 'gtag' does not exist on type 'Window & typeof globalThis'
});

🆕 The solution you'd like

You can extend the global Window interface just like with Meta Pixel by writing:

// node_modules/@nuxt/scripts/dist/runtime/registry/meta-pixel.d.ts
declare global {
    interface Window extends MetaPixelApi {
    }
}

🔍 Alternatives you've considered

No response

ℹ️ Additional info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions