Class: FacebookAds::AdSet

Inherits:
Base
  • Object
show all
Defined in:
lib/facebook_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_strategy 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
  AD_RECALL_LIFT
  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
  LANDING_PAGE_VIEWS
].freeze
BID_STRATEGIES =
%w[
  LOWEST_COST_WITHOUT_CAP
  LOWEST_COST_WITH_BID_CAP
  TARGET_COST
].freeze

Instance Method Summary collapse

Methods inherited from Base

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

Instance Method Details

#ad_accountObject

belongs_to ad_account



66
67
68
# File 'lib/facebook_ads/ad_set.rb', line 66

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

#ad_campaignObject

belongs_to ad_campaign



72
73
74
# File 'lib/facebook_ads/ad_set.rb', line 72

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

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

has_many ads



78
79
80
# File 'lib/facebook_ads/ad_set.rb', line 78

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

#create_ad(name:, creative_id:, status: 'PAUSED') ⇒ Object



82
83
84
85
86
# File 'lib/facebook_ads/ad_set.rb', line 82

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