1

Basically I have a Heroku app on a main domain and a wordpress blog on a subdomain as blog.maindomain.com. I have google tag manager installed on the herokuapp that tracks the main domain.

How am I able to also allow my wordpress to have the same functionality? I want to be able to view all the analytics in a single account.

EDIT: I don't have to use GTM on the wordpress website, just as long as the data is showing on the same GA account.

1

2 Answers 2

1

From your question it isn't very clear if you have GTM deployed on wordpress already or not. If not, get it on there via a plugin or by editing the template code to add the GTM code.

GTM Version

As far as getting sudomain.domain.com traffic to appear in the same analytics view, you need to use the same UA code in Tracking ID field of the the pageview tag in GTM and modify one thing. Specifically under More Settings --> Fields to Set add an entry with cookieDomain as the Field Name and auto as the Value. This will cause google to push pageviews to the same Google Analytics Account and event connect the same session since the cookieDomain auto part will cause GTM to set the analytics cookie to the highest domain it can which on sudomain.domain.com will resolve to domain.com

Hardcoded

<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-Y', 'auto');
  ga('send', 'pageview');

</script>

The cookieDomain part is in this line ga('create', 'UA-XXXXXXXX-Y', 'auto'); with the UA code being the same you use on the domain.com site.

1

There's quite a few different plugins available that help you install Google Tag Manager on your Wordpress website. You can check out just a few of them here:

https://en-ca.wordpress.org/plugins/search.php?type=term&q=tag+manager

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.