angulartics2 icon indicating copy to clipboard operation
angulartics2 copied to clipboard

Trouble with analytics global site tag tracking route changes

Open mpetito opened this issue 7 years ago • 5 comments

  • I'm submitting a ... [ x ] bug report [ ] feature request [ ] question about the decisions made in the repository

  • Do you want to request a feature or report a bug? I believe this is a bug with the Angulartics2GoogleAnalytics provider, at least when using the current global site tag snippet provided by Analytics. I've also tried the Angulartics2GoogleTagManager provider and verified both do not track virtual page views (as a result of route changes).

  • What is the current behavior? The GA provider sends a page view event that does not appear to actually record a page view when using gtag.js: https://github.com/angulartics/angulartics2/blob/59bb6a69c2eaf62eaae1ba22b46a4233fa275b86/src/lib/providers/ga/angulartics2-ga.ts#L61

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Here is an example of the gtag.js script tag provided by analytics.

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

gtag('config', 'UA-XXXXXXXXX-1');
</script>

After including this script on the page, and following the standard installation instructions, the initial page load is recorded but subsequent route changes are not recorded in the analytics dashboard.

  • What is the expected behavior? All route changes should be recorded in the analytics dashboard.

  • Please tell us about your environment:

  • Angular version: 4.4.4
  • Browser: all
  • Other information

I found that if I created my own custom provider and changed this line to the following, then the page views are tracked as expected:

ga.getAll().forEach(a => a.send("pageview", path));

In making this change, I simply swapped the Angulartics2GoogleAnalytics service for my own custom service in both the app module and root app component, which leads me to believe my initial issue is not due to a misconfiguration / installation of angulartics2. However, I do not know if this approach is compatible with prior versions of the analytics script tag.

mpetito avatar Mar 08 '18 15:03 mpetito

Same issue here! With gtag there are no subsequent route changes visible in Analytics! The minute I changed the tracking code to default ga it started to work!

tscislo avatar Jun 02 '18 17:06 tscislo

+1

RadouaneRoufid avatar Jun 28 '18 09:06 RadouaneRoufid

+1

is this lib abandonned ?

jscti avatar Feb 13 '19 10:02 jscti

All providers are living off community support.

scttcper avatar Feb 13 '19 15:02 scttcper

Works for me. The code snippet above is missing .startTracking() in app component for injected Angulartics2GoogleGlobalSiteTag.

pkspks avatar Apr 02 '19 22:04 pkspks