8

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?

Community
  • 1
  • 1
Vitaliy Shibaev
  • 1,420
  • 10
  • 24
  • `But unfortunately Google Analytics API allows to register only 1 event per 1 HTTP request.` Where is this in the Analytics documentation? – jk. Apr 30 '14 at 19:17
  • I just tested it - every 'send' call produces new HTTP request to Google Analytics server. – Vitaliy Shibaev May 01 '14 at 23:28

3 Answers3

0

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.

Community
  • 1
  • 1
jk.
  • 14,365
  • 4
  • 43
  • 58
  • I am not talking about registering multiple events for one page - it's definetely possible. That is performance problem - every 'send' call or every pushed event (in previous GA version) produces new roundtrip to GA servers. You can see this behaviour if you test code from your links with some network profiler enabled (e.g. with browser developer tools). – Vitaliy Shibaev May 01 '14 at 23:35
0

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.

Vitaliy Shibaev
  • 1,420
  • 10
  • 24
  • Can you give more details on what you did exactly? I need to use the Measurement Protocol for my web app but don't want to send a request for each event. – reubano Oct 16 '14 at 16:01
  • Visitors of our site make searches. We track the event "Item has been displayed in search results" to collect statistics how often each item is listed in search results. Every time visitor runs search, 10 or 20 events should be registered. To avoid tracking of events client side we register it on the server. From Javascript we send single HTTP request per search to our backend. Then, on the server we handle that request, put all events to register in the queue and return. Separate thread watch the queue and track new events via Measurement Protocol. – Vitaliy Shibaev Oct 18 '14 at 00:02
  • I see... so very similar to method 2 [of my answer](http://stackoverflow.com/a/26409560/408556) only instead of using batch requests where one request is one event, you send requests to the proxy as they are generated and each request is then parsed into the individual search item events. – reubano Oct 18 '14 at 07:53
  • @VitaliyShibaev what do you pass for the Client Id (cid) parameters? Are you able to get it on the client side from ga or generate it by your self? thanks – MatteoSp Feb 18 '15 at 00:05
  • I get client id on JS side via tracker.get('clientId') and then pass it to my server API. It is important to keep user interaction history consistent (associate events / pageviews registered from JS code and from backend code with the same user). – Vitaliy Shibaev Feb 18 '15 at 01:35
0

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
reubano
  • 5,087
  • 1
  • 42
  • 41