0

So I'm trying to set up Google Analytics for my web game. I need to send over a score and I've gotten that working, but the problem is when I test the game and check my custom report the next day then I see only one entry and it seems like it just added up all the scores and put them into one entry. I believe the solution is to use dimensions to make multiple entries. Here's what I have right now for sending over data to analytics.

var rid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
    return v.toString(16);
});

// send over relevant analytics data to Google Analytics
ga('set', 'dimension1', rid);
ga('set', 'metric1', NJ.analytics.blocksCleared);
ga('send', 'event', 'Game', 'end', 'Game Session Data');

I'm not sure if this is the correct solution and it might also create duplicate data since I'm just generating a random string. Can someone confirm that this is how you generate rows of custom variables in analytics.js and suggest a better method of generating unique anonymous users for analytics.js?

chosendeath
  • 106
  • 1
  • 7
  • I'm not entirely sure what you are asking, but metrics being added up is expected behavior, and adding a dimension is indeed necessary if you want to get a "breakdown" of the collected values (you need to include the dimension in the report). As far as I understand your question you are approaching this correctly. – Eike Pierstorff Jan 28 '16 at 08:26
  • Right, but my concern is the way that I'm setting the dimension value is by a random ID so that they'll be mostly unique. Since there could still be conflicts I was wondering if there was a way to put unique values in dimension. – chosendeath Jan 28 '16 at 08:45
  • It seems you are generating a UUID ( I think i recognize the code from here: http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript). Unless you start with the slightly optimistic assumption that your application will survive the next three universes that should be good enough. – Eike Pierstorff Jan 28 '16 at 08:59

1 Answers1

0

Having a single row for each score is not very helpful by itself. If you still want to do it though, custom dimensions is the way to go. I am not sure if that is going to provide the data you need though.

The primary question is: What do you want to do with the data you are collecting? If you are interested in the average of scores, you can look at event value field.

Custom metrics by definition are aggregates and will result in a single value over a period.

Avi
  • 2,373
  • 17
  • 22