Skip to content

Commit

Permalink
feat(ads): CAID support
Browse files Browse the repository at this point in the history
  • Loading branch information
YoloMao committed Oct 17, 2024
1 parent 9b668ef commit 09d7966
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Example/Example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ - (void)SDK3rdStart {
}
NSLog(@"deepLinkCallback params = %@, processTime = %f", params, processTime);
};

NSString *caid = @"["
@"{\"caid\":\"507b36cb169864220bc22a8c522532fa\",\"version\":\"20220111\"},"
@"{\"caid\":\"e18a100398425c5026591525e844f7a7\",\"version\":\"20230330\"}"
@"]";
configuration.CAID = caid;
#endif

#if defined(SDKAPMMODULE)
Expand Down
3 changes: 3 additions & 0 deletions GrowingTrackerCore/GrowingTrackConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ @interface GrowingTrackConfiguration ()
@property (nonatomic, copy) NSString *deepLinkHost;
@property (nonatomic, copy) id deepLinkCallback;
@property (nonatomic, assign) BOOL readClipboardEnabled;
@property (nonatomic, copy) NSString *CAID;

// APM
@property (nonatomic, copy) NSObject *APMConfig;
Expand Down Expand Up @@ -72,6 +73,7 @@ - (instancetype)initWithAccountId:(NSString *)accountId {
_deepLinkHost = kGrowingDefaultDeepLinkHost;
_deepLinkCallback = nil;
_readClipboardEnabled = YES;
_CAID = nil;

// APM
_APMConfig = nil;
Expand Down Expand Up @@ -119,6 +121,7 @@ - (id)copyWithZone:(NSZone *)zone {
configuration->_deepLinkHost = [_deepLinkHost copy];
configuration->_deepLinkCallback = [_deepLinkCallback copy];
configuration->_readClipboardEnabled = _readClipboardEnabled;
configuration->_CAID = [_CAID copy];

// APM
configuration->_APMConfig = [_APMConfig copy];
Expand Down
19 changes: 15 additions & 4 deletions Modules/Advertising/GrowingAdvertising.m
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,21 @@ - (void)generateAppActivation {
if (trackConfiguration.ASAEnabled) {
[GrowingAsaFetcher startFetchWithTimeOut:GrowingAsaFetcherDefaultTimeOut];
}

NSString *CAID = trackConfiguration.CAID;
[self accessUserAgent:^(NSString *userAgent) {
if ([self SDKDoNotTrack]) {
return;
}

GrowingActivateBuilder *builder = GrowingActivateEvent.builder.setEventName(GrowingAdEventNameActivate);
NSMutableDictionary *attributes = @{}.mutableCopy;
if (userAgent.length > 0) {
builder.setAttributes(@{@"userAgent": userAgent.copy});
[attributes setObject:userAgent.copy forKey:@"userAgent"];
}
if (CAID.length > 0) {
[attributes setObject:CAID.copy forKey:@"CAID"];
}
builder.setAttributes(attributes.copy);
[[GrowingEventManager sharedInstance] postEventBuilder:builder];
[GrowingAdUtils setActivateWrote:YES];
}];
Expand All @@ -415,9 +420,15 @@ - (void)generateAppDefer:(NSDictionary *)dic {
if ([self SDKDoNotTrack]) {
return;
}


NSMutableDictionary *attributes = dic.mutableCopy;
GrowingTrackConfiguration *trackConfiguration = GrowingConfigurationManager.sharedInstance.trackConfiguration;
NSString *CAID = trackConfiguration.CAID;
if (CAID.length > 0) {
[attributes setObject:CAID.copy forKey:@"CAID"];
}
GrowingActivateBuilder *builder =
GrowingActivateEvent.builder.setEventName(GrowingAdEventNameDefer).setAttributes(dic);
GrowingActivateEvent.builder.setEventName(GrowingAdEventNameDefer).setAttributes(attributes.copy);
[[GrowingEventManager sharedInstance] postEventBuilder:builder];
[GrowingAdUtils setActivateWrote:YES];
[GrowingAdUtils setActivateDefer:YES];
Expand Down
13 changes: 13 additions & 0 deletions Modules/Advertising/Public/GrowingAdvertising.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ NS_SWIFT_NAME(Advertising)
@property (nonatomic, copy) NSString *deepLinkHost;
@property (nonatomic, copy) GrowingAdDeepLinkCallback deepLinkCallback;
@property (nonatomic, assign) BOOL readClipboardEnabled;
/// 若您通过广协接口获取了CAID,请将按照如下JSON格式转为字符串传入:
/// [
/// {
/// "version":"20220111",
/// "caid":"507b36cb169864220bc22a8c522532fa"
/// },
/// {
/// "version":"20230330",
/// "caid":"e18a100398425c5026591525e844f7a7"
/// }
/// ]
///
@property (nonatomic, copy) NSString *CAID;

@end

Expand Down

0 comments on commit 09d7966

Please sign in to comment.