Вопрос

Using: Universal Analytics (analytics.js)

I'm currently tracking a custom dimension called 'animals' with an index of 3 and values 'pig' and 'cow'. I am trying to set up an application that can match user-input strings to their dimensionXX counterparts. For example, an input of 'animals' would match to 'dimension3'.

In addition, I'd like to be able to determine what values are held within this dimension, or at least output query data with these dimension values attached:

date        | visits | dimension3
'2013-11-1' |   4    |  'pig'
'2013-11-1' |   8    |  'cow'
'2013-11-2' |   7    |  'pig'
'2013-11-2' |   1    |  'cow'
'2013-11-3' |   14   |  'cow'

I am trying to accomplish two things:

  • Identify that dimension3 is called 'animals'
  • Identify what values are in dimension3 ('pig' and 'cow')
gapi.client.analytics.data.ga.get({
  'ids': 'ga:' + profileId,
  'start-date': '2013-11-11',
  'end-date': '2013-11-20',
  'metrics': ???,
  'dimensions': 'ga:dimension3',
}).execute(callbackFunc);
    

I had considered using filters or segments but both yielded no results. Any ideas on how to get this to work?

Это было полезно?

Решение

  1. This is currently not possible through the API. The only solution would be for you to manage this mapping yourself. You could use an array for this. Also, there is a feature request for this so you can upvote it and follow any status changes at https://code.google.com/p/analytics-issues/issues/detail?id=305

  2. To identify values, what you have is close to correct:

    • Query for ga:dimension3 and then depending on the scope of the dimension, for a metric you can use ga:pageviews (if custom dimension is scoped to hits and assuming you are sending pageviews after setting the dimension value), ga:visits (session scoped custom dimension), or ga:visitors (user scoped custom dimension).
    • Paginate through all results using start-index (if required).
    • Once you have all results and you'll need to go through each row and identify all the unique values set for that dimension. You could use a simple for loop and an Object to store the string values. E.g. For each row, check if dimension value is a member of Object, if not then add it.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top