Class: Marketing::CustomerMatch::AudienceSync

Inherits:
Object
  • Object
show all
Defined in:
app/services/marketing/customer_match/audience_sync.rb

Overview

Syncs one audience's consent-eligible members into its Google Customer
Match user list via the Data Manager API: ensure-the-list → ingest-in-
batches. Takes a resolved audience — a stable key, a display name,
and an already consent-gated customer_scope — supplied by the Google
adapter from a Audiences::Target. Defaults to validate_only
(no real upload); a live run is BULK-OP GATED and the caller must opt in.

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, name:, customer_scope:, validate_only: true, client: Client.new) ⇒ AudienceSync

Returns a new instance of AudienceSync.

Parameters:

  • key (String)

    stable per-audience key; also the CustomerMatchAudience row

  • name (String)

    display name for the Google user list

  • customer_scope (ActiveRecord::Relation)

    consent-gated Customer relation

  • validate_only (Boolean) (defaults to: true)

    true (default) dry-runs the ingest

  • client (Client) (defaults to: Client.new)


29
30
31
32
33
34
35
# File 'app/services/marketing/customer_match/audience_sync.rb', line 29

def initialize(key:, name:, customer_scope:, validate_only: true, client: Client.new)
  @key = key.to_s
  @name = name.to_s
  @customer_scope = customer_scope
  @validate_only = validate_only
  @client = client
end

Class Method Details

.callResult

Returns:



22
# File 'app/services/marketing/customer_match/audience_sync.rb', line 22

def self.call(**) = new(**).call

Instance Method Details

#callResult

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/services/marketing/customer_match/audience_sync.rb', line 38

def call
  list_id = ensure_user_list
  request_ids = []
  members = 0
  MemberBuilder.new(@customer_scope).each_batch do |batch|
    request_ids << @client.ingest(user_list_id: list_id, members: batch, validate_only: @validate_only)
    members += batch.size
  end
  record.update!(last_synced_at: Time.current, last_member_count: members,
                 last_request_id: request_ids.last)
  Result.new(key: @key, user_list_id: list_id, member_count: members, batches: request_ids.size,
             request_ids:, validate_only: @validate_only)
end