angulartics / angulartics-google-analytics

Google Analytics plugin for Angulartics
MIT License
133 stars 86 forks source link

Universal Analytics Creates A Named Tracker by Default #116

Open rcollette opened 6 years ago

rcollette commented 6 years ago

What I'm seeing at the moment is that a named tracker is created by default. I'm not doing anything to set a named tracker anywhere, I don't make any ga() call in my code. I'm merely including the tracking code.

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

  gtag('config', 'MY-ACCOUNT-ID');
</script>

What I see when the app loads is

Running command: ga("create", "MY-ACCOUNT-ID", {cookieDomain: "auto", name: "gtag_my_account_id"})

Note that the tracker name created is gtag_my_account_id. This is done in line 4049 of the gtag code (after formatting in chrome).

f = "gtag_" + c.split("-").join("_")

I have to call

$analyticsProvider.settings.ga.additionalAccountNames = ['gtag_my_account_id'];

For any of the tracking events to show show up in google analytics.

The problem is that there are redundant calls being made to the default tracker as well, which simply go into thin air.

Running command: ga("send", {hitType: "pageview", page: "/home"})
   Command ignored. Unknown target: undefined
Running command: ga("gtag_my_account_id.send", {hitType: "pageview", page: "/home"})

If in fact the default tracker is no longer the t0 one and an account specific one is used, then the plug-in should probably be updated to handle this.

If not everyone is seeing this behavior, then it would seem that we need some way of setting the default account name to use.

I'm OK with submitting a PR for this but I need more input on what others are seeing for behavior

ssohal commented 5 years ago

I'm seeing the exact same behavior.