Google Analytics and Angular4+ matrix URL parameters
Asked Answered
P

2

18

In my Angular4+ app, I'm using matrix notation for URL routing params. Google Analytics strips URLs up to first encountered ';'. I found this but it doesn't help much.

Is there a way to make GA read full URLs like this or my only option is to turn them to queryParams?

Protomartyr answered 3/1, 2018 at 13:25 Comment(4)
For anyone with same problem: I switched to queryparams.Protomartyr
Are you using any libraries for sending data to GA? Can you provide a little bit of code to show where you're triggering the ga functions on routing?Schecter
for the bounty: maybe a later answer of the original posters helps? #49874864Cognac
I switched to queryparams and handle old links using customUrlSerializer. It is a workaround rather than a solution. I'd expect some tweaking in google-analytics configuration to properly fix that.Protomartyr
I
1

Google Analytics has always offered means to force the page path being collected to an explicit value, overriding the default parsing based on location.pathname+location.search

Just set a value for the page parameter.

You'll find an example here https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications

However, first check which version of the Google Analytics tracker code you are using, to get the right syntax applicable to that version. Or prefer to push the value to Google Tag Manager, through a dataLayer.push('pagePathVariableName','/example-page;field1=value1;field2=value2;field3=value3'); call and do the mapping in GTM

Insider answered 18/4, 2020 at 19:1 Comment(0)
P
0

I see here three possible solutions:

  1. Write an URL serializer
  2. Add to the component the ability to parse the URL, detect if it's a matrix notation, and if it is, convert it to query params notation, and redirect to the desired URL. (You could also delegate this work to a Service).
  3. Switch to queryparams as suggested in the comments.
Pernicious answered 18/2, 2019 at 22:29 Comment(2)
I wouldn't say those are solutions but rather workarounds. Imo solution would involve changing configuration of google analytics.Protomartyr
Yeah, probably, but I don't know if that's possible!Pernicious

© 2022 - 2024 — McMap. All rights reserved.