Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useScriptGoogleAnalytics TS Type Not Working #325

Open
benfeather opened this issue Nov 27, 2024 · 1 comment
Open

useScriptGoogleAnalytics TS Type Not Working #325

benfeather opened this issue Nov 27, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@benfeather
Copy link

📚 What are you trying to do?

I'm trying to use the googleTagManager registry script and the useScriptGoogleAnalytics composable.

I have the registry script set up like so:

modules: [
	'@nuxt/scripts',
],

scripts: {
	registry: {
		googleTagManager: {
			id: process.env.GOOGLE_TAG_MANAGER_ID ?? '',
		},
	},
},

In my app.vue file, I'm using the composable like so:

const { proxy } = useScriptGoogleAnalytics()

proxy.gtag('consent', 'default', {
	ad_personalization: 'denied',
	ad_storage: 'denied',
	ad_user_data: 'denied',
	analytics_storage: 'denied',
})

But the gtag type shows an error in my IDE:
"Expected 2 arguments, but got 3."

However, the modules/composable works as expected (I have tested it with the tag assistant).

How can I get the types working?

🔍 What have you tried?

No response

ℹ️ Additional context

No response

@benfeather benfeather added the help wanted Extra attention is needed label Nov 27, 2024
@benfeather
Copy link
Author

benfeather commented Nov 27, 2024

This is my current workaround, but ideally, it wouldn't be required:

npm i -D @types/gtag.js

export function useGtag() {
	const { proxy } = useScriptGoogleAnalytics()

	return {
		gtag: proxy.gtag as Gtag.Gtag,
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant