Search code examples
phpgoogle-analyticsgoogle-codegoogle-analytics-api

How to fetch custom variable value in google analytics data api?


'm using GAPI version 1.3 I have added a custom variable in GA code like this:

**_gaq.push(['_setCustomVar', 1,  'Member', '<?php echo $member_id; ?>, 3]);**

And its working fine..

Now I need to fetch the data from GA: so my request to GA is like this:

**https://www.google.com/analytics/feeds/data?
ids=XXXXXXXXXXX&
dimensions=ga:customVarValue1,ga:pagePath&
metrics=ga:pageviews,ga:uniquePageviews,ga:bounces,ga:exits&
filters=ga:pagePath=@event_details.php;ga:customVarValue1=2004036442&
start-date=2011-04-20&
end-date=2011-05-04&
max-results=50**

I need to fetch data from GA where pagePath=@event_details.php AND ga:customVarValue1=2004036442

But this is not resulting anything...

When I changed the filters in the following why its resulting all the pagePath = event_details.php and its working fine.. filters=ga:pagePath=@event_details.php

But I need get the page path with the particular member ID that is why I used the condition as below: filters=ga:pagePath=@event_details.php;ga:customVarValue1=2004036442&

So any one have idea about this?? Please help..


Solution

  • After looking at the code you posted in Google Docs, I see your problem. Try using this as your filter.

    $filter =  'pagePath =@ ' . $filter_text[$tab] . ' && customVarValue1 == 2004036442'
    

    The function you are passing $filter to does a cleanup process that escapes any reserved characters with a backslash. Your customVariable is being sent with a slash at the end, which is why it's not returning any matches.