Answer the question
In order to leave comments, you need to log in
How to analyze search queries by device using Google Search Console APIs?
Hi everybody. I work with Google Search Console APIs, I need to get an analysis of search queries by device.
I do everything like this
require_once __DIR__ . '/vendor/autoload.php';
function initializeWebmasters(){
$KEY_FILE_LOCATION = __DIR__ . '/файл сервисного аккаунта.json';
$client = new Google_Client();
$client->setApplicationName("Google Webmasters Hello");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/webmasters.readonly']);
return $client;
}
$webmasters = new Google_Service_Webmasters(initializeWebmasters());
$enddate = date("Y-m-d",time()-(3*(24*60*60)));
$startdate = date("Y-m-d",time()-(3*(24*60*60)));
$ar_fil_dim = new Google_Service_Webmasters_ApiDimensionFilter();
$ar_fil_dim -> setDimension("device");
$ar_fil_dim -> setOperator("contains");
$ar_fil_dim -> setExpression("MOBILE");
$ar_fil_q = new Google_Service_Webmasters_ApiDimensionFilterGroup();
$ar_fil_q -> setFilters($ar_fil_dim);
$webmasters1 = new Google_Service_Webmasters_SearchAnalyticsQueryRequest();
$webmasters1->setStartDate($startdate);
$webmasters1->setEndDate($enddate);
$webmasters1->setSearchType("web");
$webmasters1->setDimensions("query");
$webmasters1->setDimensionFilterGroups($ar_fil_q);
$webmasters1->setRowLimit(1000);
$siteUrl = 'нужный сайт';
$result = $webmasters->searchanalytics->query($siteUrl, $webmasters1) ;
echo '<pre>';
print_r($result);
echo '</pre>';
Answer the question
In order to leave comments, you need to log in
doing like this
$query = ['запрос'];
$searchTypes = ['web'];
$dataType = ['query'];
//$enddate = date("Y-m-d",time()-(3*(24*60*60)));
//$startdate = date("Y-m-d",time()-(3*(24*60*60)));
$enddate = "2017-03-18";
$startdate = "2017-03-18";
$ar_fil_dimqq = new Google_Service_Webmasters_ApiDimensionFilter();
$ar_fil_dimqq -> setDimension("query");
$ar_fil_dimqq -> setExpression($query);
$ar_fil_q = new Google_Service_Webmasters_ApiDimensionFilterGroup();
$ar_fil_q -> setFilters( $ar_fil_dimqq );
$webmasters1 = new Google_Service_Webmasters_SearchAnalyticsQueryRequest();
$webmasters1->setStartDate($startdate);
$webmasters1->setEndDate($enddate);
$webmasters1->setSearchType($searchTypes);
$webmasters1->setDimensions($dataType);
$webmasters1->setDimensionFilterGroups($ar_fil_q);
$siteUrl = 'сайт';
$result = $webmasters->searchanalytics->query($siteUrl, $webmasters1) ;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question