DEV Community

Slawkomay
Slawkomay

Posted on

Gridsome, pushing "Google Analytics" code

I wanted to add Google Analytics on my website, Gridsome Plugin didn't work
plugin Google Analytics so I thought I can just insert this code in head / body on my page (https://gridsome.org/docs/head/), I make this:

head.script.push({
    src:'<script async src="https://www.googletagmanager.com/gtag/js?id=UA-151506029-2"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag(\'js\', new Date()); gtag(\'config\', \'UA-151506029-2\');</script>',
    body: true})

Local is everything ok but online I got an error in HTML below footer

" data-body="true">

I am beginner, so I don't know what is wrong

Top comments (2)

Collapse
 
toledox82 profile image
Marcio Toledo

Hi mate,

I solved this issue adding the gtag code into the index.html.

Take a look: github.com/marciotoledo/marciotole...

But now have another gtag gridsome plugins too.

Collapse
 
bibhuticoder profile image
Bibhuti Poudyal

Got stuck on the same issue and I did it manually 😂

Maybe this will help 🚀
bibhuticoder.medium.com/manually-s...