andeedee / gapi-google-analytics-php-interface

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

$result->getTimeOnSite() returns false information #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. You must have a profile with a TimeOnSite value higher than at least
6928817 (10 million or higher returns 1, 20 million returns 2)
2. Try to use the code snippet provided below

What is the expected output? What do you see instead?
I expect $result->getTimeOnSite() to return 10000000
I bet any $result->get... with a result over a certain value will return
the wrong value.

What version of the product are you using? On what operating system?
1.2, Ubuntu 9.04 Server 32 Bit

Please provide any additional information below.
$GLOBALS['dimensions'] = array('date');
$GLOBALS['metrics'] = array('pageviews', 'visits', 'bounces', 'timeOnSite',
'entrances', 'newVisits', 'goal1Starts', 'goal1Completions');
$GLOBALS['sort'] = array('date');
$GLOBALS['start_index'] = '1';
$GLOBALS['max_results'] = '1000';

$entries = $ga->requestReportData($id, $GLOBALS['dimensions'],
$GLOBALS['metrics'], $GLOBALS['sort'], null, null, null,
$GLOBALS['start_index'], $GLOBALS['max_results']);

foreach($ga->getResults() as $result) {
    echo $result->getTimeOnSite()."\n";
}

Original issue reported on code.google.com by austinre...@gmail.com on 8 Jun 2009 at 11:55

Attachments:

GoogleCodeExporter commented 9 years ago
I went through and manually ran the query through the API, and the problem is 
that
results over 10 million are returned expressed in scientific notation:

1.76160784E8
9.3857385E7
4.2922605E7
3.949009E7

Original comment by austinre...@gmail.com on 9 Jun 2009 at 12:15

GoogleCodeExporter commented 9 years ago
On line 346 the GAPI class incorrectly performs an 'intval' conversion on the 
data.
The majority of metrics returned by Google Analytics are integers, but certain
metrics like timeOnPage and CPM are float values.

A quick fix is to change Line 346 to:

$report_aggregate_metrics[str_replace('ga:','',$aggregate_metric->attributes()->
name)] =
floatval($aggregate_metric->attributes()->value);

The correct way to handle this data would be to check the string returned for 
decimal
point and use intval or floatval appropriately. Large integers are also 
returned by
Google Analytics in 'scientific notation' which can also be understood by 
floatval.

This fix will be incorporated into GAPI v1.2 and will be released within the 
next few
days.

Cheers,
Stig

Original comment by stigmann...@gmail.com on 9 Jun 2009 at 3:49

GoogleCodeExporter commented 9 years ago
GAPI 1.3 has been released and contains a fix for this issue. Proper float / 
integer
detection and conversion for metrics.

http://code.google.com/p/gapi-google-analytics-php-interface/downloads/detail?na
me=gapi.class.php

Cheers,
Stig

Original comment by stigmann...@gmail.com on 9 Jun 2009 at 1:30

GoogleCodeExporter commented 9 years ago
Wow, that was fast, I did notice that incorrect intval, and tried changing that 
it to
strval just to see what would happen, but it still came back wrong. I didn't 
realize
floatval could decipher that notation though. Awesome

Thank You

Original comment by austinre...@gmail.com on 9 Jun 2009 at 7:53

GoogleCodeExporter commented 9 years ago
Hi again,

Try this new link for version 1.3:

http://gapi-google-analytics-php-interface.googlecode.com/files/gapi-1.3.zip

I have just discovered a 'feature' with Google Code Project that when a file is
downloaded enough, it is locked and cannot be updated. GAPI releases will now 
be in
versioned archive files.

Thanks,
Stig

Original comment by stigmann...@gmail.com on 9 Jun 2009 at 10:24