angulartics2 icon indicating copy to clipboard operation
angulartics2 copied to clipboard

Active page is being recorded as "/" instead of the whole URL and route changes are not recorded to Google Analytics

Open craigbroadman opened this issue 5 years ago • 6 comments

For support questions, please consider using Gitter - Chat

I'm submitting a ...

  • [* ] bug report

  • [ ] feature request

  • [ ] question about the decisions made in the repository

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

Browse directly to this URL: https://localhost/my-app/user/ae24b697-c5cc-46bc-9071-48b1083bc2b9

App Module

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';

import { AppComponent } from './app.component';
import { httpInterceptorProviders } from "./core/http-interceptors/index";
import { CoreModule } from "./core/core.module";

import { LayoutModule } from './layout/layout.module';
import { RoutesModule } from './routes/routes.module';
import { Angulartics2Module, RouterlessTracking } from 'angulartics2';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    CoreModule,
    BrowserModule,
    RoutesModule,
    HttpClientModule,
    LayoutModule,
    Angulartics2Module.forRoot(),
  ],
  providers: [ httpInterceptorProviders, RouterlessTracking],
  bootstrap: [AppComponent],
  exports: []
})
export class AppModule { }

App Component

import { Component } from '@angular/core'; 
import {Angulartics2GoogleAnalytics} from "angulartics2/ga";

@Component({
  selector: 'ev-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent  {
  constructor(angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) {
    angulartics2GoogleAnalytics.startTracking();
  }
}
  • What is the expected behavior? I would expect a page view in Google Analytics to be recorded as "/email-change-verification/ae22b699-c5cc-46bc-9071-48b1083bc2b7" however it is being recorded as "/"

I believe this is also preventing route changes from being recorded.

What is being recorded... image

  • What is the motivation / use case for changing the behavior?

  • Environment:

please run the following and copy the output

./node_modules/.bin/ng --version

craigbroadman avatar Jul 25 '19 09:07 craigbroadman

I'm having the same issue. Only when I reload the page explicitly for a specific route is it working. This seems to be the most basic functionality but I can't see what I've done wrong.

longwa avatar Aug 09 '19 19:08 longwa

why are you using RouterlessTracking if you want routes recorded?

scttcper avatar Aug 09 '19 19:08 scttcper

My bad, I didn't realize this issue was using RouterlessTracking.

I can open a separate issue. I'm using Angulartics2GoogleGlobalSiteTag but I don't get any PageViews tracked. I can call the API to track an event and that works, but if I try to manually track a PageView, it doesn't report it. If I use gtag directly, it does work.

longwa avatar Aug 09 '19 20:08 longwa

@longwa try Angulartics2GoogleTagManager

https://github.com/angulartics/angulartics2/tree/master/src/lib/providers/gtm vs https://github.com/angulartics/angulartics2/tree/master/src/lib/providers/gst

its confusing and i'm not sure if that will fix it.

scttcper avatar Aug 09 '19 20:08 scttcper

I didn't realise I had set it up with RouterlessTracking.

Could you point me in the right direction for how to change it?

craigbroadman avatar Aug 09 '19 20:08 craigbroadman

@craigbroadman https://github.com/angulartics/angulartics2/tree/master#include-it-in-your-application

scttcper avatar Aug 09 '19 20:08 scttcper