Reputation: 29477
I am trying to get my JS pages reporting basic metrics back to my GA account. However the Google docs don't really cleanly/consistently clarify how to accomplish this. On one hand you have the analytics.js
snippet:
<!-- Google Analytics -->
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
But this doesn't show how you actually tie the ga
function to your GA account/client ID.
Then you have this behemoth of JS, but that looks totally different than the first snippet above. So I ask, can someone explain and provide an SSCCE of the required JS to actually send basic metrics back from a page?
Upvotes: 1
Views: 666
Reputation: 179994
But this doesn't show how you actually tie the ga function to your GA account/client ID.
You just put the tracking ID (which will be of a format like UA-XXXXX-Y
) in the UA-XXXXX-Y
spot. Nothing else requires changing.
Incidentally, GA will give you the exact code, including the tracking ID, in the Admin > Tracking Info
section, as well as when you first create the account/property.
Then you have this behemoth of JS, but that looks totally different than the first snippet above.
That's for getting data out of GA, like for a custom dashboard. If you just want to look at pretty stats in the Google Analytics interface, ignore that bit of documentation.
Upvotes: 2