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?

Nmk
  • 1,281
  • 2
  • 14
  • 25
Mike
  • 809
  • 6
  • 20
  • 2
    For anyone with same problem: I switched to queryparams. – Mike Jul 26 '18 at 20:09
  • 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? – XTOTHEL Feb 14 '19 at 03:48
  • 1
    for the bounty: maybe a later answer of the original posters helps? https://stackoverflow.com/questions/49874364/handle-both-url-matrix-query-parameters-in-angular-4 – ForestG Feb 18 '19 at 08:40
  • 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. – Mike Feb 18 '19 at 09:53

2 Answers2

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

Open SEO
  • 1,682
  • 14
  • 16
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.
josepdecid
  • 1,737
  • 14
  • 25