5

这是我正在使用的代码。如何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.
            }
        }];
    }
}
4

2 回答 2

1

有2种方法可以测试它:

  1. 单元测试:尝试 OCMock 对其进行测试并返回 Apple 在其文档中记录的虚拟数据

  2. 在设备上测试(iOS 9 及更高版本):在设备上运行您的代码。您应该能够从 Apple 接收虚拟数据。我可以看到开发和试飞版本的虚拟数据。

请注意,您可能需要为 iOS 8 和 iOS 7 使用较旧的 API:

- 确定AppInstallationAttributionWithCompletionHandler:

- 查找广告转换详细信息:

如果您的应用程序支持旧版本的 iOS,请检查 ADClient 是否响应上述方法。此外,attributionDetails包含一个较小的字典,其键为“Version3.1”,因此您的代码不正确(如官方文档中所述):

{ “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。

于 2017-04-11T21:50:35.580 回答
-1

在设备上做一些测试,我想你会发现这条线:

if ([[attributionDetails valueForKey:@"iad-attribution"] boolValue]

...实际上应该是:

if ([[attributionDetails valueForKey:@"iad-attribution"] isEqualToString:@"true"]

我意识到这并不能真正回答如何测试它的问题。但也许你不知道,如果你只是在真实设备上运行你的代码,你会得到一些虚拟数据作为响应。

于 2016-11-10T01:50:17.097 回答