Class: Seo::GoogleAdsSyncService

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

Overview

Syncs Google Ads paid search data into the SEO pipeline.

Queries two GAQL resources against the Google Ads API:

  1. landing_page_view — page-level paid clicks, cost, conversions
  2. search_term_view — keyword-level paid clicks, cost per landing page

Data is stored in:

  • SiteMapDataPoint (ads_* metric types) for page-level aggregates
  • SeoPageKeyword (paid_* columns) for keyword-level overlap

Scheduled at 2:35 AM, staggered after Ahrefs, via SeoGoogleAdsSyncWorker.

Examples:

Seo::GoogleAdsSyncService.new.process

Defined Under Namespace

Classes: Result

Constant Summary collapse

ACCOUNT_ID =
Invoicing::GoogleConversionReporter::WY_CHILD_LOCAL_ACCOUNT
LOOKBACK_DAYS =
30

Instance Method Summary collapse

Methods inherited from BaseService

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

Constructor Details

#initialize(options = {}) ⇒ GoogleAdsSyncService

Returns a new instance of GoogleAdsSyncService.



28
29
30
31
32
# File 'app/services/seo/google_ads_sync_service.rb', line 28

def initialize(options = {})
  super
  days = options[:lookback_days]
  @lookback = days.present? ? days.to_i.clamp(1, 90) : LOOKBACK_DAYS
end

Instance Method Details

#processObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/services/seo/google_ads_sync_service.rb', line 34

def process
  log_info "[GoogleAdsSyncService] Starting sync (#{@lookback}d lookback)"

  pages_updated = keywords_enriched = keywords_created = 0
  errors = []

  pu, errs = sync_landing_page_metrics
  pages_updated += pu
  errors.concat(errs)

  ke, kc, errs = sync_search_term_keywords
  keywords_enriched += ke
  keywords_created += kc
  errors.concat(errs)

  log_info "[GoogleAdsSyncService] Complete: #{pages_updated} pages, " \
           "#{keywords_enriched} keywords enriched, #{keywords_created} created"

  Result.new(pages_updated:, keywords_enriched:, keywords_created:, errors:)
end