Question: How do I remove URL params from getting pushed to GA4 through GTM? I have tried many solutions but none seem to be working.
Which key in "Fields to Set" do I need to use so GTM replaces the url query param from all dimensions like page\_path, page\_location, path\_referrer?

Answer: 
[This article](https://www.bounteous.com/insights/2020/05/15/excluding-url-query-parameters-google-analytics/) has been my life saver when dealing with URL params in GA4, but please use my experience and avoid the mistake of applying the script directly to `page_location`.

`page_location` is what I call a *technical dimension* that GA4 uses to sort referring websites according to its internal rules and do any other GA4 things. Remove URL params from `page_location` using GTM, and you'll stop seeing all channels, reliant on UTMs—so paid search, display, paid social, email etc (provided you use UTMs, of course). Don't forget: in this case, you remove the URL params in GTM *before* they get in GA, so if GTM strips params out, GA doesn't see them.

To illustrate my mistake, this is how my GA4 configuration tag in GTM looked like initially:

![page_location is set to receive a clean version of a URL with params stripped out, thanks to the script](https://i.stack.imgur.com/YFQKC.png)

Bad idea. Don't touch `page_location`.

The best approach is to just create your own dimension which you would use to store 'clean' URLs, say, `page_URI`. The reason: you stop relying on GA built-in dimensions that (potentially) are prone to change and you create something of your own that you will have control over and can add to any event as a dimension.

Below is my version of the script in GTM, deployed as a Custom Javascript Variable:

```
function() {
  var params = ['hash', 'email', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'gclid', 'fbclid', 'mc_cid', 'mc_eid', 'msclkid']; //Add URL params to be excluded from page URI
  var a = document.createElement('a');
  var param,
      qps,
      iop,
      ioe,
      i;
  a.href = {{Page URL}};
  if (a.search) { 
    qps = '&' + a.search.replace('?', '') + '&';
    for (i = 0; i < params.length; i++) { 
      param = params[i];
      iop = qps.indexOf('&' + param + '=');
      if(iop > -1) {
        ioe = qps.indexOf('&', iop + 1);
        qps = qps.slice(0, iop) + qps.slice(ioe, qps.length);
      } 
    }
    a.search = qps.slice(1, qps.length - 1);   
  } 
  return a.href; 
}

```

Two things to mention about the code:

1. List all params you want to strip out in the array ***params***;
2. `a.href = {{Page URL}}` - the code makes use of GTM's built-in variable `Page URL` (hence double curly brackets) that captures the full URL (without hostname, though). If you feel fancy, you can replace it with plain JS.

So the code above now populates the GTM field/GA4 dimension `page_URI` in the main configuration tag and any other tags, where I think having a clean URI is useful:

![you have your own personal URI dimension and don't touch anything built-in](https://i.stack.imgur.com/eIZBg.png)

I do realize that this approach uses up one GA4 dimension, but it's a price I'm willing to pay to have a clean URL in the absence of a better solution.
In the GA4 tag in GTM try to set `page_location` as *Field to Set* and a **Custom JavaScript Variable** as value with this definition:

```
function(){
  return document.location.hostname + document.location.pathname;
}

```

i.e. (note: *App+Web is old name of GA4*):

[![enter image description here](https://i.stack.imgur.com/Z2dn2.png)](https://i.stack.imgur.com/Z2dn2.png)