Hello,
i have view with data from GA. Results (sessions of current day - ga:sessions) from this views differs from GA query explorer. I think that view refresh data from GA only if i update this view. Views cache is disabled also change of query cache don't help. Any advice?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Samgarr created an issue. See original summary.

Plazik’s picture

Component: API module » Reports module
Issue tags: -views, -query explorer, -cache

Hi, Samgarr.

Enable Show the SQL query on admin/structure/views/settings page.
Refresh views page in admin UI and press "Update preview". You should see GA query. Is this the same as you using in GA query explorer?

Clear Drupal cache, refresh views, is the data the same as in GA query explorer?

i have view with data from GA. Results (sessions of current day - ga:sessions) from this views differs from GA query explorer.

Default GA cache is 3 days (see admin/config/system/google-analytics-reports-api page).
I think it's not a good idea to display sessions of current day because it will be always out-of-date.

Samgarr’s picture

Hi Plazik,
thanks for your reply.

Enable Show the SQL query on admin/structure/views/settings page.
Refresh views page in admin UI and press "Update preview". You should see GA query. Is this the same as you using in GA query explorer?

Yes, query is the same.

Clear Drupal cache, refresh views, is the data the same as in GA query explorer?

After flushing Drupal Cache is the data same as in Ga explorer. Is there way how to avoid caching in this case?

Plazik’s picture

If you will have only one GA view on your site you can use hook_form_alter to change "Query cache" select list on admin/config/system/google-analytics-reports-api page.

Samgarr’s picture

I changed "Query cache" to 60 seconds via custom module with hook_form_alter, but issue is the same. After cleaning Drupal cache i get actual results, otherwise i get old results. Isn't there any hardcoded default for query cache?

Plazik’s picture

No, there is no addition hardcoded default value.

You can call google_analytics_reports_api_cache_time() function which return UNIX timestamp when cache should be expire.

You can also take a look in database on "cache" table and find "GoogleAnalyticsReportsApiFeed" cache and see when it expires.

Samgarr’s picture

google_analytics_reports_api_cache_time returns correct timestamp according to altered "Query cache".

Here is example from cache table.

*************************** 7. row ***************************
       cid: GoogleAnalyticsReportsApiFeed:942954676d32cefec28a2dd1374bf6b9
      data: O:8:"stdClass":6:{s:7:"request";s:337:"GET /analytics/v3/data/ga?ids=ga%XXX&metrics=ga%3Asessions&sort=ga%3Asessions&start-date=2016-01-04&end-date=2016-01-04&start-index=1&max-results=9999 HTTP/1.0
Authorization: Bearer ya29.XwI_oap1lVaTByFY2mdMiaJg2_E6XQT72uAwJxAtKROT_xJ36oe_WPxQImMsZoBMfzMNtQ
User-Agent: Drupal (+http://drupal.org/)
Host: www.googleapis.com

";s:4:"data";s:949:"{"kind":"analytics#gaData","id":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXX&metrics=ga:sessions&sort=ga:sessions&start-date=2016-01-04&end-date=2016-01-04&start-index=1&max-results=9999","query":{"start-date":"2016-01-04","end-date":"2016-01-04","ids":"ga:14127664","metrics":["ga:sessions"],"sort":["ga:sessions"],"start-index":1,"max-results":9999},"itemsPerPage":9999,"totalResults":1,"selfLink":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXX&metrics=ga:sessions&sort=ga:sessions&start-date=2016-01-04&end-date=2016-01-04&start-index=1&max-results=9999","profileInfo":{"profileId":"XXXX","accountId":"XXX","webPropertyId":"UA-XXXX-1","internalWebPropertyId":"XXX","profileName":"XXXX","tableId":"ga:XXX"},"containsSampledData":false,"columnHeaders":[{"name":"ga:sessions","columnType":"METRIC","dataType":"INTEGER"}],"totalsForAllResults":{"ga:sessions":"170"},"rows":[["170"]]}";s:8:"protocol";s:8:"HTTP/1.0";s:14:"status_message";s:2:"OK";s:7:"headers";a:13:{s:7:"expires";s:29:"Mon, 04 Jan 2016 15:14:42 GMT";s:4:"date";s:29:"Mon, 04 Jan 2016 15:14:42 GMT";s:13:"cache-control";s:49:"private, max-age=0, must-revalidate, no-transform";s:4:"etag";s:57:""-eNDYzXMXVT28ykoI8oexeOT-4U/ZMLdjaO0ncHsfy2ATc322AhkRHQ"";s:4:"vary";s:8:"X-Origin";s:12:"content-type";s:31:"application/json; charset=UTF-8";s:22:"x-content-type-options";s:7:"nosniff";s:15:"x-frame-options";s:10:"SAMEORIGIN";s:16:"x-xss-protection";s:13:"1; mode=block";s:14:"content-length";s:3:"949";s:6:"server";s:3:"GSE";s:18:"alternate-protocol";s:12:"443:quic,p=1";s:7:"alt-svc";s:45:"quic=":443"; ma=604800; v="30,29,28,27,26,25"";}s:4:"code";s:3:"200";}
    expire: 1451921467
   created: 1451921466
serialized: 1
Plazik’s picture

Title: Data from view differs from GA query explorer » GA query cache doesn't update after expire time
Version: 7.x-3.0-beta2 » 7.x-3.x-dev
Component: Reports module » API module
Category: Support request » Bug report
Status: Active » Needs review
FileSize
780 bytes

It seems cache doesn't clear properly. Try this patch.

Samgarr’s picture

Great, this is patch working, now i have fresh data! Thank you for you time.

  • Plazik committed dccb191 on
    Issue #2643536 by Plazik: GA query cache doesn't update after expire...
Plazik’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.