Search Unity

Is it possible to enable and disable Analytics through an editor script?

Discussion in 'Unity Analytics' started by Carpet_Head, Dec 30, 2017.

  1. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    258
    We are using Unity Analytics in our project, but do not want it to be active on certain platforms. Is it possible to switch it on and off via editor script?

    In a similar way to how we can write an editor script to change platform

    EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64);

    Is there some api similar to this:

    // EditorSettings.Analytics.Disable()
    // EditorSettings.PerformanceReporting.Disable()
     
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    unityjingyao likes this.
  3. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    258
    is there any update to this? is it possible to disable it at build time. This would really help our build pipeline. Disabling it first thing as the player starts up still seems to send some analytics data

    Same for crash reporting
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You could try to manually edit the /ProjectSettings/UnityConnectSettings.Asset file
     
  5. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    258
    PerformanceReportingSettings.enabled = false;
    AnalyticsSettings.enabled = false;
    CrashReportingSettings.enabled = false;

    Looks like a new API was added ^
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Not sure what API you are referring to, but those settings should indeed disable Analytics.
     
  7. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021

    Hi,

    Didn't start a new thread as think this is related.

    Not sure if those Api's are working. I used the following in my game;

    CB CODE.png


    The Disable HW Statistics selected;

    CB Disabled HW STATS.png

    I did a windows standalone build. Closed down the editor. Ran the build and monitored with Charles Proxy.

    Charles proxy shows that the build is still showing communication attempts to Unity;

    CB Charles result no clinet.png

    If this is normal then how do we get access to the information shared between our games and unity as this is a legal requirement for the newish USA export compliance and French equivalent.

    Thanks
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    If you installed the Charles root certificate and rebooted, you should be able to view the contents of the request and response to see exactly what is being sent. You can find more information here https://unity3d.com/legal/gdpr You can email GDPR@unity3d.com with your GDPR related questions.
     
  9. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Hi @JeffDUnity3D,

    Thanks for the reply. I've read the links you referred to. It seems to be related to apps that have ads, marketing etc switched on. From what I understand the question relating to this thread (which is the same as mine) is how to make sure that no data is shared and no network communications attempted. Hence the need to switch of analytics through code as the thread starter asked. In my game I have attempted to turn off all network communications using the Unity provided API so the game is isolated with no need for any users to have to opt out of any such data collection etc.

    From following the API, unity manual and tutorials I thought this was achievable but it seems to not be the case demonstrated by charles proxy showing network communication generated by unity and not my code even though I am sure to have done everything required for this.

    The links you gave are not clear or helpful regarding this situation. I would have thought the APIs and selecting' Disable H W stats' would be enough

    Could you clarify then. Is it possible to stop unity collecting data? If not then are we devs expected to complete the requirements of the USA export compliance and french equivalents even when it's unity and not us that are collected the data. If this is the case could you provide an easy way for us to access the data you have gathered and providing that information to these USA and French regulatory agencies. Or when submitting products for distribution are we exempt from these legal requirements as it's unity who collect and have the data and not us?

    Thanks again.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The code that I shared should disable all data collection. As mentioned, any further questions should be directed to the GDPR team, thanks for understanding.
     
  11. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Sorry I missed the email you linked to, my fault. I'll contact them re the getting access to the data question.

    Re the code you referred to - Analytics.enabled = false;

    Should that have not stopped all the communication? This is what I'm finding confusing. I would have thought Charles proxy would report no connection attempts. Is this possible bug or am I misunderstanding it's full use?

    Thanks
     
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Are you able to view the request and response content? We would not be expected to be collecting any data, perhaps it is a call simply to check internet access or your login. It is not a Unity Analytics end point. If you disable the Internet, do you get an error?
     
  13. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Unplugging the internet gives the following report

    No internet.png

    Previously with the internet on the Request and Response info as highlighted.

    WithResonseAndRequest.png

    No obvious info showing but seems like attempts of some kind made.

    Thanks
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Agreed and likely as I stated. Please show the actual request and response content. You are only showing the Overview. Click the Structure tab on the left, then the Request and Response tabs will show the unencrypted data.
     
  15. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    @JeffDUnity3D, It's only showing as encrypted info not plain text. Think would need to add the SSL location in ssl proxy settings for that. In case this is only a personal issue and not affecting others I can start a conversation as I don't want to spam this thread. Anything that maybe useful to/affectng others I can add post later.
     
  16. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please see my previous post today at 5:35 pm. You need to install the Charles root certificate and reboot. Help/SSL Proxying/Install Charles Root Certificate. As mentioned, this is not an Analytics endpoint.
     
  17. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Got it. Will do all the tests again tomorrow. Thanks again.
     
  18. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319
    @docsavage hey, curious if you did any more testing with turning analytics off at run-time and any data sent out by Unity via Charles proxy?

    I'm going to look at this myself doing some test builds, curious to hear what you've found so far.

    Thanks
     
  19. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021

    Hi,

    I didn't change anything other than using the API and disable HW statistics. For some reason the game always tries to connect with the network no matter what I do. I know this because the firewall tells me. In spite of this Charles proxy says there's no data transmitting. I'd prefer it to have a straightforward one command API that completely cut off any network access attempts. Basically a network kill switch for the built app. Unfortunately it doesn't seem to have one. Or at least if the ones that already exist should do this they aren't doing it that effectively.

    Thanks
     
  20. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Completely disabling the network is a separate issue. If you are looking to be compliant, the steps in this thread should suffice. This article discusses how to use Charles, and what to do if the events are still encrypted. https://support.unity3d.com/hc/en-us/articles/115002917683-Using-Charles-Proxy-with-Unity . However even if the requests are encrypted, you'll be able to see which endpoints are being hit which is sufficient for confirming. Please provide this information.
     
  21. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021

    Hi @JeffDUnity3D,

    Thanks for this. I did those steps described in the article back in april. Retrying with the charles certificates etc that you advised (1st april). It still showed no data transferred but the connection attempts still occurring. Unfortunately I've can't get you the requested info with the endpoints info as currently in the middle of some massive PC housekeeping and rebuilds since finishing the game.

    You said completely disabling the network is a separate issue. Is it possible to completely disable the network for any build? If there is a way to kill any connection with any network for the builds that would be great to know.

    Thanks
     
  22. mygameskwame

    mygameskwame

    Joined:
    Oct 13, 2018
    Posts:
    11
    Hey i am facing pretty much the same issue like discussed in this thread and i followed all the steps mentioned! But Charles proxy still catches one event when ever unity iap gets initialized. It goes to this url: ecommerce.iap.unity3d.com
    with userid, decisiveid,appid, and sessionid. We got rejected from apple because of this. Is there any solution?
     
    Jbs_GameZone likes this.
  23. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    No solution yet, but we are working on it. Hopefully in the next release.
     
  24. Jbs_GameZone

    Jbs_GameZone

    Joined:
    Dec 14, 2018
    Posts:
    118
    Hello, I got same issue. Disabled ads & all analytics at runtime, but Charles still shows a call at the beginning of the app to https://ecommerce.iap.unity3d.com/catalog providing the appid, deviceid, userid, sessionid

    -> What is that endpoint on your end ?
    -> What is the purpose of the call, what should the response be ? Using Charles proxy I get denied with 405 status and IAPs are not working (price / purchase / restore), so something is not going well.
    -> How can the request be turned off / disabled ? Will IAPs work without this call ?

    I got a kids app twice rejected by apple because of third party calls, and this is the only https call left that the app makes to non apple urls.

    What is your feedback on how should we proceed forward. Disabling all forms of revenue (ADS & IAP) just to get accepted on apple is not a viable solution for most game devs out there.

    Looking fwd for your reply

    Using Unity 2019.3.12f1
     
    Last edited: May 2, 2020
  25. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    You don't need to disable Ads/Analytics at runtime. Have you checked the age designation checkbox?

    upload_2020-5-6_14-48-20.png
     
  26. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,797
    What does that checkbox do exactly?
     
  27. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
  28. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,797
    That does not really say what it actually does, at least not in any detal. I don't care about COPPA, I don't target kids, I don't have ads and I have analytics off.

    Will this checkbox help me ensure Unity does not transmit any data at all?

    Because until very recently, it still occasionally transmitted data no matter how many other checkboxes I had turned off, or whatever hacks and other attempts I did to just make Unity stop.

    I keep waiting for Unity to add a simple "I DON'T CARE ABOUT DATA, I JUST WANT TO MAKE GAMES" checkbox, that actually works.
     
  29. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    What Unity version are you using?
     
  30. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,797
    2018.4.22f1
     
  31. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    Thanks for the information. It's a confirmed bug and we are working on it.
     
  32. mygameskwame

    mygameskwame

    Joined:
    Oct 13, 2018
    Posts:
    11
    Hey solved the issue with switching from unity iap solution to this asset, https://assetstore.unity.com/packages/tools/integration/ios-native-pro-119175
    It is a little bit harder to implement but it solved most of our problems (i had to still disable some section in xcode)
     
    Jbs_GameZone likes this.
  33. mygameskwame

    mygameskwame

    Joined:
    Oct 13, 2018
    Posts:
    11
    As far as my expires earlier this year (on unity 2019.3) this check box does not help since apple does not allow any third-party (unity counts as third-party in this case) server analytic events and only after complete removal of those we got accepted from apple. I do not completely agree with that but that was the realty for us. So it would be nice if at least for ios we got a solution from unity to have iap without analytics.
    best regards!
     
  34. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    Thank you for your kind advice, we will improve the service to make it more convenient.
     
  35. Jonsi

    Jonsi

    Joined:
    May 21, 2013
    Posts:
    45
    @SamOYUnity3D is there any estimate as to when this Unity IAP without analytics for iOS is likely to be available? i.e is it likely to be in the next weeks or months or later? It would help us decide our forward (i.e. wait for solution or go with Xcode edits and 3rd party asset). Many thanks.
     
  36. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    My estimate would be towards the end of the year
     
  37. Jonsi

    Jonsi

    Joined:
    May 21, 2013
    Posts:
    45
    @JeffDUnity3D Thanks for that. Very useful to know - I'll use another IAP asset. It's disappointing as Unity IAP was so easy to set up and nice to use. It may be helpful to let people know that Unity IAP cannot be used for iOS kids apps until this time (save people spending time in integrating Unity IAP which Apple will reject). Could maybe put in a pinned thread at the top of the Unity IAP forum?
     
  38. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I did not make that claim. We simply don't know yet. Do you have a Charles Proxy capture? Did you disable Analytics at runtime and use the most recent release of Unity? https://support.unity3d.com/hc/en-us/articles/115002917683-Using-Charles-Proxy-with-Unity
     
  39. Jonsi

    Jonsi

    Joined:
    May 21, 2013
    Posts:
    45
    @JeffDUnity3D sorry ... my misunderstanding - thanks for clarifying. I was under the impression that the inclusion of the Analytics package precluded me from claiming that the app does not contain analytics when submitting a kids app ... resulting in app rejection.

    I had an app rejected yesterday as a result of the existence of 3rd party analytics (using pretty recent Unity 2019.4.1f1 with Unity IAP 1.23.2 ). Not sure how it was detected, whether by code analysis, or listening for calls, or simply because I said the app included the Unity analytics package. However, I did not include code to disable Analytics at run time, as looking in this thread it didn't seem to help in getting through review. Looking at the various posts on the forums the way people seem to reliably get around the problem is by giving up the fight and using a 3rd party asset.

    Is the theory that if I disable Analytics at runtime and monitor using Charles Proxy that I could answer "No" to the does your app contain analytics question? Or that I should try to put a case forward in app review to say "yes analytics code is there, but I never call it" (wouldn't rate my chances of pulling this one off).

    I would love to use Unity IAP as it's been so easy to integrate (until the final hurdle).
     
  40. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You don't monitor your live game with Charles Proxy, I only suggested to use it in your testing once to see what data is being sent.
     
  41. Jonsi

    Jonsi

    Joined:
    May 21, 2013
    Posts:
    45
    Yes - understood. So the theory is that if calls weren't made during testing with Charles Proxy it would provide support to the claim that the release was analytics free for all practical purposes - and perhaps this may be sufficient to pass review. Or indeed if data is being sent then this could be investigated as you wouldn't expect it?
     
  42. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We are looking for unexpected events being sent and confirming that Analytics is properly disabled.
     
  43. Jonsi

    Jonsi

    Joined:
    May 21, 2013
    Posts:
    45
    @JeffDUnity3D Just to make sure I'm up to date. Can you confirm that to disable Analytics you just need these calls as the very first calls in your game.

    Code (CSharp):
    1. // If you want to disable Analytics completely during runtime
    2.     public void DisableAnalyticsCompletely()
    3.     {
    4.         Analytics.enabled = false;
    5.         Analytics.deviceStatsEnabled = false;
    6.         PerformanceReporting.enabled = false;
    7.     }
    Taken from https://docs.unity3d.com/2020.1/Documentation/ScriptReference/Analytics.Analytics-enabled.html
     
  44. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Try this in Awake or a method with the OnLoad attribute

    https://docs.unity3d.com/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html

    Analytics.initializeOnStartup = false;
    Analytics.enabled = false;
    PerformanceReporting.enabled = false;
    Analytics.limitUserTracking = true;
    Analytics.deviceStatsEnabled = false;
     
    Last edited: Aug 12, 2020
  45. wwcolter

    wwcolter

    Joined:
    Nov 4, 2016
    Posts:
    28
    Should this be
    Code (CSharp):
    1. Analytics.limitUserTracking = true;
     
    JeffDUnity3D likes this.