Skip to content

Commit

Permalink
Implement processParameters method
Browse files Browse the repository at this point in the history
Summary:
**In this diff**
- Implement the filter method of ProtectedModeManager.

Now the standardParameter list is hardcoded in FBSDK, will change to dynamically load in the future.

Reviewed By: KylinChang

Differential Revision: D46708165

fbshipit-source-id: 6984dec83ae578e87e8df2871c28ab93a2a989ba
  • Loading branch information
Shawn Zeng authored and facebook-github-bot committed Jun 15, 2023
1 parent 9cea64c commit e94f745
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 3 deletions.
4 changes: 3 additions & 1 deletion FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,9 @@ - (void) logEvent:(FBSDKAppEventName)eventName
// Filter out restrictive keys
parameters = [self.restrictiveDataFilterParameterProcessor processParameters:parameters
eventName:eventName];

// Filter out non-standard params
parameters = [self.protectedModeManager processParameters:parameters eventName:eventName];

NSMutableDictionary<FBSDKAppEventParameterName, id> *eventDictionary = [NSMutableDictionary dictionaryWithDictionary:parameters ?: @{}];
[FBSDKTypeUtility dictionary:eventDictionary setObject:eventName forKey:FBSDKAppEventParameterNameEventName];
if (!eventDictionary[FBSDKAppEventParameterNameLogTime]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,83 @@ import Foundation

final class ProtectedModeManager: _AppEventsParameterProcessing {
private var isEnabled = false
private let standardParameters: Set<String> = [
"_currency",
"_valueToSum",
"fb_availability",
"fb_body_style",
"fb_checkin_date",
"fb_checkout_date",
"fb_city",
"fb_condition_of_vehicle",
"fb_content_category",
"fb_content_ids",
"fb_content_name",
"fb_content_type",
"fb_contents",
"fb_country",
"fb_currency",
"fb_delivery_category",
"fb_departing_arrival_date",
"fb_departing_departure_date",
"fb_destination_airport",
"fb_destination_ids",
"fb_dma_code",
"fb_drivetrain",
"fb_exterior_color",
"fb_fuel_type",
"fb_hotel_score",
"fb_interior_color",
"fb_lease_end_date",
"fb_lease_start_date",
"fb_listing_type",
"fb_make",
"fb_mileage.unit",
"fb_mileage.value",
"fb_model",
"fb_neighborhood",
"fb_num_adults",
"fb_num_children",
"fb_num_infants",
"fb_num_items",
"fb_order_id",
"fb_origin_airport",
"fb_postal_code",
"fb_predicted_ltv",
"fb_preferred_baths_range",
"fb_preferred_beds_range",
"fb_preferred_neighborhoods",
"fb_preferred_num_stops",
"fb_preferred_price_range",
"fb_preferred_star_ratings",
"fb_price",
"fb_property_type",
"fb_region",
"fb_returning_arrival_date",
"fb_returning_departure_date",
"fb_search_string",
"fb_state_of_vehicle",
"fb_status",
"fb_suggested_destinations",
"fb_suggested_home_listings",
"fb_suggested_hotels",
"fb_suggested_jobs",
"fb_suggested_local_service_businesses",
"fb_suggested_location_based_items",
"fb_suggested_vehicles",
"fb_transmission",
"fb_travel_class",
"fb_travel_end",
"fb_travel_start",
"fb_trim",
"fb_user_bucket",
"fb_value",
"fb_vin",
"fb_year",
"lead_event_source",
"predicted_ltv",
"product_catalog_id",
]

func enable() {
isEnabled = true
Expand All @@ -19,7 +96,20 @@ final class ProtectedModeManager: _AppEventsParameterProcessing {
_ parameters: [AppEvents.ParameterName: Any]?,
eventName: AppEvents.Name
) -> [AppEvents.ParameterName: Any]? {
// stub
return parameters
guard isEnabled,
let parameters = parameters,
!parameters.isEmpty
else {
return parameters
}

var params = parameters
parameters.keys.forEach { appEventsParameterName in
if !standardParameters.contains(appEventsParameterName.rawValue) {
params.removeValue(forKey: appEventsParameterName)
}
}

return params
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,27 @@ final class AppEventsTests: XCTestCase {
)
}

func testLogEventProcessParametersWithProtectedModeManager() {
let parameters: [AppEvents.ParameterName: String] = [.init("key"): "value"]
appEvents.logEvent(
eventName,
valueToSum: NSNumber(value: purchaseAmount),
parameters: parameters,
isImplicitlyLogged: false,
accessToken: nil
)
XCTAssertEqual(
protectedModeManager.capturedEventName,
eventName,
"AppEvents instance should submit the event name to the protectedModeManager."
)
XCTAssertEqual(
protectedModeManager.capturedParameters as? [AppEvents.ParameterName: String],
parameters,
"AppEvents instance should submit the parameters to the protectedModeManager."
)
}

// MARK: - Test for log push notification

func testLogPushNotificationOpen() throws {
Expand Down

0 comments on commit e94f745

Please sign in to comment.