Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I also use the <em>google-api-ruby-client</em> gem and set it up about the same way that is outlined in the link you provided (<a href="https://gist.github.com/joost/5344705" rel="nofollow">https://gist.github.com/joost/5344705</a>).</p> <p>Just follow the steps outlined in the link to set up a Google Analytics client:</p> <pre><code># you need to set this according to your situation/needs SERVICE_ACCOUNT_EMAIL_ADDRESS = '...' # looks like 12345@developer.gserviceaccount.com PATH_TO_KEY_FILE = '...' # the path to the downloaded .p12 key file PROFILE = '...' # your GA profile id, looks like 'ga:12345' require 'google/api_client' # set up a client instance client = Google::APIClient.new client.authorization = Signet::OAuth2::Client.new( :token_credential_uri =&gt; 'https://accounts.google.com/o/oauth2/token', :audience =&gt; 'https://accounts.google.com/o/oauth2/token', :scope =&gt; 'https://www.googleapis.com/auth/analytics.readonly', :issuer =&gt; SERVICE_ACCOUNT_EMAIL_ADDRESS, :signing_key =&gt; Google::APIClient::PKCS12.load_key(PATH_TO_KEY_FILE, 'notasecret') ).tap { |auth| auth.fetch_access_token! } api_method = client.discovered_api('analytics','v3').data.ga.get # make queries result = client.execute(:api_method =&gt; api_method, :parameters =&gt; { 'ids' =&gt; PROFILE, 'start-date' =&gt; Date.new(1970,1,1).to_s, 'end-date' =&gt; Date.today.to_s, 'dimensions' =&gt; 'ga:pagePath', 'metrics' =&gt; 'ga:pageviews', 'filters' =&gt; 'ga:pagePath==/url/to/user' }) puts result.data.rows.inspect </code></pre> <p>To display statistics for a user's page in your app, you have to adjust the <em>metrics</em> and <em>filters</em> parameters when making the query. The query above for example will return a result object containing all pageviews for the page with url <em>example.com/url/to/user</em>.</p> <hr> <p><strong>Caveat:</strong> this answer was written a long time ago and Google released a new, incompatible version of the gem. Please consult <a href="https://github.com/google/google-api-ruby-client/blob/master/MIGRATING.md" rel="nofollow">https://github.com/google/google-api-ruby-client/blob/master/MIGRATING.md</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload