title: Google Analytics API deviceCategory
body: <p>I am trying to use the <a href="https://developers.google.com/analytics/devguides/reporting/" rel="nofollow">Google Analytics API</a> (v3) in <a href="https://developers.google.com/apps-script/" rel="nofollow">Google Scripts</a> to pull <a href="https://developers.google.com/analytics/devguides/reporting/core/dimsmets#view=detail&amp;group=platform_or_device&amp;jump=ga_devicecategory" rel="nofollow">Device Category</a> information from Google Analytics. </p>
  
  <p>Within Analytics under <code>Audience -&gt; Mobile -&gt; Overview</code> there is a <code>Device Category</code> section listing <code>'tablet', 'mobile' and 'desktop'</code>. I wish to pull these numbers into a Google Sheet that my script is attached to.</p>
  
  <p>The code I believe I should be using is:
   <code>ga:deviceCategory==mobile (to pull mobile traffic)</code> and <code>ga:deviceCategory==tablet</code> to pull tablet traffic.</p>
  
  <p>However, I receive the error: </p>
  
  <blockquote>
    <p>Invalid dimension or metric: ga:deviceCategory==desktop</p>
  </blockquote>
  
  <p>I'm somewhat confused by this as Google's own documentation says that deviceCategory is a valid dimension </p>
  
  <p>(<a href="https://developers.google.com/analytics/devguides/reporting/core/dimsmets#view=detail&amp;group=platform_or_device&amp;jump=ga_devicecategory" rel="nofollow">https://developers.google.com/analytics/devguides/reporting/core/dimsmets#view=detail&amp;group=platform_or_device&amp;jump=ga_devicecategory</a>)</p>
  
  <p>If I remove the device type from the end ('ga:deviceCategory') I get the error:</p>
  
  <blockquote>
    <p>Unknown metric(s): ga:deviceCategory (line 43, file "Code")</p>
  </blockquote>
  
  <p>This leads me to believe that I need to include the metric (which I believe is 'pageviews') beforehand. If this is the case, can someone show me how I pull in the figures for mobile/tablet traffic?</p>
  
  <p>I am having no other issues pulling other aspects of my data. For example:</p>
  
  <pre><code>var impressions = Analytics.Data.Ga.get(tableId, startDate, endDate, 'ga:visits').rows.toString(); 
  </code></pre>
  
  <p>works fine.</p>
  
  <p>For reference, this is the full code I am using for device Category:</p>
  
  <pre><code>  // Get Mobile Visits, this is the number of visits from mobile devices
    var mvisits = Analytics.Data.Ga.get(tableId, startDate, endDate, 'ga:deviceCategory==mobile').rows.toString();
        mvisits = mvisits;
  </code></pre>
  
  <p>I would be grateful for any assistance and please let me know if you require any more code from my script.</p>
  
  <p>Thanks in advance.</p>