Search Unity

Change cloudProjectId during build in Unity 5.1

Discussion in 'Unity Analytics' started by ortin, Aug 5, 2015.

  1. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Why is PlayerSettings.cloudProjectId read only? I can easily set PlayerSettings.productName, PlayerSettings.bundleIdentifier etc, but not cloudProjectId. Before 5.1 integrated analytics you could easily change it when building app now it seems to be impossible. Is there any other way to do it?
     
  2. mpinol

    mpinol

    Joined:
    Jul 29, 2015
    Posts:
    317
    Hi @ortin,

    How are you attempting to change the PlayerSettings.cloudProjectId? In 5.1 you should be able to change it by going to Edit -> Project Settings -> Player, then in the Inspector window you should be able to edit the id.
     
  3. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    From code.
    Something like this:
    Code (CSharp):
    1. private static void BuildIPhone() {
    2.   PlayerSettings.productName = "@{productName}@";
    3.   PlayerSettings.bundleIdentifier = "@{bundleIdentifier}@";
    4.   //PlayerSettings.cloudProjectId = "@{cloudProjectId}@";
    5.   BuildPipeline.BuildPlayer(new[] { "@{SCENES_LIST}@" }, "@{BUILD_PATH}@", BuildTarget.iOS, BuildOptions.SymlinkLibraries);
    6. }
     
    Last edited: Aug 6, 2015
  4. mpinol

    mpinol

    Joined:
    Jul 29, 2015
    Posts:
    317
    Hi @ortin,

    As of 5.1 the best way to change the cloudProjectId is through the Inspector window.
    What are you trying to accomplish by changing the cloudProjectId, or what is the circumstance where you want to change it?
     
    Last edited: Aug 7, 2015
  5. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    I have multi-game project inside one unity project (it's heavily based on common code/resources). So during build build-script separates this games (deletes everything except of common based and game_name based) and then builds using method I showed in the previous post.
    Another usage for it is to have different ids for test and release builds.

    Anyway for now I resorted to replacing cloudProjectId: xxx in ProjectSettings.asset, but having real property looks less "hackish" for me.
     
    Last edited: Aug 8, 2015
  6. actraiser3

    actraiser3

    Joined:
    Sep 11, 2014
    Posts:
    28
    I too generate different apps from a single project - think for example a version of the app being Free2Play and one being a Paid App.

    Hence, there is a need to access "PlayerSettings.cloudProjectId" from Script to set it accordingly to the version of the app, either when the app boots or to put the information in a custom build script.

    Ortin, could you post a snippet how you replace the id in the ProjectSettings.asset?

    -act
     
  7. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    Just posting another request for this ability and the ability to turn off Unity Analytics altogether if necessary (possibly with a blank cloudProjectId).
     
  8. mpinol

    mpinol

    Joined:
    Jul 29, 2015
    Posts:
    317
  9. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    I use text serialization and Gradle for build script so I just replace "cloudProjectId: " with "cloudProjectId: xxxx" using ant.replace.
    Probably the same can be done inside of Unity by just using pure c# to replace string in file.
     
  10. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    Here is a very valid use case:

    We build our app for different environments like DEV, QA, STG, PROD and we want all those environment builds have different cloud project id for analytics purposes.

    We use PreExport method on cloud build to be able to process some differences on the app according to selected environment and we also want to be able to modify cloud project id inside PreExport method without modifying the ProjectSettings.asset file's text via IO operations.

    Please let me know if you implement an API for altering (link/unlink) cloud project id in UnityEditor namespace in the future.
     
  11. mbirk

    mbirk

    Unity Technologies

    Joined:
    Apr 25, 2014
    Posts:
    18
    Hi @Xtro, while we don't support changing the Cloud Project ID for different build targets, on iOS and Android you can change the Bundle ID for different build targets, and then use the Bundle ID for segmentation in the Unity Analytics dashboard. I know it's not exactly what you are looking for, but it might work for your use case. Hope that helps.

    Cloud Build dashboard (Signing Creds for Build Target):

    2017-04-10_11-34-06.png

    Unity Analytics dashboard (Segment Builder):
    2017-04-10_11-38-45.png
     
  12. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    How about performance reporting tool?
     
  13. mbirk

    mbirk

    Unity Technologies

    Joined:
    Apr 25, 2014
    Posts:
    18
    That is a good point / question. The Performance Reporting service does not currently support filtering by Bundle ID. Feel free to add a feature request at https://feedback.unity3d.com/
     
  14. FloBeber

    FloBeber

    Joined:
    Jun 9, 2015
    Posts:
    166
    Here is a quick snippet allowing to edit the ProjectSettings.asset file in a build script.

    Code (CSharp):
    1. const string projectSettingsPath = "ProjectSettings/ProjectSettings.asset";
    2. var projectSettingsString = File.ReadAllText(projectSettingsPath);
    3. var match = new Regex(@"cloudProjectId: \s*([^\s]+)").Match(projectSettingsString);
    4.  
    5. if (match.Success)
    6. {
    7.     string cloudProjectId = match.Groups[1].Value;
    8.     string desiredCloudProjectId = useId1 ? "xxx-xxxxxxx-xxxx-xxxx" : "yyyy-yyyyyyy-yyyyy-yyyy";
    9.     projectSettingsString = projectSettingsString.Replace(cloudProjectId, desiredCloudProjectId);
    10.  
    11.     File.WriteAllText(projectSettingsPath, projectSettingsString);
    12.  
    13.     CloudProjectSettings.RefreshAccessToken(null);
    14. }
    15. else
    16. {
    17.     Debug.Log("cloudProjectId could not be found");
    18. }
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Could you add any necessary Using statements too? Otherwise, thanks!
     
  16. ProdiggaPA

    ProdiggaPA

    Joined:
    Nov 29, 2019
    Posts:
    11
    Could we get an official API for this? Instead of text search and replace hacks?

    We have 3 versions of our game. Global, China, Beta. We want each to have its own set of Analytics, Diagnostics, etc. This is surely enough of a common use case in 'real games' that publish globally - at the very least the Global/China build separation. I suspect that must be fairly common.

    Every plugin we have in the project thus far - Google Play Games SDK, Facebook SDK, Flurry, Photon, Adjust, Iron Source - plays nicely and allows us to configure the project ID equivalent at build time. Would be great if Unity could catch up too.

    Unity Feedback site was deleted 2 years ago along with all the feedback that was posted (including the one linked above) and there is no replacement except forum posts, so here we are.
     
  17. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    There currently is not an API for this, I don't believe there are any immediate plans. We are moving to the deltaDNA API over the next year, I will bring this up for that effort.
     
    ProdiggaPA likes this.
  18. ProdiggaPA

    ProdiggaPA

    Joined:
    Nov 29, 2019
    Posts:
    11
    Is there any more details on the move to deltaDNA ? Which of Unitys existing services will shift there?
     
  19. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Just Analytics https://unity.com/products/deltadna