❄️ The winter sale is here. 25% off for a limited time. Join us →

Inertia
Setting up gtag with laravel inertia vue
1
427

Robert

Started this discussion 2 months ago

Does anyone have any experience setting up gtag in inertia / vue.

so in non spa application you can just set it up like this

<script async src="https://www.googletagmanager.com/gtag/js?id=G-xxxxxxxx"></script>  
<script>  
  window.dataLayer = window.dataLayer || [];  
    function gtag(){dataLayer.push(arguments);}  
      
    gtag('js', new Date());  
    gtag('config', 'G-xxxxxxx');  
</script>

but i'm presuming i'll need to so something like this

<script async src="https://www.googletagmanager.com/gtag/js?id=G-xxxxxxxx"></script>  
<script>  
  window.dataLayer = window.dataLayer || [];  
    function gtag(){dataLayer.push(arguments);}    
</script>
// not sure where to put this app.js?

router.on('navigate', (event) => {  
      gtag('js', new Date());  
	  gtag('config', 'G-xxxxxxx');
})

would the router events have access to window on the inital ssr page load?

any help appreciated

alex

Replied 1 month ago

I don't have much experience with Google tag, but possibly look at using a package that handles everything for you?

There's one just here for Vue 3