Skip to content

Commit

Permalink
Sync ATE for app launch
Browse files Browse the repository at this point in the history
Summary: $title

Reviewed By: dreamolight

Differential Revision: D25953038

fbshipit-source-id: 934f619bf7aeccaebd5f8b7abf20cea0e506bd7e
  • Loading branch information
KylinChang authored and facebook-github-bot committed Jan 21, 2021
1 parent 0db7d7e commit 0403812
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 104 deletions.
115 changes: 57 additions & 58 deletions FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,7 @@ + (void)activateApp
// Fetch app settings and register for transaction notifications only if app supports implicit purchase
// events
FBSDKAppEvents *instance = [FBSDKAppEvents singleton];
[FBSDKAppEventsConfigurationManager loadAppEventsConfigurationWithBlock:^{
[instance publishInstall];
}];
[instance publishInstall];
[instance fetchServerConfiguration:NULL];

// Restore time spent data, indicating that we're being called from "activateApp", which will,
Expand Down Expand Up @@ -959,15 +957,15 @@ - (void)publishInstall
[FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors logEntry:@"Missing [FBSDKAppEvents appID] for [FBSDKAppEvents publishInstall:]"];
return;
}
if ([FBSDKAppEventsUtility shouldDropAppEvent]) {
return;
}
NSString *lastAttributionPingString = [NSString stringWithFormat:@"com.facebook.sdk:lastAttributionPing%@", appID];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:lastAttributionPingString]) {
return;
}
[self fetchServerConfiguration:^{
if ([FBSDKAppEventsUtility shouldDropAppEvent]) {
return;
}
NSMutableDictionary *params = [FBSDKAppEventsUtility activityParametersDictionaryForEvent:@"MOBILE_APP_INSTALL"
shouldAccessAdvertisingID:self->_serverConfiguration.isAdvertisingIDEnabled];
[self appendInstallTimestamp:params];
Expand Down Expand Up @@ -1075,63 +1073,65 @@ - (void)enableCodelessEvents
// app events can use a server configuration up to 24 hours old to minimize network traffic.
- (void)fetchServerConfiguration:(FBSDKCodeBlock)callback
{
[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:^(FBSDKServerConfiguration *serverConfiguration, NSError *error) {
self->_serverConfiguration = serverConfiguration;
[FBSDKAppEventsConfigurationManager loadAppEventsConfigurationWithBlock:^{
[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:^(FBSDKServerConfiguration *serverConfiguration, NSError *error) {
self->_serverConfiguration = serverConfiguration;

if (self->_serverConfiguration.implicitPurchaseLoggingEnabled && [FBSDKSettings isAutoLogAppEventsEnabled]) {
[FBSDKPaymentObserver startObservingTransactions];
} else {
[FBSDKPaymentObserver stopObservingTransactions];
}
[FBSDKFeatureManager checkFeature:FBSDKFeatureRestrictiveDataFiltering completionBlock:^(BOOL enabled) {
if (enabled) {
[FBSDKRestrictiveDataFilterManager enable];
}
}];
[FBSDKFeatureManager checkFeature:FBSDKFeatureEventDeactivation completionBlock:^(BOOL enabled) {
if (enabled) {
[FBSDKEventDeactivationManager enable];
if (self->_serverConfiguration.implicitPurchaseLoggingEnabled && [FBSDKSettings isAutoLogAppEventsEnabled]) {
[FBSDKPaymentObserver startObservingTransactions];
} else {
[FBSDKPaymentObserver stopObservingTransactions];
}
}];
if (@available(iOS 14.0, *)) {
[FBSDKFeatureManager checkFeature:FBSDKFeatureATELogging completionBlock:^(BOOL enabled) {
[FBSDKFeatureManager checkFeature:FBSDKFeatureRestrictiveDataFiltering completionBlock:^(BOOL enabled) {
if (enabled) {
[self publishATE];
[FBSDKRestrictiveDataFilterManager enable];
}
}];
}
#if !TARGET_OS_TV
[FBSDKFeatureManager checkFeature:FBSDKFeatureCodelessEvents completionBlock:^(BOOL enabled) {
if (enabled) {
[self enableCodelessEvents];
[FBSDKFeatureManager checkFeature:FBSDKFeatureEventDeactivation completionBlock:^(BOOL enabled) {
if (enabled) {
[FBSDKEventDeactivationManager enable];
}
}];
if (@available(iOS 14.0, *)) {
[FBSDKFeatureManager checkFeature:FBSDKFeatureATELogging completionBlock:^(BOOL enabled) {
if (enabled) {
[self publishATE];
}
}];
}
}];
[FBSDKFeatureManager checkFeature:FBSDKFeatureAAM completionBlock:^(BOOL enabled) {
if (enabled) {
[FBSDKMetadataIndexer enable];
#if !TARGET_OS_TV
[FBSDKFeatureManager checkFeature:FBSDKFeatureCodelessEvents completionBlock:^(BOOL enabled) {
if (enabled) {
[self enableCodelessEvents];
}
}];
[FBSDKFeatureManager checkFeature:FBSDKFeatureAAM completionBlock:^(BOOL enabled) {
if (enabled) {
[FBSDKMetadataIndexer enable];
}
}];
[FBSDKFeatureManager checkFeature:FBSDKFeaturePrivacyProtection completionBlock:^(BOOL enabled) {
if (enabled) {
[FBSDKModelManager enable];
}
}];
if (@available(iOS 11.3, *)) {
[FBSDKFeatureManager checkFeature:FBSDKFeatureSKAdNetwork completionBlock:^(BOOL SKAdNetworkEnabled) {
if (SKAdNetworkEnabled) {
[SKAdNetwork registerAppForAdNetworkAttribution];
[FBSDKFeatureManager checkFeature:FBSDKFeatureSKAdNetworkConversionValue completionBlock:^(BOOL SKAdNetworkConversionValueEnabled) {
if (SKAdNetworkConversionValueEnabled) {
[FBSDKSKAdNetworkReporter enable];
}
}];
}
}];
}
}];
[FBSDKFeatureManager checkFeature:FBSDKFeaturePrivacyProtection completionBlock:^(BOOL enabled) {
if (enabled) {
[FBSDKModelManager enable];
#endif
if (callback) {
callback();
}
}];
if (@available(iOS 11.3, *)) {
[FBSDKFeatureManager checkFeature:FBSDKFeatureSKAdNetwork completionBlock:^(BOOL SKAdNetworkEnabled) {
if (SKAdNetworkEnabled) {
[SKAdNetwork registerAppForAdNetworkAttribution];
[FBSDKFeatureManager checkFeature:FBSDKFeatureSKAdNetworkConversionValue completionBlock:^(BOOL SKAdNetworkConversionValueEnabled) {
if (SKAdNetworkConversionValueEnabled) {
[FBSDKSKAdNetworkReporter enable];
}
}];
}
}];
}
#endif
if (callback) {
callback();
}
}];
}

Expand Down Expand Up @@ -1318,13 +1318,12 @@ - (void)flushOnMainQueue:(FBSDKAppEventsState *)appEventsState
return;
}

if ([FBSDKAppEventsUtility shouldDropAppEvent]) {
return;
}

[FBSDKAppEventsUtility ensureOnMainThread:NSStringFromSelector(_cmd) className:NSStringFromClass([self class])];

[self fetchServerConfiguration:^(void) {
if ([FBSDKAppEventsUtility shouldDropAppEvent]) {
return;
}
NSString *receipt_data = appEventsState.extractReceiptData;
NSString *encodedEvents = [appEventsState JSONStringForEvents:self->_serverConfiguration.implicitLoggingEnabled];
if (!encodedEvents || appEventsState.events.count == 0) {
Expand Down
94 changes: 48 additions & 46 deletions FBSDKCoreKit/FBSDKCoreKit/AppLink/FBSDKAppLinkUtility.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,58 @@ + (void)fetchDeferredAppLink:(FBSDKURLBlock)handler
{
NSAssert([NSThread isMainThread], @"FBSDKAppLink fetchDeferredAppLink: must be invoked from main thread.");

if ([FBSDKAppEventsUtility shouldDropAppEvent]) {
if (handler) {
NSError *error = [[NSError alloc] initWithDomain:@"AdvertiserTrackingEnabled must be enabled" code:-1 userInfo:nil];
handler(nil, error);
[FBSDKAppEventsConfigurationManager loadAppEventsConfigurationWithBlock:^{
if ([FBSDKAppEventsUtility shouldDropAppEvent]) {
if (handler) {
NSError *error = [[NSError alloc] initWithDomain:@"AdvertiserTrackingEnabled must be enabled" code:-1 userInfo:nil];
handler(nil, error);
}
return;
}
return;
}

NSString *appID = [FBSDKSettings appID];

// Deferred app links are only currently used for engagement ads, thus we consider the app to be an advertising one.
// If this is considered for organic, non-ads scenarios, we'll need to retrieve the FBAppEventsUtility.shouldAccessAdvertisingID
// before we make this call.
NSMutableDictionary *deferredAppLinkParameters =
[FBSDKAppEventsUtility activityParametersDictionaryForEvent:FBSDKDeferredAppLinkEvent
shouldAccessAdvertisingID:YES];

FBSDKGraphRequest *deferredAppLinkRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:[NSString stringWithFormat:@"%@/activities", appID, nil]
parameters:deferredAppLinkParameters
tokenString:nil
version:nil
HTTPMethod:FBSDKHTTPMethodPOST];

[deferredAppLinkRequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
NSURL *applinkURL = nil;
if (!error) {
NSString *appLinkString = result[@"applink_url"];
if (appLinkString) {
applinkURL = [NSURL URLWithString:appLinkString];

NSString *createTimeUtc = result[@"click_time"];
if (createTimeUtc) {
// append/translate the create_time_utc so it can be used by clients
NSString *modifiedURLString = [applinkURL.absoluteString
stringByAppendingFormat:@"%@fb_click_time_utc=%@",
(applinkURL.query) ? @"&" : @"?",
createTimeUtc];
applinkURL = [NSURL URLWithString:modifiedURLString];
NSString *appID = [FBSDKSettings appID];

// Deferred app links are only currently used for engagement ads, thus we consider the app to be an advertising one.
// If this is considered for organic, non-ads scenarios, we'll need to retrieve the FBAppEventsUtility.shouldAccessAdvertisingID
// before we make this call.
NSMutableDictionary *deferredAppLinkParameters =
[FBSDKAppEventsUtility activityParametersDictionaryForEvent:FBSDKDeferredAppLinkEvent
shouldAccessAdvertisingID:YES];

FBSDKGraphRequest *deferredAppLinkRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:[NSString stringWithFormat:@"%@/activities", appID, nil]
parameters:deferredAppLinkParameters
tokenString:nil
version:nil
HTTPMethod:FBSDKHTTPMethodPOST];

[deferredAppLinkRequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
NSURL *applinkURL = nil;
if (!error) {
NSString *appLinkString = result[@"applink_url"];
if (appLinkString) {
applinkURL = [NSURL URLWithString:appLinkString];

NSString *createTimeUtc = result[@"click_time"];
if (createTimeUtc) {
// append/translate the create_time_utc so it can be used by clients
NSString *modifiedURLString = [applinkURL.absoluteString
stringByAppendingFormat:@"%@fb_click_time_utc=%@",
(applinkURL.query) ? @"&" : @"?",
createTimeUtc];
applinkURL = [NSURL URLWithString:modifiedURLString];
}
}
}
}

if (handler) {
dispatch_async(dispatch_get_main_queue(), ^{
handler(applinkURL, error);
});
}
}];

if (handler) {
dispatch_async(dispatch_get_main_queue(), ^{
handler(applinkURL, error);
});
}
}];
}];
}

+ (NSString *)appInvitePromotionCodeFromURL:(NSURL *)url
Expand Down

0 comments on commit 0403812

Please sign in to comment.