5

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.
            }
        }];
    }
}
Ethan Allen
  • 14,425
  • 24
  • 101
  • 194

2 Answers2

1

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.

adbitx
  • 2,019
  • 8
  • 13
  • what params should be passed in URL if I want to use my custom campaign to get above details? currently, I am passing these dummy params publisher_id=6136&site_id=1863&campaign_id=234595&pt=4567&ct=9821 I don't get any of these param value but dummy values mentioned below iad-adgroup-id = 1234567890 iad-adgroup-name = AdGroupName iad-attribution = true iad-campaign-id = 1234567890 iad-campaign-name = CampaignName iad-click-date = "2019-11-06T07:51:48Z" iad-conversion-date = "2019-11-06T07:51:48Z" iad-keyword = Keyword iad-keyword-id = KeywordID iad-org-name" = OrgName – Muhammad Umair Gillani Nov 08 '19 at 06:34
  • There are no params to pass into the URL. You should call the methods provided in the documentation above and look into the response. In development, you'll only get dummy data as mentioned above. – adbitx Jan 13 '20 at 18:49
  • What If I want to move to production because always I am getting development dummy data. – Kirtikumar A. Mar 31 '20 at 11:39
-1

Do some testing on a device and I think you'll find that this line:

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

... should actually be:

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

I realize this does not really answer the question of how to test it. But perhaps you are not aware that if you just run your code on a real device, you will get some dummy data as a response.

xaphod
  • 6,392
  • 2
  • 37
  • 45
  • Not quite true... boolValue is smart enough to return true for "true", "YES", "Y". Here's a fairly exhaustive test of this behavior: http://blog.manbolo.com/2013/07/22/nsstring-boolvalue – photogrammer Dec 16 '16 at 19:58