title: How to get Google search query in real time?
body: <p><strong>Is it possible to find out in real time what query a visitor searched before landing on your site?</strong></p>
  
  <p>Google switched the URL structure to precede query (<code>q=</code>) with a <code>#</code> instead of <code>?</code> or <code>&amp;</code> to avoid sending data in the URL. Now <code>document.referrer</code> is <code>https://www.google.com</code> with no parameters to parse.</p>
  
  <p>Before:
  <a href="https://stackoverflow.com/questions/1348206/how-does-a-website-know-the-google-query-i-used-to-find-it">How does a website know the Google query I used to find it?</a></p>
  
  <p>My goal is letting the website search its own database for related content or tools not indexed by Google.</p>
  
  <p>Google Analytics has real time data. The <a href="https://developers.google.com/analytics/devguides/reporting/realtime/v3/" rel="nofollow noreferrer">limited beta API</a> may enable joining a session via primary key (user_id or IP) to get their referring keyword.</p>