-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add original_event_data and attribution_data to event payload
Summary: Update business SDK to include original event data and attribution data for CAPI payload Reviewed By: stcheng Differential Revision: D59697379 fbshipit-source-id: 27cebf31740d4f1d9401475200e08111364e4f2b
- Loading branch information
1 parent
7e7df0f
commit 02c4351
Showing
5 changed files
with
530 additions
and
0 deletions.
There are no files selected for viewing
216 changes: 216 additions & 0 deletions
216
lib/facebook_ads/ad_objects/server_side/attribution_data.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
# Copyright (c) 2017-present, Facebook, Inc. All rights reserved. | ||
# | ||
# You are hereby granted a non-exclusive, worldwide, royalty-free license to use, | ||
# copy, modify, and distribute this software in source code or binary form for use | ||
# in connection with the web services and APIs provided by Facebook. | ||
# | ||
# As with any software that integrates with the Facebook platform, your use of | ||
# this software is subject to the Facebook Platform Policy | ||
# [http://developers.facebook.com/policy/]. This copyright notice shall be | ||
# included in all copies or substantial portions of the software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
module FacebookAds | ||
module ServerSide | ||
|
||
# AttributionData indicated the attribution data used for attribution passback event to optimize the performance. | ||
class AttributionData | ||
|
||
# Touchpoint type. | ||
attr_accessor :scope | ||
|
||
# A Unix timestamp in seconds indicating when the campaign_id or fbc was first received. | ||
attr_accessor :visit_time | ||
|
||
# Meta-provided ad id from URL/deeplink. | ||
attr_accessor :ad_id | ||
|
||
# Meta-provided adset id from URL/deeplink. | ||
attr_accessor :adset_id | ||
|
||
# Meta-provided campaign id from URL/deeplink. | ||
attr_accessor :campaign_id | ||
|
||
# [0-1] weight of credit assigned to the visit. | ||
attr_accessor :attribution_share | ||
|
||
# Attribution model used to attribute the event. | ||
attr_accessor :attribution_model | ||
|
||
# Attribution woindow in days. | ||
attr_accessor :attr_window | ||
|
||
|
||
|
||
# @param [String] scope | ||
# @param [Integer] visit_time | ||
# @param [String] ad_id | ||
# @param [String] adset_id | ||
# @param [String] campaign_id | ||
# @param [Float] attribution_share | ||
# @param [String] attribution_model | ||
# @param [String] attr_window | ||
def initialize(scope: nil, visit_time: nil, ad_id: nil, adset_id: nil, campaign_id: nil, attribution_share: nil, attribution_model: nil, attr_window: nil) | ||
unless scope.nil? | ||
self.scope = scope | ||
end | ||
unless visit_time.nil? | ||
self.visit_time = visit_time | ||
end | ||
unless ad_id.nil? | ||
self.ad_id = ad_id | ||
end | ||
unless adset_id.nil? | ||
self.adset_id = adset_id | ||
end | ||
unless campaign_id.nil? | ||
self.campaign_id = campaign_id | ||
end | ||
unless attribution_share.nil? | ||
self.attribution_share = attribution_share | ||
end | ||
unless attribution_model.nil? | ||
self.attribution_model = attribution_model | ||
end | ||
unless attr_window.nil? | ||
self.attr_window = attr_window | ||
end | ||
end | ||
|
||
# build the object using the input hash | ||
# @param [Hash] attributes attributes in the form of hash | ||
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?(:'scope') | ||
self.scope = attributes[:'scope'] | ||
end | ||
|
||
if attributes.has_key?(:'visit_time') | ||
self.visit_time = attributes[:'visit_time'] | ||
end | ||
|
||
if attributes.has_key?(:'ad_id') | ||
self.ad_id = attributes[:'ad_id'] | ||
end | ||
|
||
if attributes.has_key?(:'adset_id') | ||
self.adset_id = attributes[:'adset_id'] | ||
end | ||
|
||
if attributes.has_key?(:'campaign_id') | ||
self.campaign_id = attributes[:'campaign_id'] | ||
end | ||
|
||
if attributes.has_key?(:'attribution_share') | ||
self.attribution_share = attributes[:'attribution_share'] | ||
end | ||
|
||
if attributes.has_key?(:'attribution_model') | ||
self.attribution_model = attributes[:'attribution_model'] | ||
end | ||
|
||
if attributes.has_key?(:'attr_window') | ||
self.attr_window = attributes[:'attr_window'] | ||
end | ||
end | ||
|
||
# Checks equality by comparing each attribute. | ||
def ==(o) | ||
return true if self.equal?(o) | ||
self.class == o.class && | ||
scope == o.scope && | ||
visit_time == o.visit_time && | ||
ad_id == o.ad_id && | ||
adset_id == o.adset_id && | ||
campaign_id == o.campaign_id && | ||
attribution_share == o.attribution_share && | ||
attribution_model == o.attribution_model && | ||
attr_window == o.attr_window | ||
end | ||
|
||
# @see the `==` method | ||
def eql?(o) | ||
self == o | ||
end | ||
|
||
# Calculates hash code according to all attributes. | ||
# @return [Fixnum] Hash code | ||
def hash | ||
[ | ||
scope, visit_time, ad_id, adset_id, campaign_id, attribution_share, attribution_model, attr_window | ||
].hash | ||
end | ||
|
||
def to_s | ||
hash = {} | ||
unless scope.nil? | ||
hash['scope'] = scope | ||
end | ||
unless visit_time.nil? | ||
hash['visit_time'] = visit_time | ||
end | ||
unless ad_id.nil? | ||
hash['ad_id'] = ad_id | ||
end | ||
unless adset_id.nil? | ||
hash['adset_id'] = adset_id | ||
end | ||
unless campaign_id.nil? | ||
hash['campaign_id'] = campaign_id | ||
end | ||
unless attribution_share.nil? | ||
hash['attribution_share'] = attribution_share | ||
end | ||
unless attribution_model.nil? | ||
hash['attribution_model'] = attribution_model | ||
end | ||
unless attr_window.nil? | ||
hash['attr_window'] = attr_window | ||
end | ||
hash.to_s | ||
end | ||
|
||
|
||
# Normalize input fields to server request format. | ||
def normalize | ||
hash = {} | ||
unless scope.nil? | ||
hash['scope'] = scope | ||
end | ||
unless visit_time.nil? | ||
hash['visit_time'] = visit_time | ||
end | ||
unless ad_id.nil? | ||
hash['ad_id'] = ad_id | ||
end | ||
unless adset_id.nil? | ||
hash['adset_id'] = adset_id | ||
end | ||
unless campaign_id.nil? | ||
hash['campaign_id'] = campaign_id | ||
end | ||
unless attribution_share.nil? | ||
hash['attribution_share'] = attribution_share | ||
end | ||
unless attribution_model.nil? | ||
hash['attribution_model'] = attribution_model | ||
end | ||
unless attr_window.nil? | ||
hash['attr_window'] = attr_window | ||
end | ||
hash | ||
end | ||
|
||
end | ||
end | ||
end |
107 changes: 107 additions & 0 deletions
107
lib/facebook_ads/ad_objects/server_side/original_event_data.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Copyright (c) 2017-present, Facebook, Inc. All rights reserved. | ||
# | ||
# You are hereby granted a non-exclusive, worldwide, royalty-free license to use, | ||
# copy, modify, and distribute this software in source code or binary form for use | ||
# in connection with the web services and APIs provided by Facebook. | ||
# | ||
# As with any software that integrates with the Facebook platform, your use of | ||
# this software is subject to the Facebook Platform Policy | ||
# [http://developers.facebook.com/policy/]. This copyright notice shall be | ||
# included in all copies or substantial portions of the software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
module FacebookAds | ||
module ServerSide | ||
|
||
# OriginalEventData contains original event info used for attribution passback event or generalized value optimization(GVO). | ||
class OriginalEventData | ||
|
||
# A Facebook pixel Standard Event or Custom Event name. | ||
# This is used with event_id to determine if events are identical. | ||
attr_accessor :event_name | ||
|
||
# A Unix timestamp in seconds indicating when the original event occurred. | ||
attr_accessor :event_time | ||
|
||
# @param [String] event_name | ||
# @param [int] event_time | ||
def initialize(event_name: nil, event_time: nil) | ||
unless event_name.nil? | ||
self.event_name = event_name | ||
end | ||
unless event_time.nil? | ||
self.event_time = event_time | ||
end | ||
end | ||
|
||
# build the object using the input hash | ||
# @param [Hash] attributes attributes in the form of hash | ||
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?(:'event_name') | ||
self.event_name = attributes[:'event_name'] | ||
end | ||
|
||
if attributes.has_key?(:'event_time') | ||
self.event_time = attributes[:'event_time'] | ||
end | ||
end | ||
|
||
# Checks equality by comparing each attribute. | ||
def ==(o) | ||
return true if self.equal?(o) | ||
self.class == o.class && | ||
event_name == o.event_name && | ||
event_time == o.event_time | ||
end | ||
|
||
# @see the `==` method | ||
def eql?(o) | ||
self == o | ||
end | ||
|
||
# Calculates hash code according to all attributes. | ||
# @return [Fixnum] Hash code | ||
def hash | ||
[ | ||
event_name, event_time, | ||
].hash | ||
end | ||
|
||
def to_s | ||
hash = {} | ||
unless event_name.nil? | ||
hash['event_name'] = event_name | ||
end | ||
unless event_time.nil? | ||
hash['event_time'] = event_time | ||
end | ||
hash.to_s | ||
end | ||
|
||
|
||
# Normalize input fields to server request format. | ||
def normalize | ||
hash = {} | ||
unless event_name.nil? | ||
hash['event_name'] = event_name | ||
end | ||
unless event_time.nil? | ||
hash['event_time'] = event_time | ||
end | ||
hash | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.