Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Is it possible to use the productsReceived parameter in custom events?

Discussion in 'Unity Analytics' started by jmartiniGC, Aug 26, 2022.

  1. jmartiniGC

    jmartiniGC

    Joined:
    Jun 2, 2016
    Posts:
    3
    Is it possible to use the productsReceived or productsSpent or any of the other objet type standard parameters in a custom event? I'm able to add them to the schema in the dashboard, but I don't see any way to send them through the Unity SDK. I've been trying to send through the REST API, but those events get flagged as invalid with the reason being "Event schema itemActioned not found."
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You could send a Transaction event https://docs.unity.com/analytics/RecordingTransactionEvents.html . Are you using Unity IAP or other purchase library? Where would you be expecting to obtain productsReceived? https://docs.unity.com/analytics/RecordingTransactionEvents.html
     
  3. jmartiniGC

    jmartiniGC

    Joined:
    Jun 2, 2016
    Posts:
    3
    We're not currently using any IAP system, though we're planning on adding Unity IAP in the future. We're trying to track an event where a player is awarded several items and or virtual currencies, so the Transaction didn't seem like the appropriate event to use.
    We're basing our schema off of the schema we used in DDNA in a previous project where we had a custom rewards object parameter with a similar structure to productsReceived. Since custom object parameters aren't an option in Unity Analytics, I was looking into whether we could use productsReceived instead.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, you would just use the parameter name in your code and send your own event. Are you getting an error? Can you share the code you are using? If you get an error, you could just create your own similarly named parameter if you are seeing a collision.

    https://docs.unity.com/analytics/RecordingCustomEvents.html
     
  5. jmartiniGC

    jmartiniGC

    Joined:
    Jun 2, 2016
    Posts:
    3
    I tried using this initially:
    Code (CSharp):
    1. var parameters = new Dictionary<string, object>()
    2. {
    3.   { "itemName", "TestItem" },
    4.   { "itemType", "TestItemType" },
    5.   { "itemID", "1234" },
    6.   { "action", "Claimed" },
    7.   { "productsReceived", new Unity.Services.Analytics.Product() },
    8. };
    9. AnalyticsService.Instance.CustomData("itemActioned", parameters);
    Which resulted in the error:
    Unknown type found for key productsReceived, this value will not be included.

    This is what I was using to send through the REST API:
    Code (CSharp):
    1. StringBuilder postData = new StringBuilder();
    2. postData.Append("{\"eventName\":\"itemActioned\",");
    3. postData.Append(  "\"userID\":\"").Append(AnalyticsService.Instance.GetAnalyticsUserID()).Append("\",");
    4. postData.Append(  "\"eventUUID\":\"").Append(Guid.NewGuid().ToString()).Append("\",");
    5. postData.Append(  "\"eventVersion\":1,");
    6. postData.Append(  "\"eventParams\":{");
    7. postData.Append(    "\"platform\":\"MAC_CLIENT\",");
    8. postData.Append(    "\"itemName\":\"TestItem\",");
    9. postData.Append(    "\"itemType\":\"TestItemType\",");
    10. postData.Append(    "\"itemID\":\"1234\",");
    11. postData.Append(    "\"action\":\"Claimed\",");
    12. postData.Append(    "\"productsReceived\":{}");
    13. postData.Append(  "}");
    14. postData.Append("}");
    15.  
    16. Debug.Log($"UGS post data: {postData}");
    17.  
    18. string url = $"https://collect.analytics.unity3d.com/api/analytics/collect/v1/projects/{UnityEngine.Application.cloudProjectId}/environments/dev";
    19. var request = new UnityWebRequest(url, "POST");
    20. request.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(postData.ToString()))
    21. {
    22.   contentType = "application/json"
    23. };
    24.  
    25. var requestOp = request.SendWebRequest();
    26. requestOp.completed += delegate
    27. {
    28.   Debug.Log($"UGS responseCode: {request.responseCode}");
    29. };
    I got back a 204 response code, but in Event Browser it was flagged as invalid with "Event schema itemActioned not found." as the reason. I'm thinking that may be unrelated to the specific parameters I'm using though, since it seems like the same issue from https://forum.unity.com/threads/why-are-rest-api-custom-analysis-events-invalid-events.1320606/
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    In your code you are trying to send an empty product object. Where are you actually building your products of this type? What is your intent with this event, how are you planning to use the product object in the dashboard? Did you create your itemActioned custom event in your dashboard with this parameter defined? Why not create your own parameter? I would suggest to get your events working in C# before using the REST API, and ensure they are working correctly first.