Reputation: 45
In the dashboard of the new GA4, if I go to Engagement, Page and Screens, then press Page path and screen class I see repeated urls with query parameters with "?"
example.com/?utm_source=...
example.com/
I would like to ask how to unify the page paths
Upvotes: 3
Views: 4696
Reputation: 912
You can use the config object in your measurement code to override the location string that is reported. You should see a line of code that goes like gtag('config', '...your id...')
or gtag('config', '...your id...', { /* some config */ })
. You need to either add the 3rd config parameter, or if it is already there you need to add a new attribute into it, so your code should look something like this after all:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=...your id..."></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '...your id...', {
'page_location': location.protocol + '//' + location.host + location.pathname,
/* other options if you have anything else */
});
</script>
Please note that this will remove all URL parameters so everything after the ?
. If you only need to remove some, you need to implement a bit more logic and set page_location
to the modified URL with only the unwanted parameters removed.
Upvotes: 3
Reputation: 14179
Query parameter removal with App + Web is a bit different because of the automatic pageview tracking. If you need to remove parameters from your page paths, you can use the page_location field in your Configuration tag in GTM. Keep in mind that there are no filters or view settings to strip query parameters in the Google Analytics interface as we saw for Universal Analytics.
i.e. If you want to remove all query parameters from your page path, we'll use the same method but a different Custom Javascript Variable.
In a new Custom Javascript variable paste the following:
function() {
return document.location.hostname + document.location.pathname;
}
https://www.bounteous.com/insights/2020/05/15/excluding-url-query-parameters-google-analytics/
Upvotes: 3