Class: FacebookAds::Ad

Inherits:
Base
  • Object
show all
Defined in:
lib/facebook_ads/ad.rb

Overview

An ad belongs to an ad set. It is created using an ad creative. developers.facebook.com/docs/marketing-api/reference/adgroup

Constant Summary collapse

FIELDS =
%w[id account_id campaign_id adset_id adlabels bid_amount bid_info bid_type configured_status conversion_specs created_time creative effective_status last_updated_by_app_id name tracking_specs updated_time ad_review_feedback].freeze
STATUSES =
%w[ACTIVE PAUSED DELETED PENDING_REVIEW DISAPPROVED PREAPPROVED PENDING_BILLING_INFO CAMPAIGN_PAUSED ARCHIVED ADSET_PAUSED].freeze

Instance Method Summary collapse

Methods inherited from Base

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

Instance Method Details

#ad_accountObject

belongs_to ad_account



12
13
14
# File 'lib/facebook_ads/ad.rb', line 12

def 
  @ad_account ||= AdAccount.find()
end

#ad_campaignObject

belongs_to ad_campaign



18
19
20
# File 'lib/facebook_ads/ad.rb', line 18

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

#ad_creativeObject

belongs_to ad_creative



30
31
32
# File 'lib/facebook_ads/ad.rb', line 30

def ad_creative
  @ad_creative ||= AdCreative.find(creative['id'])
end

#ad_insights(range: Date.today..Date.today, level: 'ad', time_increment: 1) ⇒ Object

has_many ad_insights



36
37
38
39
40
41
42
43
# File 'lib/facebook_ads/ad.rb', line 36

def ad_insights(range: Date.today..Date.today, level: 'ad', time_increment: 1)
  query = {
    level: level,
    time_increment: time_increment,
    time_range: { 'since': range.first.to_s, 'until': range.last.to_s }
  }
  AdInsight.paginate("/#{id}/insights", query: query)
end

#ad_setObject

belongs_to ad_set



24
25
26
# File 'lib/facebook_ads/ad.rb', line 24

def ad_set
  @ad_set ||= AdSet.find(adset_id)
end