Google Analytics PHP API (GAPI) - Get Direct Traffic Data -
i new @ google analytics , still finding way around. trying find way on how retrieve info (landing page, visits, pages/visits, avg. visit duration, % new visits, bounce rate) under direct traffic on dashboard(traffic sources-->sources-->direct). i've tried filtering using define('filter', 'source == direct');
their website states no luck avail. i've seen similar post here want deepen search. missing something?
my current code can retrieve info all traffic..
require_once('gapi.class.php'); define('email', 'email address'); define('password', 'password'); define('profileid', profileid); define('dimensions', 'source'); define('metrics', 'visits'); define('sortmetric', '-visits'); define('filter', null); define('startdate', '2013-01-18'); define('enddate', '2013-02-17'); define('startindex', 1); define('maxresult', 10); $ga = new gapi(email, password); $ga->requestreportdata(profileid,dimensions,metrics,sortmetric,filter,startdate,enddate,startindex,maxresult); foreach($ga->getresults() $result){ echo '<strong>'.$result.'</strong><br />'; echo 'source: ' . $result->getsource() . ' '; echo 'visits: ' . $result->getvisits() . '<br /><br />'; }
i found answer, want share guys in case encounters same problem.
basically error didn't surround direct
parenthesis ()
. replaced define('filter', 'source == direct');
define('filter', 'source==(direct)');
, viola! want.
here's code in case need it, might notice have replaced dimensions , metrics need them array.
require_once('gapi.class.php'); define('email', 'email address'); define('password', 'password'); define('profileid', profileid); $dimensions = array('landingpagepath'); $metrics = array('visits','pageviewspervisit','avgtimeonsite','percentnewvisits','visitbouncerate'); define('sortmetric', '-visits'); define('filter', 'ga:source==(direct)'); define('startdate', '2013-01-18'); define('enddate', '2013-02-17'); define('startindex', 1); define('maxresult', 10); $ga = new gapi(email, password); $ga->requestreportdata(profileid,$dimensions,$metrics,sortmetric,filter,startdate,enddate,startindex,maxresult);
php google-analytics google-analytics-api
No comments:
Post a Comment