Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register method update #317

Merged
merged 7 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class AdViewerViewController: FormViewController {
Criteo.resetSharedCriteo()
let criteo = Criteo.shared()
criteo.networkManagerDelegate = LogManager.sharedInstance()
criteo.registerPublisherId(publisherId, with: adUnits)
criteo.registerPublisherId(publisherId, withStoreId: "testStoreid", with: adUnits)
return criteo
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ - (void)loadBannerForAdUnit:(CRBannerAdUnit *)adUnit
mediationParams:(CRGoogleMediationParameters *)params
childDirectedTreatment:(NSNumber *)childDirectedTreatment {
/// Set the publicher id to
[Criteo.sharedCriteo registerCriteoPublisherId:params.publisherId withAdUnits:@[ adUnit ]];
[Criteo.sharedCriteo registerCriteoPublisherId:params.publisherId
withStoreId:params.storeId
withAdUnits:@[ adUnit ]];
/// Set child directed treatment flag to Criteo SDK.
[Criteo.sharedCriteo setChildDirectedTreatment:childDirectedTreatment];
if (self.bannerView == nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ NS_ASSUME_NONNULL_BEGIN
@interface CRGoogleMediationParameters : NSObject

- (instancetype)init NS_UNAVAILABLE;
- (id)initWithPublisherId:(NSString *)publisherId adUnitId:(NSString *)adUnitId;
- (id)initWithPublisherId:(NSString *)publisherId
storeId:(NSString *)storeId
adUnitId:(NSString *)adUnitId;
+ (nullable CRGoogleMediationParameters *)parametersFromJSONString:(NSString *)jsonString
error:(NSError **)outError;

@property(copy, readonly) NSString *publisherId;
@property(copy, readonly) NSString *adUnitId;
@property(copy, readonly) NSString *storeId;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

static NSString *const criteoGoogleMediationPublisherIdKey = @"cpId";
static NSString *const criteoGoogleMediationAdUnitIdKey = @"adUnitId";
static NSString *const criteoGoogleMediationStoreIdKey = @"storeId";

static void setJSONParsingError(NSError **error) {
if (error != nil) {
Expand All @@ -42,13 +43,16 @@ static void setJSONParsingError(NSError **error) {

@implementation CRGoogleMediationParameters

- (id)initWithPublisherId:(NSString *)publisherId adUnitId:(NSString *)adUnitId {
- (id)initWithPublisherId:(NSString *)publisherId
storeId:(NSString *)storeId
adUnitId:(NSString *)adUnitId {
self = [super init];
if (self == nil) {
return nil;
}
_publisherId = [NSString stringWithString:publisherId];
_adUnitId = [NSString stringWithString:adUnitId];
_storeId = [NSString stringWithString:storeId];
return self;
}

Expand All @@ -70,13 +74,16 @@ + (nullable CRGoogleMediationParameters *)parametersFromJSONString:(NSString *)j
}
NSString *pubId = nonEmptyStringFromObj(jsonDict[criteoGoogleMediationPublisherIdKey]);
NSString *adId = nonEmptyStringFromObj(jsonDict[criteoGoogleMediationAdUnitIdKey]);
NSString *storeId = nonEmptyStringFromObj(jsonDict[criteoGoogleMediationStoreIdKey]);
if (pubId == nil || adId == nil) {
setJSONParsingError(error);
return nil;
}
if (error != nil) {
*error = nil;
}
return [[CRGoogleMediationParameters alloc] initWithPublisherId:pubId adUnitId:adId];
return [[CRGoogleMediationParameters alloc] initWithPublisherId:pubId
storeId:storeId
adUnitId:adId];
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ @implementation CRInterstitialCustomEvent
- (void)loadInterstitialForAdUnit:(CRInterstitialAdUnit *)adUnit
adConfiguration:(CRGoogleMediationParameters *)params
childDirectedTreatment:(NSNumber *)childDirectedTreatment {
[Criteo.sharedCriteo registerCriteoPublisherId:params.publisherId withAdUnits:@[ adUnit ]];
[Criteo.sharedCriteo registerCriteoPublisherId:params.publisherId
withStoreId:params.storeId
withAdUnits:@[ adUnit ]];
/// Set child directed treatment flag to Criteo SDK.
[Criteo.sharedCriteo setChildDirectedTreatment:childDirectedTreatment];
if (!self.interstitial) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ - (void)loadBannerForAdUnit:(CRBannerAdUnit *)adUnit
mediationParams:(CRGoogleMediationParameters *)params
childDirectedTreatment:(NSNumber *)childDirectedTreatment {
/// Set the publicher id to
[Criteo.sharedCriteo registerCriteoPublisherId:params.publisherId withAdUnits:@[ adUnit ]];
[Criteo.sharedCriteo registerCriteoPublisherId:params.publisherId
withStoreId:params.storeId
withAdUnits:@[ adUnit ]];
/// Set child directed treatment flag to Criteo SDK.
[Criteo.sharedCriteo setChildDirectedTreatment:childDirectedTreatment];
if (self.bannerView == nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ NS_ASSUME_NONNULL_BEGIN
@interface CRGoogleMediationParameters : NSObject

- (instancetype)init NS_UNAVAILABLE;
- (id)initWithPublisherId:(NSString *)publisherId adUnitId:(NSString *)adUnitId;
- (id)initWithPublisherId:(NSString *)publisherId
storeId:(NSString *)storeId
adUnitId:(NSString *)adUnitId;
+ (nullable CRGoogleMediationParameters *)parametersFromJSONString:(NSString *)jsonString
error:(NSError **)outError;

@property(copy, readonly) NSString *publisherId;
@property(copy, readonly) NSString *adUnitId;
@property(copy, readonly) NSString *storeId;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

static NSString *const criteoGoogleMediationPublisherIdKey = @"cpId";
static NSString *const criteoGoogleMediationAdUnitIdKey = @"adUnitId";
static NSString *const criteoGoogleMediationStoreIdKey = @"storeId";

static void setJSONParsingError(NSError **error) {
if (error != nil) {
Expand All @@ -42,13 +43,16 @@ static void setJSONParsingError(NSError **error) {

@implementation CRGoogleMediationParameters

- (id)initWithPublisherId:(NSString *)publisherId adUnitId:(NSString *)adUnitId {
- (id)initWithPublisherId:(NSString *)publisherId
storeId:(NSString *)storeId
adUnitId:(NSString *)adUnitId {
self = [super init];
if (self == nil) {
return nil;
}
_publisherId = [NSString stringWithString:publisherId];
_adUnitId = [NSString stringWithString:adUnitId];
_storeId = [NSString stringWithString:storeId];
return self;
}

Expand All @@ -70,13 +74,16 @@ + (nullable CRGoogleMediationParameters *)parametersFromJSONString:(NSString *)j
}
NSString *pubId = nonEmptyStringFromObj(jsonDict[criteoGoogleMediationPublisherIdKey]);
NSString *adId = nonEmptyStringFromObj(jsonDict[criteoGoogleMediationAdUnitIdKey]);
NSString *storeId = nonEmptyStringFromObj(jsonDict[criteoGoogleMediationStoreIdKey]);
if (pubId == nil || adId == nil) {
setJSONParsingError(error);
return nil;
}
if (error != nil) {
*error = nil;
}
return [[CRGoogleMediationParameters alloc] initWithPublisherId:pubId adUnitId:adId];
return [[CRGoogleMediationParameters alloc] initWithPublisherId:pubId
storeId:storeId
adUnitId:adId];
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ @implementation CRInterstitialCustomEvent
- (void)loadInterstitialForAdUnit:(CRInterstitialAdUnit *)adUnit
adConfiguration:(CRGoogleMediationParameters *)params
childDirectedTreatment:(NSNumber *)childDirectedTreatment {
[Criteo.sharedCriteo registerCriteoPublisherId:params.publisherId withAdUnits:@[ adUnit ]];
[Criteo.sharedCriteo registerCriteoPublisherId:params.publisherId
withStoreId:params.storeId
withAdUnits:@[ adUnit ]];
/// Set child directed treatment flag to Criteo SDK.
[Criteo.sharedCriteo setChildDirectedTreatment:childDirectedTreatment];
if (!self.interstitial) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ - (instancetype)initWithBanner:(CRBannerView *)ad {

@end

#define SERVER_PARAMETER @"{\"cpId\":\"testCpId\",\"adUnitId\":\"testAdUnitId\"}"
#define SERVER_PARAMETER \
@"{\"cpId\":\"testCpId\",\"adUnitId\":\"testAdUnitId\",\"storeId\":\"testStoreId\"}"

@implementation CRBannerCustomEventTests

Expand All @@ -69,7 +70,9 @@ - (void)testRequestBannerAdSuccess {

id mockCriteo = OCMClassMock([Criteo class]);
OCMStub([mockCriteo sharedCriteo]).andReturn(mockCriteo);
OCMStub([mockCriteo registerCriteoPublisherId:@"testCpId" withAdUnits:@[ bannerAdUnit ]]);
OCMStub([mockCriteo registerCriteoPublisherId:@"testCpId"
withStoreId:@"testStoreId"
withAdUnits:@[ bannerAdUnit ]]);
OCMStub([mockCriteo setChildDirectedTreatment:mockChildDirectedTreatment]);

[customEvent loadBannerForAdUnit:bannerAdUnit
Expand All @@ -78,7 +81,9 @@ - (void)testRequestBannerAdSuccess {

OCMVerify([mockCRBannerView loadAd]);
OCMVerify([mockCRBannerView setDelegate:customEvent]);
OCMVerify([mockCriteo registerCriteoPublisherId:@"testCpId" withAdUnits:@[ bannerAdUnit ]]);
OCMVerify([mockCriteo registerCriteoPublisherId:@"testCpId"
withStoreId:@"testStoreId"
withAdUnits:@[ bannerAdUnit ]]);
OCMVerify([mockCriteo setChildDirectedTreatment:mockChildDirectedTreatment]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ - (void)testGoogleMediationParametersNormal {
NSError *error;
CRGoogleMediationParameters *gmp = [CRGoogleMediationParameters
parametersFromJSONString:
@"{\"cpId\":\"B-056946\", \"adUnitId\": \"/140800857/Endeavour_320x50\"}"
@"{\"cpId\":\"B-056946\", \"adUnitId\": \"/140800857/Endeavour_320x50\", \"storeId\": \"B-056946\"}"
error:&error];
XCTAssertNotNil(gmp);
XCTAssertEqualObjects(gmp.publisherId, @"B-056946");
XCTAssertEqualObjects(gmp.adUnitId, @"/140800857/Endeavour_320x50");
XCTAssertEqualObjects(gmp.storeId, @"B-056946");
}

// Normal case - check that the error is set to nil
- (void)testGoogleMediationParametersErrorSetToNil {
NSError *error = [NSError new];
CRGoogleMediationParameters *gmp = [CRGoogleMediationParameters
parametersFromJSONString:
@"{\"cpId\":\"B-056946\", \"adUnitId\": \"/140800857/Endeavour_320x50\"}"
@"{\"cpId\":\"B-056946\", \"adUnitId\": \"/140800857/Endeavour_320x50\", \"storeId\": \"B-056946\"}"
error:&error];
XCTAssertNil(error);
}
Expand All @@ -50,11 +51,12 @@ - (void)testGoogleMediationParametersErrorSetToNil {
- (void)testGoogleMediationParametersNilError {
CRGoogleMediationParameters *gmp = [CRGoogleMediationParameters
parametersFromJSONString:
@"{\"cpId\":\"B-056946\", \"adUnitId\": \"/140800857/Endeavour_320x50\"}"
@"{\"cpId\":\"B-056946\", \"adUnitId\": \"/140800857/Endeavour_320x50\", \"storeId\": \"B-056946\"}"
error:nil];
XCTAssertNotNil(gmp);
XCTAssertEqualObjects(gmp.publisherId, @"B-056946");
XCTAssertEqualObjects(gmp.adUnitId, @"/140800857/Endeavour_320x50");
XCTAssertEqualObjects(gmp.storeId, @"B-056946");
}

// Nil input string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ - (instancetype)initWithInterstitial:(CRInterstitial *)interstitial {

@end

#define SERVER_PARAMETER @"{\"cpId\":\"testCpId\",\"adUnitId\":\"testAdUnitId\"}"
#define SERVER_PARAMETER \
@"{\"cpId\":\"testCpId\",\"adUnitId\":\"testAdUnitId\",\"storeId\":\"testStoreId\"}"

@implementation CRInterstitialCustomEventTests

Expand All @@ -76,7 +77,9 @@ - (void)testLoadAndPresentFromRootViewController {

id mockCriteo = OCMStrictClassMock([Criteo class]);
OCMStub([mockCriteo sharedCriteo]).andReturn(mockCriteo);
OCMStub([mockCriteo registerCriteoPublisherId:@"testCpId" withAdUnits:@[ interstitialAdUnit ]]);
OCMStub([mockCriteo registerCriteoPublisherId:@"testCpId"
withStoreId:@"testStoreId"
withAdUnits:@[ interstitialAdUnit ]]);
OCMStub([mockCriteo setChildDirectedTreatment:mockChildDirectedTreatment]);

[customEvent loadInterstitialForAdUnit:interstitialAdUnit
Expand All @@ -87,7 +90,9 @@ - (void)testLoadAndPresentFromRootViewController {
OCMVerify([mockCRInterstitial loadAd]);
OCMVerify([mockCRInterstitial setDelegate:customEvent]);
OCMVerify([mockCRInterstitial presentFromRootViewController:realVC]);
OCMVerify([mockCriteo registerCriteoPublisherId:@"testCpId" withAdUnits:@[ interstitialAdUnit ]]);
OCMVerify([mockCriteo registerCriteoPublisherId:@"testCpId"
withStoreId:@"testStoreId"
withAdUnits:@[ interstitialAdUnit ]]);
OCMVerify([mockCriteo setChildDirectedTreatment:mockChildDirectedTreatment]);
}

Expand Down
6 changes: 5 additions & 1 deletion CriteoPublisherSdk/Sources/Configuration/CR_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ FOUNDATION_EXTERN NSString *const CR_ConfigConfigurationUrl;
@property(copy, nonatomic) NSString *adTagUrlMode;
@property(copy, nonatomic) NSString *viewportWidthMacro;
@property(copy, nonatomic) NSString *displayURLMacro;

@property(copy, nonatomic, nullable) NSString *storeId;
#pragma mark CSM

@property(assign, nonatomic, getter=isCsmEnabled) BOOL csmEnabled;
Expand Down Expand Up @@ -77,11 +77,15 @@ FOUNDATION_EXTERN NSString *const CR_ConfigConfigurationUrl;
#pragma mark - Lifecycle

- (instancetype)initWithCriteoPublisherId:(nullable NSString *)criteoPublisherId
storeId:(nullable NSString *)storeId
cdbUrl:(NSString *)cdbUrl
appEventsUrl:(NSString *)appEventsUrl
configUrl:(NSString *)configUrl
userDefaults:(NSUserDefaults *)userDefaults NS_DESIGNATED_INITIALIZER;

- (instancetype)initWithCriteoPublisherId:(nullable NSString *)criteoPublisherId
storeId:(nullable NSString *)storeId;

- (instancetype)initWithCriteoPublisherId:(nullable NSString *)criteoPublisherId;

- (instancetype)initWithUserDefaults:(NSUserDefaults *)userDefaults;
Expand Down
14 changes: 14 additions & 0 deletions CriteoPublisherSdk/Sources/Configuration/CR_Config.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ @interface CR_Config ()
@implementation CR_Config

- (instancetype)initWithCriteoPublisherId:(nullable NSString *)criteoPublisherId
storeId:(nullable NSString *)storeId
cdbUrl:(NSString *)cdbUrl
appEventsUrl:(NSString *)appEventsUrl
configUrl:(NSString *)configUrl
Expand Down Expand Up @@ -73,12 +74,24 @@ - (instancetype)initWithCriteoPublisherId:(nullable NSString *)criteoPublisherId
_remoteLogLevel = [userDefaults cr_valueForRemoteLogLevel];
_userDefaults = userDefaults;
_mraidEnabled = [userDefaults cr_valueForMRAID];
_storeId = storeId;
}
return self;
}

- (instancetype)initWithCriteoPublisherId:(nullable NSString *)criteoPublisherId {
return [self initWithCriteoPublisherId:criteoPublisherId
storeId:nil
cdbUrl:CR_ConfigCdbUrl
appEventsUrl:CR_ConfigAppEventsUrl
configUrl:CR_ConfigConfigurationUrl
userDefaults:[NSUserDefaults standardUserDefaults]];
}

- (instancetype)initWithCriteoPublisherId:(nullable NSString *)criteoPublisherId
storeId:(nullable NSString *)storeId {
return [self initWithCriteoPublisherId:criteoPublisherId
storeId:storeId
cdbUrl:CR_ConfigCdbUrl
appEventsUrl:CR_ConfigAppEventsUrl
configUrl:CR_ConfigConfigurationUrl
Expand All @@ -91,6 +104,7 @@ - (instancetype)init {

- (instancetype)initWithUserDefaults:(NSUserDefaults *)userDefaults {
return [self initWithCriteoPublisherId:nil
storeId:nil
cdbUrl:CR_ConfigCdbUrl
appEventsUrl:CR_ConfigAppEventsUrl
configUrl:CR_ConfigConfigurationUrl
Expand Down
10 changes: 9 additions & 1 deletion CriteoPublisherSdk/Sources/Criteo.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,22 @@ + (void)resetSharedCriteo {
}

- (void)registerCriteoPublisherId:(NSString *)criteoPublisherId
withStoreId:(NSString *)storeId
withAdUnits:(NSArray<CRAdUnit *> *)adUnits {
if (criteoPublisherId == nil || criteoPublisherId.length == 0) {
CRLogError(@"Registration", @"Invalid Criteo publisher ID: \"%@\"", criteoPublisherId);
}
if (storeId == nil || storeId.length == 0) {
CRLogError(@"Registration", @"Invalid store ID: \"%@\"", storeId);
}
@synchronized(self) {
if (!self.isRegistered) {
self.registered = true;
@try {
[self.dependencyProvider.threadManager dispatchAsyncOnGlobalQueue:^{
[self _registerCriteoPublisherId:criteoPublisherId withAdUnits:adUnits];
[self _registerCriteoPublisherId:criteoPublisherId
withStoreId:storeId
withAdUnits:adUnits];
CRLogInfo(@"Registration",
@"Criteo SDK version %@ is registered with Publisher ID %@ and %d ad units: %@",
CRITEO_PUBLISHER_SDK_VERSION, criteoPublisherId, adUnits.count, adUnits);
Expand Down Expand Up @@ -187,8 +193,10 @@ - (instancetype)initWithDependencyProvider:(CR_DependencyProvider *)dependencyPr
}

- (void)_registerCriteoPublisherId:(NSString *)criteoPublisherId
withStoreId:(NSString *)storeId
withAdUnits:(NSArray<CRAdUnit *> *)adUnits {
self.config.criteoPublisherId = criteoPublisherId;
self.config.storeId = storeId;
[self.appEvents registerForIosEvents];
[self.appEvents sendLaunchEvent];
[self.configManager refreshConfig:self.config];
Expand Down
1 change: 1 addition & 0 deletions CriteoPublisherSdk/Sources/Network/CR_ApiQueryKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(class, nonatomic, readonly) NSString *wrapperVersion;
@property(class, nonatomic, readonly) NSString *zoneId;
@property(class, nonatomic, readonly) NSString *regs;
@property(class, nonatomic, readonly) NSString *storeId;

/// Used to map childDirectedTreatment property.
@property(class, nonatomic, readonly) NSString *coppa;
Expand Down
3 changes: 3 additions & 0 deletions CriteoPublisherSdk/Sources/Network/CR_ApiQueryKeys.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,8 @@ + (NSString *)banner {
+ (NSString *)api {
return @"api";
}
+ (NSString *)storeId {
return @"storeId";
}

@end
Loading
Loading