开发者

PHP Problem with Google Analytics

Hey, I'm having some trouble with this code for retrieving Google Analytic data.

if($_GET['month'] || $_GET['year']):
    $month = (int) $_GET['month']; if(!$month) { $month = 1; }
    $year = (int) $_GET['year']; if(!$year) { $year = date('Y'); }
    require 'ga/analytics.class.php';
    $analytics = new analytics('email@domain.com', 'password');

    $analytics->setProfileByName('mysite.com');

    $analytics->setMonth($month,$year);
    $visits = $analytics->getVisitors();
    $views = $analytics->getPageviews();
    if(count($visits)) {
        foreach($visits as $day=>$visit) { 开发者_Go百科
            $flot_datas_visits[] = '['.$day.','.$visit.']';
            $flot_datas_views[] = '['.$day.','.$views[$day].']';
        }
        $flot_data_visits = '['.implode(',',$flot_datas_visits).']';
        $flot_data_views = '['.implode(',',$flot_datas_views).']';
    }
endif;

I keep getting this error:

Fatal error: Uncaught exception 'Exception' with message 'No profile ID found!'

Any help would be great, Thanks!


It seems that you are passing a wrong account name to the Analytics class at this line:

$analytics->setProfileByName('mysite.com');

Just login to Google Analytics, from the home page where you have the list of your registered sites click on Manage>Google Analytics Profile and replace "mysite.com" with the value of the very right column that says "Accounts".

I hope that solves the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜