1

I need to track events in Google Analytics from a server through the Measurement Protocol. I can do this just fine, but my problem is that I want to send additional/custom data along with the event. Specifically, I want to send a UUID along with the event so that it is possible for me to fetch data from the Google Analytics API in the future and correlate events with rows in a relational database.

Is there any decent way to send custom data along with events? I looked at using the event value, but it must be an integer, and it is not intended for things like this. The event category, action, and label are reserved for other purposes.

I am not that proficient in Google Analytics, so the solutions off the top of my head would be:

  • Send an additional event containing the UUID in the event label or something like that. Seems like a bit of a hack/workaround to send two events, with one being used exclusively behind the scenes.
  • Perhaps using a custom dimension or metric. I am not 100% sure about the implications of this and if that's a decent approach or not.

So basically my question is: what would be the best way for me to send a UUID along with a Google Analytics event from a server, taking into consideration that I cannot use the event category, action, and label for the current event? Is there any other way in which I could link events retrieved from the Google Analytics API to rows in a database?

ba0708
  • 10,180
  • 13
  • 67
  • 99
  • have you tried adding cid=XXXX to your request? Just becouse you are sending hit type event does not mean you can only send those parameters to the request. – Linda Lawton - DaImTo Feb 05 '18 at 12:28
  • @DaImTo I do send the client ID, but I use that to link the event to the GA session. Specifically, I use the cookie value that the GA analytics.js script sets to make sure the event is triggered on the correct session. – ba0708 Feb 05 '18 at 12:30
  • Which database are you exactly trying to link things to? – Linda Lawton - DaImTo Feb 05 '18 at 12:37
  • @DaImTo Basically I store data from a web application in a database, and I also send this data to GA. So let's say I trigger a "Completed Order" event to GA, and I also have orders in a MySQL database. So what I want to do, is to link an event to an order row in the database. – ba0708 Feb 05 '18 at 12:54
  • From a data collection POV custom dimensions do not have that much implications - any individual dimension can have 150 bytes at most and the whole payload must not exceed 8024 bytes, and that's basically it. The more interesting question is what scope (user vs. session vs hit) you assign to them, since that has implications on how you can use them in your reports. – Eike Pierstorff Feb 05 '18 at 13:06

1 Answers1

0

So let's say I trigger a "Completed Order" event to GA, and I also have orders in a MySQL database. So what I want to do, is to link an event to an order row in the database.

There are several things that you can do and it pretty much depends on what you want to do with the information you are storing. For starters, all your requests should include the uid field with the value being the user ID within your system. This way all Google Analytics data will be calculated on the same user. Note: this is an internal value used within Google Analytics and you won't be able to see it.

Second, I would create a custom dimension of the name user_id and store the user information in that. You will then be able to use this information within your reports to see what each user is doing. Note: it's against TOS to send user name, email, or any other PII (personally identifiable information) to Google Analytics. But you can send your internal user ID.

I have done both of these in the past and found it to work quite well.

More info on User-ID.

Community
  • 1
  • 1
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Users in my system are actually anonymous, so I don't have any user ID. Sure I could just generate a UUID, but I guess that's besides the point. Just to clarify about the custom dimension... Would this mean that for each event I send to GA, I would be able to retrieve the UUID from the custom dimension? It is important that I can retrieve it through the API for a given event to accomplish what I am trying to do. Thanks for your help so far! – ba0708 Feb 06 '18 at 11:26
  • Yup you would be able to retrieve your custom dimension via the api for each even that you have sent it for. – Linda Lawton - DaImTo Feb 06 '18 at 13:35