Comments (6)
Hey there, I've implemented an optional ID parameter for useGtagConsent
: 7859fe6
Make sure to set initialConsent
to false
in the module options. Then, you can fetch your data and initialize a specific Gtag ID:
useGtagConsent(true, { id: "XXX" })
Since no Gtag instance has been initialized until that point, it will do so for the custom ID. Hope that helps!
from nuxt-gtag.
You are right, there was a bug in my code, which I just fixed.
You won't have to add the Gtag ID to your Nuxt config, but can dynamically enable Gtag in the client.
from nuxt-gtag.
Thanks for the quick handling. After testing the code it seems you have accidentally removed the import of defineNuxtPlugin.
This causes the following error:
Uncaught ReferenceError: defineNuxtPlugin is not defined
at plugin.client.mjs?v=2faffd2d:1:1
Thanks for fixing this :)
from nuxt-gtag.
We were wondering if its possible to set the GTAG ID Dynamically.
What do you mean by that? At runtime instead of build time? You can adapt the GTAG ID based on the NUXT_PUBLIC_GTAG_ID
variable:
# Sets the `gtag.id` module option
NUXT_PUBLIC_GTAG_ID=G-XXXXXXXXXX
from nuxt-gtag.
from nuxt-gtag.
Hi @johannschopplich ,
I've tested the implementation however I'm encountering a weird issue that may be related to #19 .
For some reason, the script doesn't get injected into the head with your instructions. The only time it gets injected is when I do set the ID in the Nuxt config. However, then it also injects it 2 times. One time with the Nuxt config and another time with the new implementation.
As a result, the first collection for analytics also uses injection originating from Nuxt config. (G-XXXXXXX)
<script type="text/javascript" async="" src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX&l=dataLayer&cx=c"></script>
<script src="https://www.googletagmanager.com/gtag/js?id=G-4DJ1K7LHXI"></script>
This is my implementation:
Nuxt Config:
export default defineNuxtConfig({
...
modules: [
...
'nuxt-gtag'
],
gtag: {
initialConsent: false
// id: 'G-XXXXXXXXXX' <<< If this is added it does work except for the first collection.
}
...
})
Plugin:
export default defineNuxtPlugin(async () => {
// Do some magic to get the GTAG ID:
useGtagConsent(true, { id: 'G-4MJ1K7LSXM' })
})
from nuxt-gtag.
Related Issues (20)
- No data collected HOT 7
- `useGtagConsent(true)` should initialize the Gtag script HOT 3
- Types for public runtime config HOT 1
- Tracking events when gtag not set up HOT 1
- Nuxt 2 compatibility HOT 4
- useTrackEvent typing improvement HOT 1
- Multiple tracking IDs HOT 3
- Nuxt 3.8.1
- Consent management HOT 6
- Nuxt types are missing after installing the module HOT 1
- Google Ads conversion linker HOT 1
- Automatic `page_view` events on router change HOT 3
- Data not collecting in SSG mode HOT 4
- Disable tracking while in development HOT 2
- Own subdomain as proxy
- Analytics Hits Not Registered After Update to 1.2.0 HOT 1
- Module option `initCommands` won't trigger HOT 1
- Persist consent state in session HOT 17
- Update documentation on nuxt.com/modules/gtag HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuxt-gtag.