Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change page URL sent to Universal Google Analytics when using Google Tag Manager

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?

like image 960
jacbmelo Avatar asked Jan 31 '17 18:01

jacbmelo


1 Answers

Changing the "dp" value can be accomplished in GTM by setting the desired value in the page field, under "Fields to set":

enter image description here

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.

like image 171
nyuen Avatar answered Sep 19 '22 02:09

nyuen