Google Analytics API Multiple Queries

ぃ、小莉子 提交于 2019-12-12 18:20:08

问题


Is it possible to package multiple queries to the Google Analytics API? I'm running subsequent queries with the following syntax using the AnalyticsService (documented here):

        var query = this.AnalyticsService.Data.Ga.Get(
                this.GoogleAnalyticsProfileId, // profile id
                start.ToString("yyyy-MM-dd"), // start date
                DateTime.Now.ToString("yyyy-MM-dd"), // end date
                QueryMetricMap[metric]); // metrics

        var result = query.Fetch();

        var query2 = this.AnalyticsService.Data.Ga.Get(
                this.GoogleAnalyticsProfileId, // profile id
                start.ToString("yyyy-MM-dd"), // start date
                DateTime.Now.ToString("yyyy-MM-dd"), // end date
                QueryMetricMap[metric]); // metrics

        var result2 = query2.Fetch();

I understand that there may be ways I can query for multiple metrics but the above samples are cut down for brevity - I use different filters and dimmensions on different queries that make simple boolean logic impossible. I would like to simply package up multiple queries into one request.

Is this possible?


回答1:


Adding the correct answer for the above mentioned question, Batch Processing is allowed in Google Data Protocol, here's the official documentation link.




回答2:


No.

If they are really that similar you can put them inside a loop and have a configuration array that changes specific settings for each query.

Better yet instead of running them on a loop where an exception could kill all of them, push each query as a job in a queue and have a subsystem that pulls jobs form the queue and query google analytics. Now you can quickly queue how many tasks you want and have the subsystem handle them individually, while your application returns safe and quick.




回答3:


I don't think it's yet implemented for Google Analytics. It seems to be pending. https://code.google.com/p/analytics-issues/issues/detail?id=276&can=1&q=batch&colspec=ID%20Component%20Type%20Status%20Priority%20Stars%20Summary

Also, per @Cody 's link, I'm not returning a batch link relation when I query the feed.




回答4:


The R language and the RGoogleAnalytics package might help with that. Here is an example of querying multiple GA Views using a for loop in R.

http://www.analyticsforfun.com/2015/05/query-multiple-google-analytics-view.html



来源:https://stackoverflow.com/questions/11962286/google-analytics-api-multiple-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!