2011-11-15 12 views
2

私は(gapiソースコードを使用して)参照先のリンクをユーザーのウェブサイトにリクエストしようとしています。たとえば、Facebookからクリックした場合や、紹介された紹介者が何人いるかなどです。google analytics apiのAPI(参照元)gapiを使用して

ページビューの日付にリンクする私のgapiコードは現在次のようになっています。

$ga = new gapi(ga_email,ga_password); 
$filter = 'country == United Kingdom && browser == Firefox || browser == Chrome'; 
$ga->requestReportData(ga_profile_id,array('browser','browserVersion'),array('pageviews','visits'),'-visits',$filter, $start_date=$date, $end_date=$date); 

<?php echo $ga->getVisits() ?> 

でページにエコーされどのように私は、フィルタが参照さページを通してそれをエコーNDリストの中からを表示するのですか?

答えて

2

唯一の目的は紹介URLと総ページビュー数と訪問数を取得することです。私はそれがあなたが望むものだと思う。

<?php 
define('ga_email','[email protected]'); 
define('ga_password','password'); 
define('ga_profile_id','profile_id'); 

require 'gapi.class.php'; 

$ga = new gapi(ga_email,ga_password); 

$filter = 'medium==referral && referralPath != /'; 

/*** // << add '/' to uncomment 
$date_start = '2011-11-01'; 
$date_end = '2011-11-13'; 
//**/$date_start = $date_end = null; 

$ga->requestReportData(
    ga_profile_id, 
    array('source','referralPath'),//what field you are looking for 
    array('pageviews','visits'),//what metric you want to calculate 
    '-visits',//sort order, prefix - means descending 
    $filter,//filter query 
    $date_start,//yyyy-mm-dd or null 
    $date_end,//yyyy-mm-dd or null 
    1,//offset lookup 
    100);//max result 
?> 
<table> 
<tr> 
    <th>Referral URL</th> 
    <th>Pageviews</th> 
    <th>Visits</th> 
</tr> 
<?php 
foreach($ga->getResults() as $result): 
?> 
<tr> 
    <td><?php echo $result->getSource() . $result->getReferralPath() ?></td> 
    <td><?php echo $result->getPageviews() ?></td> 
    <td><?php echo $result->getVisits() ?></td> 
</tr> 
<?php 
endforeach 
?> 
</table> 
+0

ありがとうございました – meohmy

+0

ありがとう私はしばらくの間これをやろうとしています! Awesome – JasonDavis

+1

これは素晴らしいですが、特定のページのトップの紹介を表示する方法を知っていますか?私は最高のショーを私のトップの紹介は、各ブログの記事のWordPressのサイトにしようとしている?私はこのフィルタを変更しようとしました... $ filter = 'pagePath ==/articles/50-web-developer-documentation-manuals-you-know-about/&& medium == referral && referralPath!=/'; 'しかし、私がこれをしたときには正確ではない結果しか表示されていないようでした! – JasonDavis

関連する問題