Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  3. Unity’s Demo Team is excited to share their upcoming interactive demo, Book of the Dead. See more information here.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Tracking Monetization: Receipt Verification

Discussion in 'Unity Analytics' started by kentunity, Mar 27, 2015.

  1. kentunity

    kentunity

    Unity Technologies

    Joined:
    Sep 16, 2014
    Posts:
    55
    Tracking monetization in our SDK requires you to call the Transaction method and pass in the necessary parameters.

    The Transaction method looks like this:
    Code (csharp):
    1. UnityAnalytics.Transaction(string productId, decimal price, string currency, string receipt, string signature);
    example:
    Code (csharp):
    1. UnityAnalytics.Transaction("PRODUCT_ID", 0.99m, "USD", null, null);
    We currently support both iOS and Android platforms and also support receipt verification.
    With receipt verification, you'll have the ability to differentiate fraud and real transactions on your dashboard.
    We've had a lot of questions regarding the receipt verification and how to do it when using popular In-App-Purchase plugins like Prime31 or Unibill.

    So we've come up with the following receipt guide:
     
    Last edited: Apr 28, 2015
  2. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,370
    Well I was doing just this but after querying why I didn't get any verified transactions I was told by Angelo Ferro that the receipt could not be base 64 encoded and I had to decode it myself before passing it to you.

    The receipt can't be Base64 encoded. It needs to be decoded first before being passed as a parameter, here is some sample code to decode it:

    byte[] data = System.Convert.FromBase64String("IOS_RECEIPT_GOES_HERE");
    string receipt = System.Text.Encoding.UTF8.GetString(data);
     
  3. angeloferro

    angeloferro

    Unity Technologies

    Joined:
    Sep 12, 2014
    Posts:
    105
    Hi @andymads,

    We recently made a change to our backend infrastructure to accept Base64 encoding for Prime31 transactions. The original instructions I sent you were correct at the time, but we wanted to simplify the receipt verification process by accepting Base64 encoded transactions (so no need to decode it!) :)

    Either way, for Prime31 transactions on iOS, whether you send it decoded or encoded, our backend will still process it correctly. Please let us know if you have any questions :)

    Thanks!
    -Angelo
     
  4. michael_voltage

    michael_voltage

    Joined:
    Feb 27, 2015
    Posts:
    30
    How is the data handled if a duplicate receipt is sent for multiple transactions? Is it treated as just one (under both total revenue and verified)?
     
  5. kentunity

    kentunity

    Unity Technologies

    Joined:
    Sep 16, 2014
    Posts:
    55
    Currently, we don't validate for duplicate receipt, but we do checks based on the timestamp of the receipt and when the transaction event was triggered. Both timestamps have to be within 1 hour.
     
  6. Lotti

    Lotti

    Joined:
    Apr 15, 2013
    Posts:
    18
    Good to know. Time to leave Flurry and save time verifying all those F***ing receipt that no-one implements in the same way.
    I will surely try this service on next game.
     
  7. michael_voltage

    michael_voltage

    Joined:
    Feb 27, 2015
    Posts:
    30
    Thanks Kent for the further details!
     
  8. Splipic

    Splipic

    Joined:
    May 18, 2015
    Posts:
    2
    Hi, Im trying to set my Google Api Key but always I recieved "There was an error updating your project."

    Any guess??
     
  9. sschan

    sschan

    Unity Technologies

    Joined:
    Oct 8, 2014
    Posts:
    87
    Hi @Splipic - We apologize for the error message when you attempted entering your Google API Key. Please try this again as the error is now fixed. Let us know if you need any assistance.
     
  10. Splipic

    Splipic

    Joined:
    May 18, 2015
    Posts:
    2
    It work thank you, the Google Api Key is the Base64-encoded RSA public key right?
     
  11. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    711
    Hey, I was just implementing this and I was wondering if you think it's worthwhile and/or possible to track refunds? How would I go about doing this? I was thinking of just tracking a negative purchase value... but I wasn't sure if that was a good idea or not.
     
  12. mbirk

    mbirk

    Unity Technologies

    Joined:
    Apr 25, 2014
    Posts:
    18
    Hi @Splipic, Yes that is the correct Google API key, as described in Google's documentation. Our receipt verification for Google Play apps works by base64-decoding the key and using it to verify the signature in the receipt.
     
  13. eezSZI

    eezSZI

    Joined:
    Nov 16, 2012
    Posts:
    121
    Is there currently a way to check the response of verified or unverified - or is that a future API? Is it foolproof enough to disable future IAP for a user with unverified transactions - assuming they have a tampered version of the app?

    My instinct says no, but isn't that the point of monitoring if the transactions are verified?
     
  14. mpinol

    mpinol

    Unity Technologies

    Joined:
    Jul 29, 2015
    Posts:
    315
    Hi @eezSZI,

    Currently there is no returned value on a Transaction method so determining if an in app purchase was verified or unverified is not possible. Our goal is to accurately display your transaction histories, by separating your verified transaction from fraudulent ones, and not to prevent fraudulent transactions from occurring.
     
  15. eezSZI

    eezSZI

    Joined:
    Nov 16, 2012
    Posts:
    121
    mpinol likes this.
  16. vladrybak

    vladrybak

    Joined:
    Aug 30, 2013
    Posts:
    106
    Hello, I'm using Unity 5.2.1p2 and build games for windows, android, ios and web. Does purchase verification exist now only for android and ios? Did you plan to integrate it for windows store/phone 8.1/10 and for facebook?
     
  17. mpinol

    mpinol

    Unity Technologies

    Joined:
    Jul 29, 2015
    Posts:
    315
    Hi @vladrybak,

    Yes, we currently only support purchase verification for Android and iOS. Windows store is certainly on our roadmap but I cannot give you any real information about when it will be available. I do not believe Facebook has a purchase verification system in place, if you have any information on this you could link me that would be greatly appreciated, but I will look into the possibility of adding Facebook to our future plans as well.
     
  18. fpomerleau

    fpomerleau

    Joined:
    Jun 22, 2015
    Posts:
    1
    Hi everyone,

    We are using Unibill in Unity 5.1.1p2 and everything seems to work properly, excepted that we do not see the transactions in Unity Analytics. Even though the transactions are processed in iTunes Connect.

    Any guess?
     
  19. mpinol

    mpinol

    Unity Technologies

    Joined:
    Jul 29, 2015
    Posts:
    315
  20. ailen

    ailen

    Joined:
    Mar 4, 2014
    Posts:
    4
    Hi @kentunity

    can we filter our test devices with purchase data or it will mix the test data and real data.
     
  21. mpinol

    mpinol

    Unity Technologies

    Joined:
    Jul 29, 2015
    Posts:
    315
    Hi @ailen,

    As of right now there is no way to keep the test data and real data separated on the Dashboard. There are two kinds of approaches you can use to keep your test data separated from your real data.

    1. When building your projects check 'Development Build' in the Build Settings window. This will send all of the Analytics data directly to the Validator on the integration pages. The only downside to this is that you will only be able to view this data as it is coming in and not be able to reference it at a later date so this would be most appropriate for testing whether or not your events are formatted correctly with the correct monetary values.

    2. You could create a new Analytics project and then link that project id to your Unity project only when you are creating test builds. The main issue with this is that you will need to be rather diligent about making sure that the appropriate Analytics project is linked to your Unity project when creating builds but it is much more useful being able to reference the data at a later date.
     
  22. levius

    levius

    Joined:
    Jun 18, 2016
    Posts:
    3
    Hi @mpinol . Can you help me?
    I don't understand what insert in Analytics.Transaction(productId, amount, currency, --->receiptPurchaseData<---, --->signature<---)
    from Unity IAP. I have IPurchaseReceipt, than I cast it to GooglePlayReceipt & AppleInAppPurchaseReceipt.

    Can I use Analytics.Transition >>OK return's value<< to identify the receipt is valid?

    Thank's. Best regards, Andrew
     
  23. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    787
    @levius

    If you are using Unity IAP then you do not need to use the Transaction events. This method is used internally in the Unity IAP purchase code. If you were to use Unity IAP and the Transaction event, then you will be double counting your revenue and it could cause issues and discrepancies in your data.
     
  24. levius

    levius

    Joined:
    Jun 18, 2016
    Posts:
    3
    This isn't true. I think you don't test this or don't realy know how it works.

    Yes, I'm using Unity IAP. But, I don't see Revenue, only unverified revenue - but this is not correct information.

    For iOS I fixed this problem.

    AppleInAppPurchaseReceipt apple = productReceipt as AppleInAppPurchaseReceipt;
    Analytics.Transaction(productId, amount, currency, apple.ToString(), null);

    It works very well!

    But for Google Play, I don't know where I can get signature for my transaction.
    Please ask about it in those who develop analytics.
     
  25. levius

    levius

    Joined:
    Jun 18, 2016
    Posts:
    3
    Local receipt verification doesn't work too. I have many fake purchases.
     
  26. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    787
  27. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,370
    In the Receipt Validation section of the docs it says if you are using the Prime31 StoreKit iOS plugin to pass in the base64EncodedTransactionReceipt property. This property was removed in plugin version 2.17 (September 2016) "as it has been deprecated by Apple since iOS 7".

    FYI the AppsFlyer plugin we use has a similar method but it takes the transaction id.
     
  28. dragonfoundry

    dragonfoundry

    Joined:
    Jun 18, 2014
    Posts:
    4
    To confirm something I think is right: If I'm using Unity Analytics for a Steam game, I should be calling "Analytics.Transaction(itemId, price, currency)" for every successful purchase. But for an iOS/Android game using Unity Purchasing, I should not call that, as Unity Purchasing already handles that
     
  29. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    787
    Yes, that is correct.
     
  30. krisventure

    krisventure

    Joined:
    Mar 24, 2016
    Posts:
    40
    @ap-unity Could you point me to the documentation of this, saying that we don't need to add the transaction code if we use Unity Analytics on iOS? I've been reading Unity analytics integrations tutorials for a while and this detail wasn't mentioned.
     
  31. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    787
    @krisventure

    That is definitely something we should make more clear in the documentation. I think it's meant to be implied by the fact that Analytics is required for Unity IAP, but we should update our docs.

    I did find a reference to it in the Manual, under Monetization Metrics:

    >IAP transactions include Unity IAP purchases and purchases reported using the Analytics.Transaction() function.

    https://docs.unity3d.com/Manual/UnityAnalyticsTerminology.html
     
    krisventure likes this.
  32. krisventure

    krisventure

    Joined:
    Mar 24, 2016
    Posts:
    40
    @ap-unity Awesome thanks! On another note, we're submitting our iOS app tomorrow with Unity IAP/analytics/ads. The IAP transaction currently takes me like 15 seconds before it returns payment success (but this is on TestFlight, app isn't released yet). Is the extreme slow response time related to Unity IAP - iTunes Store interface, is it always going to be that slow or perhaps related to TestFlight?

    Sorry about the unrelated question.
     
  33. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    787
    @krisventure

    Once you initiate a purchase, we call the native purchase API, so the OS takes over after that. We have definitely heard reports of slow and weird behavior with sandbox purchases that are cleared up once the app is released. However, I can't really make any guarantees. For the most part, Unity IAP is a wrapper for native functionality, so we try to be as efficient as we can.
     
  34. krisventure

    krisventure

    Joined:
    Mar 24, 2016
    Posts:
    40
    @ap-unity I'm seeing another weird behavior with IAP in Testflight: I've been bombarded with lots of Sign in alerts in the game, continuously, like every 10 seconds. Every time it asks me to type in my password but when I do so it comes back again later. It started when I signed in from my iPhone with a test account created in iTunes Connect, and then (after testing with test account finished) I signed out and back into my own personal account to continue testing with my own account. So ever since I'm back to my own account (the one that worked fine before), I just can't silence this pop up message.

    I've read on multiple Apple forums that 'This usually means that your app failed to call finishTransaction for one or more transactions sent to updatedTransactions. IStoreKit wants the appropriate user to log in so it can resend the transactions.' But I'm just using the IAP script provided by Unity, with little modification.

    Is it possible that Unity IAP isn't taking care of calling finishTransaction in some cases (somehow related to Testflight and sandbox users)?