title: Google Analytics UserID API extraction
body: <p>Trying to extract a userID from GoogleAnalytics. This is to view which user is the using the website <strong>most</strong> and <strong>least</strong>.
  I would to retrieve the <strong>top 5 user IDs and bottom 5 user IDs</strong> that were passed using either: </p>
  
  <pre><code>gtag('config', 'GA_TRACKING_ID', {
    'user_id': 'USER_ID'
  });
  </code></pre>
  
  <p>OR</p>
  
  <p><code>using a custom dimension...</code> ( <a href="https://support.google.com/analytics/answer/2709828?hl=en" rel="nofollow noreferrer">https://support.google.com/analytics/answer/2709828?hl=en</a> )</p>
  
  <p>I'm (vaguely) aware of policies and TOS to keep 'non identifying' information on Google BUT there are posts online indicating you can link back to CMS data.</p>
  
  <p>Steps so far
  Google Analytics with UserID and view setup - Working in Google dashboard and showing filtered userID and All website data using the idea.</p>
  
  <blockquote>
    <p>Requirements:</p>
    
    <p>Extract page view and session data for each userId between a date
    range (or all by default)</p>
  </blockquote>
  
  <ul>
  <li>UserID via standard GA method</li>
  <li>UserID via Custom dimension method</li>
  </ul>
  
  <p>Any help, pointers or examples how someone has completed something like this are appreciated.
  NOTE: This is to PULL data out of GA and manipulate/display it on an external system/dashboard.</p>
  
  <p>Seen this which states it's not possible: <a href="https://stackoverflow.com/questions/27059136/google-analytics-userid-tracking">Google analytics userID tracking</a>
  and this which states it (kind of) is <a href="https://stackoverflow.com/questions/40952378/google-analytics-api-implementation-for-tracking-a-specific-user-activities-in-p">google analytics API implementation for tracking a specific user activities in php</a></p>