GA: UA behavioural flow worked perfectly (I think, I am getting confused on all the different implementations) when I added this snippet of code to my app.component of my Angular 10 project:

     constructor(router: Router) {
    const navEndEvents = router.events.pipe(
      filter((event) => event instanceof NavigationEnd)
    navEndEvents.subscribe((event: NavigationEnd) => {
      gtag('config', 'UA-********-2', {
        page_path: event.urlAfterRedirects,

Is there a way to get the behavioural flow populating without this piece of code?

Or alternatively is there similar piece of code I can use for a LAMP stack(PHP) application to help populate the behavioural flow?

Or am I making a mistake else where? For clarity I am using a connected GA4 and GA:UA and Google Tag Manger


1 Answer 1


Well, if you're using GTM, then why do you use gtag directly? You're not supposed to touch gtag ever. You can, but it's confusing. It's easier to have one point of interaction with gtag and that point is GTM. It will make it much easier to debug issues in the future.

Instead, you can pass all the needed information to your window.dataLayer, using a .push() method. GTM overrides the .push() of that array to be able to listen to the changes in it and refresh the state.

So in this case, you're trying to set the page path in the router level, which is perfectly fine, but what we normally do is just something like this:

window.dataLayer = window.dataLayer || [];
  event: 'pageview',
  page_path: event.urlAfterRedirects

Then in GTM, you're creating a custom event trigger with event name set to pageview and create a data layer variable that tries to use the value page_path. Finally, make a pageview tag, applying your trigger to it as well as overriding the default page (or location) field like so:

enter image description here

Inspect your events. It is important that both page and location fields are set properly in network calls. Well, really, page field is optional. location is really what matters, but for your purposes, you may need to set both.

Oh, right, in the network call, page field is dp and location field is dl short from document page and document location. Normally people use dp to only store path with no protocol, host or query params. To clean it up a bit, while still leaving all that in dl.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.