MatteoGabriele / vue-gtag

Global Site Tag plugin for Vue (gtag.js)
https://matteo-gabriele.gitbook.io/vue-gtag/
MIT License
864 stars 64 forks source link

GoogleAnalytics not being added #143

Closed toritroniks closed 4 years ago

toritroniks commented 4 years ago

Description

I followed the documentation to add a new Analytics account to my vue application. But events are not being sent to Analytics.

When I use the "Tag Assistant" plugin, it says that the gtag.js is set, but the analytics is not added. I checked the devTools, and I couldn't find the analytics library being added.

<link href="https://www.googletagmanager.com" rel="preconnect">
<script async="" src="https://www.googletagmanager.com/gtag/js?id=UA-1234567-8" charset="utf-8"></script>

My setup is on the main.js file:

import VueGtag from 'vue-gtag';

Vue.use(
  VueGtag,
  {
    config: { id: 'UA-1234567-8' },
  },
  router
);

If I manually add this snippet to my index.html, it seems to work, but I thought that by using this plugin, this step should not be necessary.

window.dataLayer = window.dataLayer || [];
function gtag() {
  dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'UA-1234567-8');

Am I missing something? Any help would be appreciated!

Thanks in advance.

Environment

vue-gtag@1.6.3

  1. Operating system: Windows
  2. Browser and version: Google Chrome Version 83.0.4103.97 (Official Build) (64-bit)
MatteoGabriele commented 4 years ago

gtag.js is the only library loaded here, why would analytcs.js be loaded as well? they are 2 separate libraries

sCarita commented 4 years ago

I am also running to the same issue. So we are supposed to add google snippet to our head correct?

MatteoGabriele commented 4 years ago

you are not supposed to add any snippets. vue-gtag loads gtag.js and no other libraries. why would you use analytics and gtag at the same time?

toritroniks commented 4 years ago

Sorry if I am misunderstanding the plugin. I am new to this. Please tell me where is my mistake.

  1. I created an Analytics account and got a TrackingID (UA-1234567-8)
  2. I installed the plugin and configured the TrackingID
  3. I run my app in localhost and expected to see some user activity on the Analytics console, but there was none.
  4. I tried to send custom events with this.$gtag, but nothing was sent to the Analytics console.

after the account creation, there is an instruction to add this snippet to the <head> tag.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1234567-8"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-1234567-8');
</script>

if I do this, analytics.js is automatically added to the page. (even though I am not directly adding it)

I also saw that in this other issue, analytics.js seems to be automatically added for him. https://github.com/MatteoGabriele/vue-gtag/issues/119#issue-607530088

Not sure what I am missing.

sCarita commented 4 years ago

I think you cannot use the GA TrackID directly without adding it to your GTM. I am still looking further into it, I will comment if I make it work :)

ap-arto commented 4 years ago

Got the same issue. When I trying to add vue-analytics Tag Assistant says that there are few gtag instances. But if I use only vue-gtag it recommends adding google analytics.

MatteoGabriele commented 4 years ago

just saying it out there, but it could be related to this issue. I will have a look later

https://github.com/MatteoGabriele/vue-gtag/issues/144

MatteoGabriele commented 4 years ago

:tada: This issue has been resolved in version 1.6.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket: