How can I change the page URL that is sent to Universal Google Analytics when using Google Tag Manager? Without Google Tag Manager it's really simple. You just have to add ga('set', 'page', '/my/custom/url');
before ga('send', 'pageview');
.
Your Google Analytics script needs to be like this:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', 'auto');
ga('set', 'page', '/my/custom/url'); /* Set my custom URL */
ga('send', 'pageview');
</script>
How can I do something similar using Google Tag Manager?
Changing the "dp" value can be accomplished in GTM by setting the desired value in the page
field, under "Fields to set":
Edit: For dynamic page values, you could define them in the dataLayer (make sure it's defined BEFORE your GTM container snippet so that the pageview tag sees it):
dataLayer = [{
'newPage': '/your/page/here'
}];
and define a Data Layer type variable that captures the newPage
value, which you use as the value of the page
field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With