Remove URL query string via Google Tag Manager

A few days ago I was looking at the tracking for a hybrid iOS/Android app where the Apps appended a query string to the URLs in app. Given this, I had two versions of each URL in Google Analytics, looking something like this:

  • www.domain.com/awesome-post/
  • www.domain.com/awesome-post/?device=app

The first one is the URL that is being used on the desktop version of the site, no matter of you are browsing with a laptop, mobile phone or tablet. The latter one is the URL being used if you open the link from within the app on your phone.

An easier way of doing this is probably using rewrite filters in Google Analytics, but since I want to do most things in Google Tag Manager this is how I solved the issue, takingĀ into account that we don’t want to get rid of the query string in its entirety but only that part.

Read More