andeedee / gapi-google-analytics-php-interface

Automatically exported from code.google.com/p/gapi-google-analytics-php-interface
0 stars 0 forks source link

Can i access user-defined custom variables, present in GA, through GAPI and get results to be displayed on my webpage #43

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We are trying to add custom variables to GA to track certain features and I was 
wondering if I will be able to get the results/values of these custom variables 
through GAPI just like how we are getting values for pageViews or Visits. Any 
info on this?

Original issue reported on code.google.com by jvsiva2...@gmail.com on 1 Sep 2010 at 6:09

GoogleCodeExporter commented 9 years ago
What's the status on this?

Original comment by i...@kryap.com on 6 May 2011 at 12:16

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I have tried to retrieve a custom variable - without success.

Here is my request call, which includes customVarValue1.

...
$ga->requestReportData(ga_profile_id, array('visitorType', 'customVarValue1', 
'networkDomain', 'hostname', 'pagePath', 'date', 'hour'), 
array('pageviews','visits'));

No results are returned.

But if I exclude customVarValue1, I get results.

Original comment by colin.go...@gmail.com on 14 Jun 2011 at 3:05

GoogleCodeExporter commented 9 years ago
Hi,
I am 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 requst 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 perticular member ID that is why I used 
the condition as below:
filters=ga:pagePath=@event_details.php;ga:customVarValue1=2004036442&

I have also tried like this and this is also not working

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&
segment=dynamic::ga:customVarValue1==1041533899&
start-date=2011-04-20&
end-date=2011-05-04&
max-results=50

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

Original comment by contactv...@gmail.com on 28 Jul 2011 at 11:21

GoogleCodeExporter commented 9 years ago
You should be able to retrieve custom variables as long as custom variables 
have been captured in the date range you sent.

As far as filtering by them, this is a bit of a bug in the GAPI class.  To fix 
it you can either (as others have suggested) prefix your customVarValue{n} and 
customVarName{n} values with "ga:".  For example: "ga:customVarValue1 == 
myvariable" instead of "customVarValue1 == myvariable".

Or you can open up the gapi.class.php file and edit line 235, changing:

$filter = preg_replace('/(&&\s*|\|\|\s*|^)([a-z]+)(\s*' . $valid_operators . 
')/i','$1ga:$2$3',$filter);

to:

$filter = preg_replace('/(&&\s*|\|\|\s*|^)([a-z0-9]+)(\s*' . $valid_operators . 
')/i','$1ga:$2$3',$filter);

Just added a 0-9 to the regular expression character class so it will properly 
prefix the custom variable filters.

Original comment by char...@dwstudios.net on 23 Feb 2012 at 10:40