Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I test Apple's new Search Ads Attribution API?

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.
            }
        }];
    }
}
like image 905
Ethan Allen Avatar asked Nov 19 '22 14:11

Ethan Allen


1 Answers

There are 2 ways to test it:

  1. Unit test: try OCMock to test it and return the dummy data that Apple documents in their documents

  2. 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.

like image 73
adbitx Avatar answered May 30 '23 05:05

adbitx