title: Get pageview's from Google Analytics API in Javascript
body: <p>I am having trouble with fetching data from Google Analytics API with javascript.
  I can't seem to fetch anything but lets say its something basic like pageviews.</p>
  
  <p>I am using <a href="https://developers.google.com/analytics/devguides/collection/analyticsjs/" rel="nofollow">Analytics.js</a> </p>
  
  <p>This is the code i am using to connect to GA API:</p>
  
  <pre><code>(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', 'XXX', 'example.com');
      ga('send', 'pageview');
  </code></pre>
  
  <p>So how do i get the pageviews now?
  I tried using this code but it returns undefined:</p>
  
  <pre><code>ga(function() {
        var tracker = ga.getByName('t0');
        alert(tracker.get('page'));
      });
  </code></pre>