Class: SeoMetricsSyncWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Status::Worker, Sidekiq::Worker
Defined in:
app/workers/seo_metrics_sync_worker.rb

Overview

Nightly worker to sync SEO metrics from all sources.
Writes time-series data to site_map_data_points for historical tracking.

Sources:

  • Ahrefs: Estimated traffic, keywords, positions, traffic value
  • Google Search Console: Clicks, impressions, CTR, position
  • Google Analytics 4: Page views, sessions, bounce rate, engagement
  • Visits table: First-party page view counts

Scheduled nightly via sidekiq_production_schedule.yml

Instance Method Summary collapse

Instance Method Details

#performObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/workers/seo_metrics_sync_worker.rb', line 20

def perform
  total 5

  # Step 1: Sync Ahrefs data
  at 1, 'Syncing Ahrefs metrics...'
  ahrefs_result = sync_ahrefs

  # Step 2: Sync GSC data
  at 2, 'Syncing Google Search Console metrics...'
  gsc_result = sync_gsc

  # Step 3: Sync GA4 data
  at 3, 'Syncing Google Analytics 4 metrics...'
  ga4_result = sync_ga4

  # Step 4: Sync Visit counts
  at 4, 'Syncing visit counts from internal data...'
  visits_result = sync_visits

  # Step 5: Update sync timestamps
  at 5, 'Updating sync timestamps...'
  update_sync_timestamps

  # Store summary
  store info_message: build_summary(ahrefs_result, gsc_result, ga4_result, visits_result)
end