Here is the code I'm using. How can I test attributionDetails
from Apple so I can ensure my Search Ads Attribution API code is working properly? Apple provides little to no details (https://searchads.apple.com/help/measure-results/#attribution-api) on how developers can do some test dummy conversions for testing.
+ (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.
}
}];
}
}
There are 2 ways to test it:
Unit test: try OCMock to test it and return the dummy data that Apple documents in their documents
Test on devices (iOS 9 and above): run your code on the devices. You should be able to receive the dummy data from Apple. I could see the dummy data on development and test flight versions.
Note that you may need to use older APIs for iOS 8 and iOS 7 :
- determineAppInstallationAttributionWithCompletionHandler:
- lookupAdConversionDetails:
if your app supports older versions of iOS by checking whether the ADClient responds to the methods above. Also, attributionDetails contains a smaller dictionary with the key "Version3.1" so your code is not correct (as documented in the official 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”; }; }
You will need to get the innerDictionary first before looking up the iad-attribution value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With