这是我正在使用的代码。如何attributionDetails
从 Apple 进行测试,以确保我的 Search Ads Attribution API 代码正常工作?Apple 几乎没有提供关于开发人员如何进行一些测试虚拟转换以进行测试的详细信息 ( https://searchads.apple.com/help/measure-results/#attribution-api )。
+ (void)conversionTracking
{
if ([[ADClient sharedClient] respondsToSelector:@selector(requestAttributionDetailsWithBlock:)])
{
// iOS 10 call exists
[[ADClient sharedClient] requestAttributionDetailsWithBlock:^(NSDictionary *attributionDetails, NSError *error) {
if (error) {
NSLog(@"Request Search Ads attributes failed with error: %@", error.description);
if (error.code == ADClientErrorLimitAdTracking) {
NSLog(@"Limit Ad Tracking is enabled for this device.");
}
}
else {
NSLog(@"Search Ads attributes: %@", attributionDetails);
// Found details, track the purchase.
NSString *searchAdsCampaign = @"";
// Check value for "iad-attribution":
if ([attributionDetails valueForKey:@"iad-attribution"] != nil) {
// Check value:
if ([[attributionDetails valueForKey:@"iad-attribution"] boolValue]) {
// Get campaign name:
if ([attributionDetails valueForKey:@"iad-campaign-name"] != nil) {
NSString *campaignName = [attributionDetails valueForKey:@"iad-campaign-name"];
// Exclude Apple test data, where value is "CampaignName":
if ([campaignName isEqualToString:@"CampaignName"]) {
searchAdsCampaign = @"No Campaign";
}
else {
searchAdsCampaign = campaignName;
}
}
else {
// Key not found:
searchAdsCampaign = @"Error";
}
}
else {
// Value "false":
searchAdsCampaign = @"No Campaign";
}
}
else {
// Key not found:
searchAdsCampaign = @"Error";
}
// TRACK IT HERE. Pass up searchAdsCampaign for tracking to my server.
}
}];
}
}