Class: Seo::VisitsSyncService

Inherits:
BaseService show all
Defined in:
app/services/seo/visits_sync_service.rb

Overview

Syncs first-party page view counts from the Visits table.
Writes to site_map_data_points (source of truth) and updates visit_count_30d on site_maps (cached for SQL sorting).

This provides 100% accurate first-party data on actual page views,
independent of third-party analytics services.

Examples:

Basic usage

Seo::VisitsSyncService.new.process

Process specific site maps only

Seo::VisitsSyncService.new(site_map_ids: [1, 2, 3]).process

Instance Method Summary collapse

Methods inherited from BaseService

#log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger

Constructor Details

#initialize(options = {}) ⇒ VisitsSyncService

Returns a new instance of VisitsSyncService.



17
18
19
20
21
# File 'app/services/seo/visits_sync_service.rb', line 17

def initialize(options = {})
  super
  @site_map_ids = options[:site_map_ids]
  @stats = { pages_updated: 0, errors: [] }
end

Instance Method Details

#processObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/seo/visits_sync_service.rb', line 23

def process
  @logger.info '[VisitsSyncService] Starting visit count sync'

  site_maps = @site_map_ids.present? ? SiteMap.where(id: @site_map_ids) : SiteMap.all
  site_maps.find_each do |site_map|
    sync_visit_counts(site_map)
  end

  @logger.info "[VisitsSyncService] Completed: #{@stats[:pages_updated]} pages updated"
  @stats
end