Integrating 1C-Bitrix with Google Search Console
Google Search Console has no direct counterpart among 1C-Bitrix tools. Click, impression, and position data from GSC is not available in Metrica. Integration via the Search Console API makes it possible to automatically collect this data and aggregate it in the 1C-Bitrix administrative panel — without opening external services every day.
Integrating 1C-Bitrix with Google Search Console
Google Search Console API: available data
Search Console API (v1) provides:
- Search Analytics — clicks, impressions, CTR, positions by queries, pages, devices, and countries
- URL Inspection API — indexing status for a specific URL
- Sitemaps API — sitemap management
- URL Notifications API (via Indexing API) — re-indexing requests for pages with job listings and live streams (restricted access for other types)
Authorization: OAuth 2.0 or Service Account (preferred for server-side applications — no manual token refresh required).
Authorization via Service Account
// Install google/apiclient via Composer in /local/
// composer require google/apiclient
namespace Google\SearchConsole;
class ServiceClient
{
private \Google\Service\SearchConsole $service;
public function __construct()
{
$keyFile = \Bitrix\Main\Config\Option::get('mymodule', 'gsc_key_file_path');
$client = new \Google\Client();
$client->setAuthConfig($keyFile);
$client->addScope(\Google\Service\SearchConsole::WEBMASTERS_READONLY);
$this->service = new \Google\Service\SearchConsole($client);
}
public function getSearchAnalytics(
string $siteUrl,
string $startDate,
string $endDate,
array $dimensions = ['query', 'page']
): array {
$request = new \Google\Service\SearchConsole\SearchAnalyticsQueryRequest();
$request->setStartDate($startDate);
$request->setEndDate($endDate);
$request->setDimensions($dimensions);
$request->setRowLimit(5000);
$response = $this->service->searchanalytics->query($siteUrl, $request);
return $response->getRows() ?? [];
}
}
The Service Account JSON key is stored in a secured folder outside the webroot. The path to it is stored in b_option via \Bitrix\Main\Config\Option.
Collecting data by site pages
A 1C-Bitrix agent fetches the previous day's data daily and saves it to a custom table:
class GscDataCollectorAgent
{
public static function run(): string
{
$client = new \Google\SearchConsole\ServiceClient();
$siteUrl = \Bitrix\Main\Config\Option::get('mymodule', 'gsc_site_url');
$date = date('Y-m-d', strtotime('-3 days')); // GSC: data with a 2-3 day delay
$rows = $client->getSearchAnalytics(
$siteUrl,
$date,
$date,
['page', 'query']
);
$connection = \Bitrix\Main\Application::getConnection();
foreach ($rows as $row) {
$connection->queryExecute(
'INSERT INTO b_gsc_analytics (DATE, PAGE, QUERY, CLICKS, IMPRESSIONS, CTR, POSITION)
VALUES (?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
CLICKS = VALUES(CLICKS), IMPRESSIONS = VALUES(IMPRESSIONS),
CTR = VALUES(CTR), POSITION = VALUES(POSITION)',
[
$date,
$row->getKeys()[0], // page
$row->getKeys()[1], // query
(int)$row->getClicks(),
(int)$row->getImpressions(),
round($row->getCtr() * 100, 2),
round($row->getPosition(), 1),
]
);
}
return __CLASS__ . '::run();';
}
}
The b_gsc_analytics table:
CREATE TABLE b_gsc_analytics (
ID INT AUTO_INCREMENT PRIMARY KEY,
DATE DATE NOT NULL,
PAGE VARCHAR(2048) NOT NULL,
QUERY VARCHAR(512) NOT NULL,
CLICKS INT DEFAULT 0,
IMPRESSIONS INT DEFAULT 0,
CTR DECIMAL(5,2) DEFAULT 0,
POSITION DECIMAL(6,1) DEFAULT 0,
UNIQUE KEY idx_date_page_query (DATE, PAGE(500), QUERY(200))
);
URL Inspection: page indexing status
Checking the indexing status of a specific URL via API:
public function inspectUrl(string $siteUrl, string $pageUrl): array
{
$request = new \Google\Service\SearchConsole\InspectUrlIndexRequest();
$request->setInspectionUrl($pageUrl);
$request->setSiteUrl($siteUrl);
$response = $this->service->urlInspection_index->inspect($request);
$result = $response->getInspectionResult();
return [
'verdict' => $result->getIndexStatusResult()->getVerdict(),
'coverage_state' => $result->getIndexStatusResult()->getCoverageState(),
'last_crawl_time' => $result->getIndexStatusResult()->getLastCrawlTime(),
'robots_txt_state' => $result->getIndexStatusResult()->getRobotsTxtState(),
'indexing_state' => $result->getIndexStatusResult()->getIndexingState(),
'canonical' => $result->getIndexStatusResult()->getGoogleCanonical(),
];
}
Displaying the status in an iblock element card lets editors immediately see whether the page is indexed.
SEO data dashboard in the administrative panel
Using the collected data, we build reports in the 1C-Bitrix administrative panel. We use the standard admin page interface:
- Top queries with low CTR at high impressions — potential for improving title/description
- Pages with declining positions — require attention from the content team
- Pages with zero clicks — possible sign of incorrect meta markup or keyword cannibalization
Data from b_gsc_analytics is joined with b_iblock_element by URL — providing direct links to edit content in the administrative panel.
Auto-updating Sitemap
// After generating the sitemap
$sitemap = $this->service->sitemaps;
$sitemap->submit($siteUrl, 'https://site.ru/sitemap.xml');
API limitations
- URL Inspection: 2,000 requests per day per project
- Search Analytics: data with a 2–3 day delay, depth — 16 months
- Rows per response: up to 25,000 (filtering needed for large sites)
- Service Account must be added to GSC with "Full access" permissions
Timelines
| Task | Timeline |
|---|---|
| Service Account setup, authorization, connection test | 4–8 hours |
| Search Analytics collection, storage in 1C-Bitrix database | 1–2 days |
| Dashboard with query and page reports | 2–3 days |
| URL Inspection in iblock element cards | 1 day |







