コード例 #1
0
 /**
  * @covers \Yandex\Metrica\Stat\StatClient::data
  */
 public function testMethodDataWithCustomClient()
 {
     $token = 'test';
     $statClient = new StatClient($token, $this->getMock('GuzzleHttp\\Client'));
     $client = $statClient->data();
     $this->assertTrue($client instanceof DataClient);
     $this->assertEquals($token, $client->getAccessToken());
 }
コード例 #2
0
ファイル: bytime.php プロジェクト: andyceo/yandex-php-library
<?php

/**
 * User: Tanya Kalashnik
 * Date: 21.07.14 13:18
 */
use Yandex\Metrica\Stat\StatClient;
$data = [];
$errorMessage = false;
//Is auth
if (isset($_COOKIE['yaAccessToken']) && isset($_COOKIE['yaClientId'])) {
    $settings = (require_once '../../settings.php');
    try {
        $statClient = new StatClient($_COOKIE['yaAccessToken']);
        if (isset($_GET['counter-id']) && $_GET['counter-id']) {
            $counterId = $_GET['counter-id'];
            $paramsModel = new Yandex\Metrica\Stat\Models\ByTimeParams();
            $paramsModel->setMetrics(\Yandex\Metrica\Stat\MetricConst::S_HITS)->setId($counterId)->setDate1('6daysAgo')->setDate2('today')->setGroup('day')->setFilters("ym:s:isMobile!='Yes'");
            $data = $statClient->data()->getByTime($paramsModel);
        }
    } catch (\Exception $ex) {
        $errorMessage = $ex->getMessage();
        if ($errorMessage === 'PlatformNotAllowed') {
            $errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте ' . '<a href="' . rtrim(str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__), "/") . '/../OAuth/' . '">авторизироваться</a> и повторить.</p>';
        }
    }
}
?>
<!doctype html>
<html lang="en-US">
<head>
コード例 #3
0
<?php

/**
 * User: Tanya Kalashnik
 * Date: 21.07.14 16:38
 */
use Yandex\Metrica\Stat\StatClient;
$data = array();
$errorMessage = false;
//
//Is auth
if (isset($_COOKIE['yaAccessToken']) && isset($_COOKIE['yaClientId'])) {
    $settings = (require_once '../../settings.php');
    try {
        $statClient = new StatClient($_COOKIE['yaAccessToken']);
        if (isset($_GET['counter-id']) && $_GET['counter-id']) {
            $counterId = $_GET['counter-id'];
            $paramsModel = new Yandex\Metrica\Stat\Models\ComparisonParams();
            $paramsModel->setMetrics(\Yandex\Metrica\Stat\MetricConst::S_USERS)->setId($counterId)->setDimensions(\Yandex\Metrica\Stat\DimensionsConst::S_TRAFFIC_SOURCE)->setFiltersA("ym:s:isMobile=='Yes'")->setFiltersB("ym:s:isMobile=='No'");
            /**
             * @see http://api.yandex.ru/metrika/doc/beta/api_v1/requestcompareab.xml
             */
            $data = $statClient->data()->getComparisonSegments($paramsModel);
        }
    } catch (\Exception $ex) {
        $errorMessage = $ex->getMessage();
        if ($errorMessage === 'PlatformNotAllowed') {
            $errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте ' . '<a href="' . rtrim(str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__), "/") . '/../OAuth/' . '">авторизироваться</a> и повторить.</p>';
        }
    }
}
コード例 #4
0
<?php

/**
 * User: Tanya Kalashnik
 * Date: 21.07.14 11:18
 */
use Yandex\Metrica\Stat\StatClient;
$data = array();
$errorMessage = false;
//Is auth
if (isset($_COOKIE['yaAccessToken']) && isset($_COOKIE['yaClientId'])) {
    $settings = (require_once '../../settings.php');
    try {
        $statClient = new StatClient($_COOKIE['yaAccessToken']);
        if (isset($_GET['counter-id']) && $_GET['counter-id']) {
            $counterId = $_GET['counter-id'];
            $paramsModel = new Yandex\Metrica\Stat\Models\TableParams();
            $paramsModel->setPreset(\Yandex\Metrica\Stat\AvailableValues::PRESET_TECH_PLATFORMS)->setDimensions(\Yandex\Metrica\Stat\DimensionsConst::S_BROWSER)->setId($counterId);
            /**
             * @see http://api.yandex.ru/metrika/doc/beta/api_v1/data.xml
             */
            $data = $statClient->data()->getTable($paramsModel);
        }
    } catch (\Exception $ex) {
        $errorMessage = $ex->getMessage();
        if ($errorMessage === 'PlatformNotAllowed') {
            $errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте ' . '<a href="/examples/OAuth/">авторизироваться</a> и повторить.</p>';
        }
    }
}
?>