以下是我正在使用的代码。如何从Apple测试attributionDetails
,以便确保我的搜索广告归因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.
}
}];
}
}
答案 0 :(得分:1)
有两种测试方法:
单元测试:尝试使用OCMock对其进行测试并返回Apple文档在其documents
在设备上进行测试(iOS 9及更高版本):在设备上运行您的代码。您应该能够从Apple接收虚拟数据。我可以在开发和测试飞行版本上看到虚拟数据。
请注意,您可能需要为iOS 8和iOS 7使用较旧的API:
- determineAppInstallationAttributionWithCompletionHandler:
如果您的应用支持旧版iOS,请检查ADClient是否响应上述方法。此外, attributionDetails 包含一个较小的字典,其中包含密钥" Version3.1"所以你的代码不正确(如官方documentation中所述):
{ “Version3.1” = { “iad-attribution” = true; “iad-org-name” = “Light Right”; “iad-campaign-id” = 15292426; “iad-campaign-name” = “Light Bright Launch”; “iad-conversion-date” = “2016-06-14T17:18:07Z”; “iad-click-date” = “2016-06-14T17:17:00Z”; “iad-adgroup-id” = 15307675; “iad-adgroup-name” = “LightRight Launch Group”; “iad-keyword” = “light right”; }; }
在查找 iad-attribution 值之前,您需要先获取innerDictionary。
答案 1 :(得分:-1)
在设备上进行一些测试,我想你会发现这一行:
if ([[attributionDetails valueForKey:@"iad-attribution"] boolValue]
......实际应该是:
if ([[attributionDetails valueForKey:@"iad-attribution"] isEqualToString:@"true"]
我意识到这并没有真正回答如何测试它的问题。但也许您不知道如果您只是在真实设备上运行代码,您将获得一些虚拟数据作为响应。