Google Analytics - track multiple events in single HTTP request

↘锁芯ラ 提交于 2019-12-09 06:15:51

问题


I need to track how many times the item is present in search results (in web application). I.e. user search something and get first 20 items - 1 visit for each of 20th items is tracked. On another page user can see statistic for item - how many times it was shown in search results.

I consider usage of Google Analytics Event Tracking for that task. E.g. from Javascript:

ga('send', 'event', {
    eventCategory: 'item-category',
    eventAction: 'search',
    eventLabel: 'item-id',
});

But unfortunately Google Analytics API allows to register only 1 event per 1 HTTP request. It means that for every search 20+ HTTP requests will be send. That's pretty ineffective for our requirements.

I looked for workarounds:

  1. Measurement protocol allows to send direct HTTP requests, but both GET and POST versions of http://www.google-analytics.com/collect registers only single event per request.
  2. Batch Processing in Google Data might help, but GData looks obsolete and I am not sure if it supports Google Analytics Events data. It looks quite heavyweight for experiments.
  3. Management API and Reporting API does not support uploading of events data.
  4. It is not possible with ga.js (previous version of Google Analytics Tracking): Post Multiple Events within One HttpRequest to Google Analytics

Is it possible to register multiple Google Analytics events per 1 HTTP request?


回答1:


It was possible with the previous version of GA (ga.js): Can I track multiple Google Analytics events at once?

And, it's possible with the universal version: Setting Parameters Across Multiple Send Commands

In some cases you might want to set a parameter and have the value persist across multiple send commands. For example, if you have a webpage in which you want to track one pageview and two events.

In the above example, Google is illustrating setting a specific page parameter but it also shows sending multiple events.




回答2:


It is not possible to track multiple GA events with single HTTP request.

Finally, I implement server side event registration via Measurement Protocol. There is still 1 HTTP request to GA servers per event, but it does not affect end users.




回答3:


I've been trying to do the exact same thing and I see only 2 solutions:

  1. Reverse engineer the Android SDK's Dispatch API
  2. Write an intermediate log proxy that accepts batch requests and then forward the individual requests directly to GA's Measurement Protocol


来源:https://stackoverflow.com/questions/23360227/google-analytics-track-multiple-events-in-single-http-request

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