Class: FacebookAds::ServerSide::EventRequest
- Inherits:
-
Object
- Object
- FacebookAds::ServerSide::EventRequest
- Defined in:
- lib/facebook_ads/ad_objects/server_side/event_request.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
An array of Server Event objects.
-
#namespace_id ⇒ Object
Scope used to resolve extern_id or Third-party ID.
-
#partner_agent ⇒ Object
Platform from which the event is sent e.g.
-
#pixel_id ⇒ Object
Ad pixel id.
-
#test_event_code ⇒ Object
Code used to verify that your server events are received correctly by Facebook.
-
#upload_id ⇒ Object
Unique id used to denote the current set being uploaded.
-
#upload_source ⇒ Object
The origin/source of data for the dataset to be uploaded.
-
#upload_tag ⇒ Object
Tag string added to track your Offline event uploads.
Instance Method Summary collapse
-
#==(o) ⇒ Object
Checks equality by comparing each attribute.
-
#build(attributes = {}) ⇒ Object
build the object using the input hash.
- #eql?(o) ⇒ Boolean
-
#execute ⇒ Object
Execute request.
-
#hash ⇒ Fixnum
Calculates hash code according to all attributes.
-
#initialize(pixel_id: nil, events: nil, test_event_code: nil, partner_agent: nil, namespace_id: nil, upload_id: nil, upload_tag: nil, upload_source: nil) ⇒ EventRequest
constructor
A new instance of EventRequest.
-
#list_invalid_properties ⇒ Object
Show invalid properties with the reasons.
- #normalize ⇒ Object
- #to_s ⇒ Object
-
#valid? ⇒ Boolean
Check to see if the all the properties in the model are valid.
Constructor Details
#initialize(pixel_id: nil, events: nil, test_event_code: nil, partner_agent: nil, namespace_id: nil, upload_id: nil, upload_tag: nil, upload_source: nil) ⇒ EventRequest
Returns a new instance of EventRequest.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 62 def initialize(pixel_id: nil, events: nil, test_event_code: nil, partner_agent: nil, namespace_id: nil, upload_id: nil, upload_tag: nil, upload_source: nil) unless pixel_id.nil? self.pixel_id = pixel_id end unless events.nil? self.events = events end unless test_event_code.nil? self.test_event_code = test_event_code end unless partner_agent.nil? self.partner_agent = partner_agent end unless namespace_id.nil? self.namespace_id = namespace_id end unless upload_id.nil? self.upload_id = upload_id end unless upload_tag.nil? self.upload_tag = upload_tag end unless upload_source.nil? self.upload_source = upload_source end end |
Instance Attribute Details
#events ⇒ Object
An array of Server Event objects
28 29 30 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 28 def events @events end |
#namespace_id ⇒ Object
Scope used to resolve extern_id or Third-party ID. Can be another data set or data partner ID.
43 44 45 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 43 def namespace_id @namespace_id end |
#partner_agent ⇒ Object
Platform from which the event is sent e.g. wordpress
40 41 42 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 40 def partner_agent @partner_agent end |
#pixel_id ⇒ Object
Ad pixel id
37 38 39 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 37 def pixel_id @pixel_id end |
#test_event_code ⇒ Object
Code used to verify that your server events are received correctly by Facebook. Use this code to test your server events in the Test Events feature in Events Manager. See Test Events Tool (developers.facebook.com/docs/marketing-api/facebook-pixel/server-side-api/using-the-api#testEvents) for an example.
34 35 36 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 34 def test_event_code @test_event_code end |
#upload_id ⇒ Object
Unique id used to denote the current set being uploaded.
46 47 48 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 46 def upload_id @upload_id end |
#upload_source ⇒ Object
The origin/source of data for the dataset to be uploaded.
52 53 54 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 52 def upload_source @upload_source end |
#upload_tag ⇒ Object
Tag string added to track your Offline event uploads.
49 50 51 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 49 def upload_tag @upload_tag end |
Instance Method Details
#==(o) ⇒ Object
Checks equality by comparing each attribute.
186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 186 def ==(o) return true if self.equal?(o) self.class == o.class && pixel_id == o.pixel_id && events == o.events && test_event_code == o.test_event_code && partner_agent == o.partner_agent && namespace_id == o.namespace_id && upload_id == o.upload_id && upload_tag == o.upload_tag && upload_source == o.upload_source end |
#build(attributes = {}) ⇒ Object
build the object using the input hash
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 92 def build(attributes = {}) return unless attributes.is_a?(Hash) # convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } if attributes.has_key?(:'pixel_id') self.pixel_id = attributes[:'pixel_id'] end if attributes.has_key?(:'events') if (value = attributes[:'events']).is_a?(Array) self.events = value end end if attributes.has_key?(:'test_event_code') self.test_event_code = attributes[:'test_event_code'] end if attributes.has_key?(:'partner_agent') self.partner_agent = attributes[:'partner_agent'] end if attributes.has_key?(:'namespace_id') self.namespace_id = attributes[:'namespace_id'] end if attributes.has_key?(:'upload_id') self.upload_id = attributes[:'upload_id'] end if attributes.has_key?(:'upload_tag') self.upload_tag = attributes[:'upload_tag'] end if attributes.has_key?(:'upload_source') self.upload_source = attributes[:'upload_source'] end end |
#eql?(o) ⇒ Boolean
200 201 202 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 200 def eql?(o) self == o end |
#execute ⇒ Object
Execute request
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 134 def execute unless valid? raise list_invalid_properties end normalized_events = normalize ads_pixel = FacebookAds::AdsPixel.get(pixel_id) response = ads_pixel.events.create( { data: normalized_events, test_event_code: test_event_code, partner_agent: partner_agent, namespace_id: namespace_id, upload_id: upload_id, upload_tag: upload_tag, upload_source: upload_source, } ) json_response_object = JSON.parse(JSON.generate(response), object_class: OpenStruct) FacebookAds::ServerSide::EventResponse.new( events_received: json_response_object.events_received, messages: json_response_object., fbtrace_id: json_response_object.fbtrace_id ) end |
#hash ⇒ Fixnum
Calculates hash code according to all attributes.
206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 206 def hash [ pixel_id, events, test_event_code, partner_agent, namespace_id, upload_id, upload_tag, upload_source, ].hash end |
#list_invalid_properties ⇒ Object
Show invalid properties with the reasons. Usually used together with valid?
169 170 171 172 173 174 175 176 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 169 def list_invalid_properties invalid_properties = Array.new if @events.nil? invalid_properties.push('invalid value for "data", data cannot be nil.') end invalid_properties end |
#normalize ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 159 def normalize normalized_events = [] events.each do |event| normalized_events.push(JSON.generate(event.normalize)) end normalized_events end |
#to_s ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 219 def to_s hash = {} unless pixel_id.nil? hash['pixel_id'] = pixel_id end unless events.nil? hash['data'] = events end unless test_event_code.nil? hash['test_event_code'] = test_event_code end unless partner_agent.nil? hash['partner_agent'] = partner_agent end unless namespace_id.nil? hash['namespace_id'] = namespace_id end unless upload_id.nil? hash['upload_id'] = upload_id end unless upload_tag.nil? hash['upload_tag'] = upload_tag end unless upload_source.nil? hash['upload_source'] = upload_source end hash.to_s end |
#valid? ⇒ Boolean
Check to see if the all the properties in the model are valid
180 181 182 183 |
# File 'lib/facebook_ads/ad_objects/server_side/event_request.rb', line 180 def valid? return false if @events.nil? true end |