Skip to content

Commit

Permalink
Add campaign_ids to Facebook Business SDK for Ruby
Browse files Browse the repository at this point in the history
Summary: Shopify is trying to send app events using Facebook Ruby SDK and it does not have the campaign_ids parameter. campaign_ids is listed as an optional field in [CAPI docs](https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/app-data/). This diff adds campaign_ids to the Ruby SDK.

Reviewed By: connorsmithmeta, stcheng

Differential Revision: D63080213

fbshipit-source-id: 61f2fca40888c05c9bcc3670eb6082058238dbb9
  • Loading branch information
Jianwei Tu authored and facebook-github-bot committed Sep 24, 2024
1 parent 6ce86fe commit 83c5310
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/facebook_ads/ad_objects/server_side/app_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class AppData
# Attribution token used for Windows 10.
attr_accessor :windows_attribution_id

# An encrypted string and non-user metadata appended to the outbound URL (for example, ad_destination_url) or deep link (for App Aggregated Event Manager) when a user clicked on a link from Facebook.
attr_accessor :campaign_ids

# @param [Boolean] application_tracking_enabled
# @param [Boolean] advertiser_tracking_enabled
# @param [Boolean] consider_views
Expand All @@ -60,6 +63,7 @@ class AppData
# @param [String] installer_package
# @param [Array<String>] url_schemes
# @param [String] windows_attribution_id
# @param [String] campaign_ids
def initialize(application_tracking_enabled: nil,
advertiser_tracking_enabled: nil,
consider_views: nil,
Expand All @@ -69,7 +73,8 @@ def initialize(application_tracking_enabled: nil,
install_referrer: nil,
installer_package: nil,
url_schemes: nil,
windows_attribution_id: nil)
windows_attribution_id: nil,
campaign_ids: nil)

unless application_tracking_enabled.nil?
self.application_tracking_enabled = application_tracking_enabled
Expand Down Expand Up @@ -101,6 +106,9 @@ def initialize(application_tracking_enabled: nil,
unless windows_attribution_id.nil?
self.windows_attribution_id = windows_attribution_id
end
unless campaign_ids.nil?
self.campaign_ids = campaign_ids
end
end

# build the object using the input hash
Expand Down Expand Up @@ -151,6 +159,10 @@ def build(attributes = {})
if attributes.has_key?(:'windows_attribution_id')
self.windows_attribution_id = attributes[:'windows_attribution_id']
end

if attributes.has_key?(:'campaign_ids')
self.campaign_ids = attributes[:'campaign_ids']
end
end

# Checks equality by comparing each attribute.
Expand All @@ -166,7 +178,8 @@ def ==(o)
install_referrer == o.install_referrer &&
installer_package == o.installer_package &&
url_schemes == o.url_schemes &&
windows_attribution_id == o.windows_attribution_id
windows_attribution_id == o.windows_attribution_id &&
campaign_ids == o.campaign_ids
end

# @see the `==` method
Expand All @@ -187,7 +200,8 @@ def hash
install_referrer,
installer_package,
url_schemes,
windows_attribution_id
windows_attribution_id,
campaign_ids
].hash
end

Expand Down Expand Up @@ -225,6 +239,9 @@ def to_s
unless windows_attribution_id.nil?
hash['windows_attribution_id'] = windows_attribution_id
end
unless campaign_ids.nil?
hash['campaign_ids'] = campaign_ids
end
hash.to_s
end

Expand Down Expand Up @@ -258,6 +275,9 @@ def normalize
unless windows_attribution_id.nil?
hash['windows_attribution_id'] = windows_attribution_id
end
unless campaign_ids.nil?
hash['campaign_ids'] = campaign_ids
end

unless extinfo.nil?
hash['extinfo'] = extinfo.normalize
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/facebook_ads/ad_objects/server_side/app_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
installer_package = 'b'
url_schemes = ['abc']
windows_attribution_id = '123'
campaign_ids = '678'
app_data = FacebookAds::ServerSide::AppData.new(
application_tracking_enabled: application_tracking_enabled,
advertiser_tracking_enabled: advertiser_tracking_enabled,
Expand All @@ -57,6 +58,7 @@
installer_package: installer_package,
url_schemes: url_schemes,
windows_attribution_id: windows_attribution_id,
campaign_ids: campaign_ids,
)

expect(app_data.normalize).to eq(
Expand All @@ -70,6 +72,7 @@
'installer_package' => installer_package,
'url_schemes' => url_schemes,
'windows_attribution_id' => windows_attribution_id,
'campaign_ids' => campaign_ids,
)
end

Expand Down Expand Up @@ -108,6 +111,7 @@
installer_package: 'b',
url_schemes: ['abc'],
windows_attribution_id: '123',
campaign_ids: '678',
)
app_data2 = FacebookAds::ServerSide::AppData.new(
application_tracking_enabled: true,
Expand Down Expand Up @@ -137,6 +141,7 @@
installer_package: 'b',
url_schemes: ['abc'],
windows_attribution_id: '123',
campaign_ids: '678'
)
expect(app_data1).to eq(app_data2)
expect(app_data1.hash).to eq(app_data2.hash)
Expand Down Expand Up @@ -171,6 +176,7 @@
installer_package: 'b',
url_schemes: ['abc'],
windows_attribution_id: '123',
campaign_ids: '678'
)
app_data2 = FacebookAds::ServerSide::AppData.new(
application_tracking_enabled: true,
Expand Down

0 comments on commit 83c5310

Please sign in to comment.