Class: TheTradeDeskAds::AdSet

Inherits:
Base
  • Object
show all
Defined in:
lib/the_trade_desk_ads/ad_set.rb

Overview

An ad set belongs to a campaign and has many ads. developers.facebook.com/docs/marketing-api/reference/ad-campaign

Constant Summary collapse

FIELDS =

Fields we might actually care about:

%w[
  id account_id campaign_id
  name
  status configured_status effective_status
  bid_amount billing_event optimization_goal pacing_type
  daily_budget budget_remaining lifetime_budget
  promoted_object
  targeting
  created_time updated_time
].freeze
STATUSES =
%w[ACTIVE PAUSED DELETED PENDING_REVIEW DISAPPROVED PREAPPROVED PENDING_BILLING_INFO CAMPAIGN_PAUSED ARCHIVED ADSET_PAUSED].freeze
BILLING_EVENTS =
%w[APP_INSTALLS IMPRESSIONS].freeze
OPTIMIZATION_GOALS =
%w[
  NONE
  APP_INSTALLS
  BRAND_AWARENESS
  CLICKS
  ENGAGED_USERS
  EVENT_RESPONSES
  IMPRESSIONS
  LEAD_GENERATION
  LINK_CLICKS
  OFFER_CLAIMS
  OFFSITE_CONVERSIONS
  PAGE_ENGAGEMENT
  PAGE_LIKES
  POST_ENGAGEMENT
  REACH
  SOCIAL_IMPRESSIONS
  VIDEO_VIEWS
  APP_DOWNLOADS
].freeze

Instance Method Summary collapse

Methods inherited from Base

auth, delete, #destroy, find, get, paginate, post, #save, #update

Instance Method Details

#ad_accountObject

belongs_to ad_account



59
60
61
# File 'lib/the_trade_desk_ads/ad_set.rb', line 59

def 
   ||= AdAccount.find("act_#{account_id}")
end

#ad_campaignObject

belongs_to ad_campaign



65
66
67
# File 'lib/the_trade_desk_ads/ad_set.rb', line 65

def ad_campaign
  @campaign ||= AdCampaign.find(campaign_id)
end

#ads(effective_status: ['ACTIVE'], limit: 100) ⇒ Object

has_many ads



71
72
73
# File 'lib/the_trade_desk_ads/ad_set.rb', line 71

def ads(effective_status: ['ACTIVE'], limit: 100)
  Ad.paginate("/#{id}/ads", query: { effective_status: effective_status, limit: limit })
end

#create_ad(name:, creative_id:) ⇒ Object



75
76
77
78
79
# File 'lib/the_trade_desk_ads/ad_set.rb', line 75

def create_ad(name:, creative_id:)
  query = { name: name, adset_id: id, creative: { creative_id: creative_id }.to_json }
  result = Ad.post("/act_#{account_id}/ads", query: query)
  Ad.find(result['id'])
end