1

トピックを復活させて申し訳ありませんが、私は同じ疑問を持っています。

私はgapiを使用しています。現在、「2013年10月23日」Googleはデータの取得方法を少し変更しました。総訪問数を取得できません。

サイトへの総アクセス数だけが必要です。それ以上は必要ありません。

ここで私が使用しているコード:

<?php
define('ga_email','email@gmail.com');
define('ga_password','password');
define('ga_profile_id','999999');

require 'gapi.class.php';
$ga = new gapi(ga_email,ga_password);
$ga->requestReportData(ga_profile_id,
  array('browser','browserVersion'),
  array('pageviews','visitors')
);
?>

<table>
<tr>
  <th>Browser &amp; Browser Version</th>
  <th>Pageviews</th>
</tr>

<?php
foreach($ga->getResults() as $result):
?>

<tr>
  <td><?php echo $result ?></td>
  <td><?php echo $result->getPageviews() ?></td>
  <td><?php echo "Visitors: ".$result->getVisitors() ?></td>
</tr>

<?php
    endforeach
?>

</table>

<table>
<tr>
  <th>Total Results</th>
  <td><?php echo $ga->getTotalResults() ?></td>
</tr>

<tr>
  <th>Total Pageviews</th>
  <td><?php echo $ga->getPageviews() ?>
</tr>

<tr>
  <th>Total Visits</th>
  <td><?php echo $ga->getVisitors() ?></td>
</tr>

<tr>
  <th>Results Updated</th>
  <td><?php echo $ga->getUpdated() ?></td>
</tr>

</table>}

誰かがこれを行う方法の例を教えてもらえますか?

ありがとう

4

1 に答える 1

1

あなたのforeachは間違っています

<?php
 ....

 foreach($ga->getResults() as $result):
?>

次のようにする必要があります。

<?php
 ....

 foreach($ga->getResults() as $result) {
 ?>

<tr>
  <td><?php echo $result ?></td>
  <td><?php echo $result->getPageviews() ?></td>
  <td><?php echo "Visitors: ".$result->getVisitors() ?></td>
</tr>

<?php
 }
?>

あなたは何を手に入れますか:

<?php
....


$ga->requestReportData(
  ga_profile_id,
  array('browser'),
  array('pageviews','visits'),
  array('-visits'),
  null,
  '2013-05-01',
  null,
  1,
  30
);
?>

<table>
<tr>
  <th>Total Pageviews</th>
  <td><?php echo $ga->getPageviews() ?>
</tr>
<tr>
  <th>Total Visits</th>
  <td><?php echo $ga->getVisits() ?></td>
</tr>
</table>
于 2013-11-19T15:06:52.280 に答える