Class: Seo::GscSyncService
- Inherits:
-
BaseService
- Object
- BaseService
- Seo::GscSyncService
- Defined in:
- app/services/seo/gsc_sync_service.rb
Overview
Syncs search performance data from Google Search Console.
Writes to site_map_data_points (source of truth) and updates seo_clicks on site_maps (cached for SQL sorting).
GSC provides first-party, authoritative data on how your pages appear in Google Search.
Data is typically delayed 2-3 days from Google.
Constant Summary collapse
- DEFAULT_DATE_RANGE =
days
28
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ GscSyncService
constructor
A new instance of GscSyncService.
- #process ⇒ Object
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
#initialize(options = {}) ⇒ GscSyncService
Returns a new instance of GscSyncService.
22 23 24 25 26 27 |
# File 'app/services/seo/gsc_sync_service.rb', line 22 def initialize( = {}) super @start_date = [:start_date] || DEFAULT_DATE_RANGE.days.ago.to_date @end_date = [:end_date] || Date.yesterday @stats = { pages_updated: 0, errors: [] } end |
Instance Method Details
#process ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/seo/gsc_sync_service.rb', line 29 def process @logger.info "[GscSyncService] Starting sync for #{@start_date} to #{@end_date}" # Fetch all pages data from GSC pages_data = fetch_all_pages return @stats if pages_data.blank? @logger.info "[GscSyncService] Fetched #{pages_data.size} pages from GSC" # Match GSC URLs to SiteMap records and update metrics process_pages(pages_data) @logger.info "[GscSyncService] Completed: #{@stats[:pages_updated]} pages updated" @stats end |