Note that there are some explanatory texts on larger screens.

plurals
  1. POTracking JSON calls with Google Analytics in a Ruby/Rails app
    primarykey
    data
    text
    <p>I searched a lot about this issue but I can't find anything good. I think that this is a common problem: you have a web app and build JSON APIs on top of your platform, so you can develop some widgets, mobile apps or third party applications.</p> <p>I know that there a are a lot of specific analytics services via API (like Mixpanel, Kissmetrics and many others) but I want to track all the JSON calls also via Google Analytics.</p> <p>I found that the best method is to use the __utm.gif image but strangely I cannot find any plugin or gem to use this image. So I tried to build my own method without success (see the code below)... Someone can help?</p> <pre><code>def google_analytics_call(page_title) today = Time.now.to_i utma = cookies[:__utma].to_s utmb = cookies[:__utmb].to_s utmc = cookies[:__utmc].to_s utmz = cookies[:__utmz].to_s utma = (rand(8).to_s + "." + rand(10).to_s + "." + today.to_s + "." + today.to_s+ "." + today.to_s) unless cookies[:__utma] utmb = rand(8).to_s unless cookies[:__utmb] utmc = rand(8).to_s unless cookies[:__utmc] utmz = rand(8).to_s+ "." + today + ".2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)" unless cookies[:__utmz] Thread.new do params = { :utmac =&gt; GOOGLE_ANALYTICS, :utmcc =&gt; "__utma%3D"+utma+"%3B%2B"+"__utmb%3D"+utmb+"%3B%2B"+"__utmc%3D"+utmc+"%3B%2B"+"__utmz%3D"+utmz+"%3B%2B", :utmcn =&gt; "1", :utmcs =&gt; "-", :utmdt =&gt; page_title, #page title :utmhn =&gt; BASE_URL, :utmwv =&gt; 1, :utmt =&gt; "page", :utmr =&gt; request.referer } puts params http_get("www.google-analytics.com", "/__utm.gif", params) end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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. 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