Remove URL Query Parameters in GA4 using Google Tag Manager

Standard

Exclude URL Query Parameters in Google Analytics 4 (GA4) using Google Tag Manager

In Google Analytics 4 (GA4), you can remove URL query parameters from your page URLs by using the “Exclude URL Query Parameters” feature. Here’s how you can set it up:

  1. Go to your GA4 property and select the “Data Streams” tab.

2. Click on the “Edit” button next to the data stream for which you want to exclude query parameters.

3. Scroll down to the “Advanced settings” section, and find the “Exclude URL Query Parameters” field.

4. In the “Exclude URL Query Parameters” field, enter the names of the query parameters you want to exclude, separated by commas. For example, if you want to exclude “utm_source” and “utm_campaign” parameters, you would enter “utm_source, utm_campaign” in the field.

5. Click the “Save” button to save your changes.

After you have set this up, GA4 will no longer include the specified query parameters in the URLs it tracks. This can help to simplify your data and make it easier to analyze. Additionally it can help to reduce the number of unique pages in your report.

It’s possible to remove URL query parameters in Google Analytics 4 (GA4) using Google Tag Manager (GTM). Here’s an overview of the process:

  1. Create a new variable in GTM, of the type “URL”, and name it “Page Path”.

2. Create a new variable of the type “Custom JavaScript” and name it “Clean URL”

3. In the “Custom JavaScript” variable, use the following code:

function(){
  var pagePath = {{Page Path}};
  var queryString = pagePath.split("?")[1];
  if(queryString){
    var params = queryString.split("&");
    var newParams = [];
    for(var i = 0; i < params.length; i++){
      var param = params[i].split("=")[0];
      if(param != "utm_source" && param != "utm_medium" && param != "utm_campaign"){
        newParams.push(params[i]);
      }
    }
    var cleanUrl = pagePath.split("?")[0] + "?" + newParams.join("&");
    return cleanUrl;
  }else{
    return pagePath;
  }
}

This code will take the current page path, split it at the “?” character, and remove any query parameters that you specify in the if statement, in this case “utm_source”, “utm_medium” and “utm_campaign”.

4. Edit your GA4 page view tag in GTM, and in the “Page” field, select the “Clean URL” variable that you just created.

5. Publish your container changes.

By doing this, you are telling GA4 to use the “Clean URL” variable as the page value, which will exclude the specified query parameters from your page URLs

It’s important to note that this process will change the way data is presented in your GA4 reports, but it will not affect your data collection, it will just help you to simplify your data and make it easier to analyze. Additionally it can help to reduce the number of unique pages in your report.

Warning: If you do n’t know about javascript or do n’t have developing knowledge then do n’t try to Remove URL Query Parameters in GA4 using Google Tag Manager for Google Tag Manager that can broke your site, Cart and other functionality 

Disclaimer: Google tag manager belongs to Google property  For Contact: mappchero@gmail.com

I am available for Hire on Freelancer: Freelancer.com

I am available for Hire on Upwork: Upwork.com

I am available for Hire on Peopleperhour: Peopleperhour.com

I am available for Hire on Guru: Guru.com

Leave a Reply

Your email address will not be published. Required fields are marked *