Jump to: Collecting the Receipt Data | Apple Install Receipt with Measure Session | iOS Install Validation Results
Using our iOS SDK 3.1.3 or greater, installs from the iTunes app store on iOS 7 are now verified with Apple as outlined in iOS 7.0+ Install Validation.
In order for you to take advantage of the Apple install validation information with the measure session endpoint, it requires that:
- Your app collects the receipt data and sends it to your servers.
- Your servers include the receipt data with measure session.
Collecting the Receipt Data
Please use the following method to detect whether the appStoreReceiptURL
selector as is available per Apples docs.
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { // Load resources for iOS 6.1 or earlier return nil; } else { // Load resources for iOS 7 or later NSURL *appStoreReceiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; NSData *receiptData = [NSData dataWithContentsOfURL:appStoreReceiptURL]; return receiptData; }
Receipt in the below context is the returned receiptData from above:
// Base64 encode the IAP receipt data NSString *strReceipt =nil; if (receipt.length > 0) strReceipt = [MATUtils MATbase64EncodedStringFromData:receipt];
Apple Install Receipt with Measure Session
Once you’ve collected the receipt data and base64-encoded it as a string, you can send include it with the call measure session. You can form the necessary POST body by placing the receipt you collect in a JSON object named “apple_receipt”. This is taken and POSTed to the measurement URL.
POST Body format:
{ "apple_receipt":"INSERT_YOUR_STRING_RECEIPT_HERE"}
Example Measure Session URL:
https://YOUR_ADVERTISER_ID.measure.mobileapptracking.com/serve?action=session&advertiser_id=877&sdk=ios&package_name=app.atomic.dodgeball&ios_ifa=AAAAAA-BBBB-CCCC-11111-2222222222222&ios_ad_tracking_disabled=0&ios_ifv=ZZZZZZ-BBBB-CCCC-11111-2222222222222&user_id=10000000001&device_ip=123.123.123.123&os_version=11.2.2&device_brand=Apple&device_model=iPhone5,2&device_carrier=Verizon&country_code=US&response_format=json
NOTE: Please ensure you have included the following parameters:
- os_version="YOUR_CURRENT_OS_VSERION"
- sdk=ios (Replace sdk=server with sdk=ios)
If these parameters are not included, our system does not read the app as an iOS app and will throw out the Apple Receipt.
POST body for example above:
{ "apple_receipt":"MIISfAYJKoZIhvcNAQcCoIISbTCCEmkCAQExCz...=" }
Upon the Measurement API responding to the request, we will take the receipt and verify with Apple that the install was valid. Keep in mind it’s important to pass the package name of your app in the request URL to ensure validation is successful.
iOS Install Validation Results
When we do the validation on in-app purchases for iOS, successfully verified purchases have a purchase validation code of 0. If the purchase is not validated, however, there can be many reasons as to why as shown in the table below. Install validation uses the same as in-app purchase validation.
Purchase Validation Code | Reason |
-4 | No receipt when one was required. |
-3 | Valid receipt but contains bundle id of a different site. |
-2 | Some error with our attempt occurred. |
-1 | We haven’t tried to validate this yet. |
0 | Good verification from Apple. |
21000 | The App Store could not read the JSON object you provided |
21002 | The data in the receipt-data property was malformed. |
21003 | The receipt could not be authenticated. |
21004 | The shared secret you provided does not match the shared secret on file for your account. |
21005 | The receipt server is not currently available. |
21006 | This receipt is valid but the subscription has expired. When this status code is returned to your server, the receipt data is also decoded and returned as part. |
21007 | This receipt is a sandbox receipt and sent to the production service for verification. |
21008 | This receipt is a production receipt and sent to the sandbox service for verification. |
You can view the results of the iOS install validation in the log reports. Learn how by continuing to read our support document iOS 7.0+ Install Validation.