Skip to content

Commit

Permalink
Add SKAN reporter dependency to AEM reporter
Browse files Browse the repository at this point in the history
Reviewed By: dreamolight

Differential Revision: D30716979

fbshipit-source-id: ce1b3a6f52d5e2081b63023090a3a0283e17c463
  • Loading branch information
KylinChang authored and facebook-github-bot committed Sep 3, 2021
1 parent 135c6ce commit 197b93d
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 3 deletions.
10 changes: 10 additions & 0 deletions FBAEMKit/FBAEMKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
474EFD6AB5988C7361FA0E15 /* FBAEMRule.h in Headers */ = {isa = PBXBuildFile; fileRef = F9ACAD4216D72E4122034CB9 /* FBAEMRule.h */; };
499A9AE9074800B75AAA76E5 /* FBAEMRequestBody.m in Sources */ = {isa = PBXBuildFile; fileRef = 69F89ACD1C21793D31565351 /* FBAEMRequestBody.m */; };
5630949F273EEA4D536894D9 /* SampleAEMData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4177A5533D7CFF825F97ECA0 /* SampleAEMData.swift */; };
565CE9AC0313BEDA111FA043 /* FBSKAdNetworkReporting.h in Headers */ = {isa = PBXBuildFile; fileRef = 153B4C403EFEC54B3E5A0203 /* FBSKAdNetworkReporting.h */; settings = {ATTRIBUTES = (Public, ); }; };
567D930E785504CA4A62B0ED /* FBAEMAdvertiserSingleEntryRule.h in Headers */ = {isa = PBXBuildFile; fileRef = EA8FABFB4D409A28FC534768 /* FBAEMAdvertiserSingleEntryRule.h */; };
599163559FEC9EF5DB917435 /* FBAEMNetworking.h in Headers */ = {isa = PBXBuildFile; fileRef = 8060F398EB7F033AD9F1D6AA /* FBAEMNetworking.h */; settings = {ATTRIBUTES = (Public, ); }; };
5A6B01E84A3CDA4D6B39BBA2 /* FBAEMInvocation.m in Sources */ = {isa = PBXBuildFile; fileRef = BF14F7D688B16F470687F043 /* FBAEMInvocation.m */; };
Expand Down Expand Up @@ -80,6 +81,7 @@
CB0B635973208B511A062FB5 /* FBAEMReporter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8554100C2E72F8997D18A1D1 /* FBAEMReporter.h */; settings = {ATTRIBUTES = (Public, ); }; };
CC7B4787404ACCEE7D6B6E8F /* FBAEMKit.h in Headers */ = {isa = PBXBuildFile; fileRef = BDDBCE1CDBD3488598FE265C /* FBAEMKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
CF815EBD130A652187ED6DA7 /* FBAEMRequestBody.m in Sources */ = {isa = PBXBuildFile; fileRef = 69F89ACD1C21793D31565351 /* FBAEMRequestBody.m */; };
D006673B24F89813D040D9E6 /* TestSKAdNetworkRepoter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B11CF6827A713779EB0D1E /* TestSKAdNetworkRepoter.swift */; };
D14F628136A6491B9258692D /* FBAEMNetworker.m in Sources */ = {isa = PBXBuildFile; fileRef = 50F60F57E8A966C73543C6E7 /* FBAEMNetworker.m */; };
D175879013592F781F627ED5 /* FBAEMEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = C2368B332ED43BBAF2493859 /* FBAEMEvent.m */; };
D5636656757EDC3E1CD3560D /* FBAEMAdvertiserRuleFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 931238348E95CD28C59333BD /* FBAEMAdvertiserRuleFactoryTests.swift */; };
Expand All @@ -91,6 +93,7 @@
E87F536334B42D42EC3452A2 /* FBAEMConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = CAAE2115CC5A03D37FABC343 /* FBAEMConfiguration.h */; };
F1104751E43FE9AB97E4AABA /* FBCoreKitBasicsImportForAEMKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 0954C8A4F08D670E5928AA17 /* FBCoreKitBasicsImportForAEMKit.h */; };
F317CC64B9EA550F74510E37 /* FBAEMAdvertiserRuleFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 308D372D24FA9EC87811E74C /* FBAEMAdvertiserRuleFactory.m */; };
F581E474473D84C5DA5D3B98 /* FBSKAdNetworkReporting.h in Headers */ = {isa = PBXBuildFile; fileRef = 153B4C403EFEC54B3E5A0203 /* FBSKAdNetworkReporting.h */; settings = {ATTRIBUTES = (Public, ); }; };
FB2ED4B8A9D7F7BEFA0891DA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55624583B4F08EB7CA742BFA /* UIKit.framework */; };
FC81960674090AD38CABBA41 /* FBAEMReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = F9CB68BCAEA3667ED30FF01A /* FBAEMReporter.m */; };
FC96D3627E3CC140C8B64E37 /* AEMConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCF97D130F84518CF735123 /* AEMConfigurationTests.swift */; };
Expand Down Expand Up @@ -172,11 +175,13 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
02B11CF6827A713779EB0D1E /* TestSKAdNetworkRepoter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSKAdNetworkRepoter.swift; sourceTree = "<group>"; };
0485B2A82D1087BAD40DEF28 /* TestAEMNetworker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestAEMNetworker.swift; sourceTree = "<group>"; };
06D636174F633A8977B80DC4 /* FBAEMEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBAEMEventTests.swift; sourceTree = "<group>"; };
08EA45F62800A6094DE6FE23 /* FBAEMKitTests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = FBAEMKitTests.xcconfig; sourceTree = "<group>"; };
0954C8A4F08D670E5928AA17 /* FBCoreKitBasicsImportForAEMKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBCoreKitBasicsImportForAEMKit.h; sourceTree = "<group>"; };
0B2DB862A2534E9BCF64D92F /* TestTools */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = TestTools; path = ../TestTools/TestTools.xcodeproj; sourceTree = "<group>"; };
153B4C403EFEC54B3E5A0203 /* FBSKAdNetworkReporting.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBSKAdNetworkReporting.h; sourceTree = "<group>"; };
200CAFDF7052329542187DCB /* FBSDKCoreKit_Basics */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = FBSDKCoreKit_Basics; path = ../FBSDKCoreKit_Basics/FBSDKCoreKit_Basics.xcodeproj; sourceTree = "<group>"; };
27B0E5D3B1EF8C9BA530BC3D /* FBAEMAdvertiserMultiEntryRule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBAEMAdvertiserMultiEntryRule.m; sourceTree = "<group>"; };
2D50412F133CE2A6A7D5150D /* SampleAEMInvocations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleAEMInvocations.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -296,6 +301,7 @@
7BE582199B8FBA1789FEC3E0 /* SampleAEMSingleEntryRules.swift */,
0485B2A82D1087BAD40DEF28 /* TestAEMNetworker.swift */,
8D1A8648B7AF86852325E167 /* TestInvocation.swift */,
02B11CF6827A713779EB0D1E /* TestSKAdNetworkRepoter.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -408,6 +414,7 @@
BDDBCE1CDBD3488598FE265C /* FBAEMKit.h */,
8060F398EB7F033AD9F1D6AA /* FBAEMNetworking.h */,
8554100C2E72F8997D18A1D1 /* FBAEMReporter.h */,
153B4C403EFEC54B3E5A0203 /* FBSKAdNetworkReporting.h */,
);
name = include;
path = ../Sources/FBAEMKit/include;
Expand Down Expand Up @@ -437,6 +444,7 @@
5B97E50781C011C42447373D /* FBAEMRequestBody.h in Headers */,
191858C71EF3965CC6068391 /* FBAEMRule.h in Headers */,
F1104751E43FE9AB97E4AABA /* FBCoreKitBasicsImportForAEMKit.h in Headers */,
F581E474473D84C5DA5D3B98 /* FBSKAdNetworkReporting.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -461,6 +469,7 @@
A04003FA9F804ECE55FEBDBD /* FBAEMRequestBody.h in Headers */,
474EFD6AB5988C7361FA0E15 /* FBAEMRule.h in Headers */,
B3CD5E0EB8287EF16619F04D /* FBCoreKitBasicsImportForAEMKit.h in Headers */,
565CE9AC0313BEDA111FA043 /* FBSKAdNetworkReporting.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -699,6 +708,7 @@
7C15398E0B92F0A99548AA17 /* SampleAEMSingleEntryRules.swift in Sources */,
C31C49F965C147E171E9F7AF /* TestAEMNetworker.swift in Sources */,
92A75FC874F8470A8B25D944 /* TestInvocation.swift in Sources */,
D006673B24F89813D040D9E6 /* TestSKAdNetworkRepoter.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 2 additions & 0 deletions FBAEMKit/FBAEMKitTests/FBAEM+Testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (class, nonatomic) NSMutableArray<FBAEMInvocation *> *invocations;
@property (class, nonatomic) NSMutableArray<FBAEMReporterBlock> *completionBlocks;
@property (class, nonatomic) NSString *reportFilePath;
@property (class, nonatomic) id<FBAEMNetworking> networker;
@property (class, nonatomic) id<FBSKAdNetworkReporting> reporter;

+ (void)enable;

Expand Down
16 changes: 15 additions & 1 deletion FBAEMKit/FBAEMKitTests/FBAEMReporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FBAEMReporterTests: XCTestCase {
}

let networker = TestAEMNetworker()
let reporter = TestSKAdNetworkReporter()
let date = Calendar.current.date(
byAdding: .day,
value: -2,
Expand All @@ -67,7 +68,7 @@ class FBAEMReporterTests: XCTestCase {
super.setUp()

removeReportFile()
AEMReporter.configure(withNetworker: networker, appID: "123")
AEMReporter.configure(withNetworker: networker, appID: "123", reporter: reporter)
// Actual queue doesn't matter as long as it's not the same as the designated queue name in the class
AEMReporter.queue = DispatchQueue(label: name, qos: .background)
AEMReporter.isEnabled = true
Expand All @@ -89,6 +90,19 @@ class FBAEMReporterTests: XCTestCase {
XCTAssertTrue(AEMReporter.isEnabled, "AEM Report should be enabled")
}

func testConfigure() {
XCTAssertEqual(
networker,
AEMReporter.networker as? TestAEMNetworker,
"Should configure with the expected AEM networker"
)
XCTAssertEqual(
reporter,
AEMReporter.reporter as? TestSKAdNetworkReporter,
"Should configure with the expected SKAdNetwork reporter"
)
}

func testParseURL() {
var url: URL?
XCTAssertNil(AEMReporter.parseURL(url))
Expand Down
31 changes: 31 additions & 0 deletions FBAEMKit/FBAEMKitTests/Helpers/TestSKAdNetworkRepoter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2014-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 Developer Principles and Policies
// [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.

public class TestSKAdNetworkReporter: NSObject, SKAdNetworkReporting {

public var cutOff: Bool = false
public var reportingEvents: Set<String> = []

public func shouldCutoff() -> Bool {
cutOff
}

public func isReportingEvent(_ event: String) -> Bool {
reportingEvents.contains(event)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@

#import <Foundation/Foundation.h>

#if defined FBSDKCOCOAPODS || defined BUCK
#import "FBSDKCoreKitAEMImport.h"
#else
#import "../../../Internal/FBSDKCoreKitAEMImport.h"
#endif

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_NAME(SKAdNetworkReporter)
@interface FBSDKSKAdNetworkReporter : NSObject
@interface FBSDKSKAdNetworkReporter : NSObject <FBSKAdNetworkReporting>

- (void)enable;

Expand Down
4 changes: 3 additions & 1 deletion FBSDKCoreKit/FBSDKCoreKit/FBSDKApplicationDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,9 @@ - (void)configureDependencies
conversionValueUpdatable:SKAdNetwork.class];
}
if (@available(iOS 14.0, *)) {
[FBAEMReporter configureWithNetworker:[FBSDKAEMNetworker new] appID:[FBSDKSettings appID]];
[FBAEMReporter configureWithNetworker:[FBSDKAEMNetworker new]
appID:[FBSDKSettings appID]
reporter:self.skAdNetworkReporter];
}
[FBSDKProfile configureWithStore:store
accessTokenProvider:FBSDKAccessToken.class
Expand Down
1 change: 1 addition & 0 deletions FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKCoreKitAEMImport.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#else
#import <FBAEMKit/FBAEMNetworking.h>
#import <FBAEMKit/FBAEMReporter.h>
#import <FBAEMKit/FBSKAdNetworkReporting.h>
#endif

#endif
14 changes: 14 additions & 0 deletions Sources/FBAEMKit/FBAEMReporter.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
static NSDate *g_configRefreshTimestamp;
static NSMutableArray<FBAEMReporterBlock> *g_completionBlocks;
static _Nullable id<FBAEMNetworking> _networker = nil;
static _Nullable id<FBSKAdNetworkReporting> _reporter = nil;
static NSString *_appId;

@implementation FBAEMReporter
Expand All @@ -70,10 +71,18 @@ @implementation FBAEMReporter

+ (void)configureWithNetworker:(nullable id<FBAEMNetworking>)networker
appID:(NSString *)appID
{
[self configureWithNetworker:networker appID:appID reporter:nil];
}

+ (void)configureWithNetworker:(nullable id<FBAEMNetworking>)networker
appID:(NSString *)appID
reporter:(nullable id<FBSKAdNetworkReporting>)reporter
{
if (self == [FBAEMReporter class]) {
_networker = networker;
_appId = appID;
_reporter = reporter;
}
}

Expand All @@ -82,6 +91,11 @@ + (void)configureWithNetworker:(nullable id<FBAEMNetworking>)networker
return _networker;
}

+ (id<FBSKAdNetworkReporting>)reporter
{
return _reporter;
}

+ (void)enable
{
if (@available(iOS 14.0, *)) {
Expand Down
1 change: 1 addition & 0 deletions Sources/FBAEMKit/include/FBAEMKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@

#import "FBAEMNetworking.h"
#import "FBAEMReporter.h"
#import "FBSKAdNetworkReporting.h"

#endif
18 changes: 18 additions & 0 deletions Sources/FBAEMKit/include/FBAEMReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#import <Foundation/Foundation.h>
#import "FBAEMNetworking.h"
#import "FBSKAdNetworkReporting.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -42,6 +43,23 @@ NS_SWIFT_NAME(AEMReporter)
+ (void)configureWithNetworker:(nullable id<FBAEMNetworking>)networker
appID:(NSString *)appID;

/**
Configure networker used for calling Facebook AEM Graph API endpoint
and Facebook App ID
This function should be called in application(_:open:options:) from ApplicationDelegate
and BEFORE [FBAEMReporter enable] function. We will use SKAdNetwork reporter to prevent
double counting.
@param networker An optional networker conforms to FBAEMNetworking which handles Graph API request
@param appID The Facebook app ID
@param reporter The SKAdNetwork repoter
*/
+ (void)configureWithNetworker:(nullable id<FBAEMNetworking>)networker
appID:(NSString *)appID
reporter:(nullable id<FBSKAdNetworkReporting>)reporter;

/**
Enable AEM reporting
Expand Down
38 changes: 38 additions & 0 deletions Sources/FBAEMKit/include/FBSKAdNetworkReporting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2014-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 Developer Principles and Policies
// [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.

#import "TargetConditionals.h"

#if !TARGET_OS_TV

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_NAME(SKAdNetworkReporting)
@protocol FBSKAdNetworkReporting

- (BOOL)shouldCutoff;

- (BOOL)isReportingEvent:(NSString *)event;

@end

NS_ASSUME_NONNULL_END

#endif

0 comments on commit 197b93d

Please sign in to comment.