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.”
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
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.
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.
I tried using this initially:
var parameters = new Dictionary<string, object>()
{
{ "itemName", "TestItem" },
{ "itemType", "TestItemType" },
{ "itemID", "1234" },
{ "action", "Claimed" },
{ "productsReceived", new Unity.Services.Analytics.Product() },
};
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:
StringBuilder postData = new StringBuilder();
postData.Append("{\"eventName\":\"itemActioned\",");
postData.Append( "\"userID\":\"").Append(AnalyticsService.Instance.GetAnalyticsUserID()).Append("\",");
postData.Append( "\"eventUUID\":\"").Append(Guid.NewGuid().ToString()).Append("\",");
postData.Append( "\"eventVersion\":1,");
postData.Append( "\"eventParams\":{");
postData.Append( "\"platform\":\"MAC_CLIENT\",");
postData.Append( "\"itemName\":\"TestItem\",");
postData.Append( "\"itemType\":\"TestItemType\",");
postData.Append( "\"itemID\":\"1234\",");
postData.Append( "\"action\":\"Claimed\",");
postData.Append( "\"productsReceived\":{}");
postData.Append( "}");
postData.Append("}");
Debug.Log($"UGS post data: {postData}");
string url = $"https://collect.analytics.unity3d.com/api/analytics/collect/v1/projects/{UnityEngine.Application.cloudProjectId}/environments/dev";
var request = new UnityWebRequest(url, "POST");
request.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(postData.ToString()))
{
contentType = "application/json"
};
var requestOp = request.SendWebRequest();
requestOp.completed += delegate
{
Debug.Log($"UGS responseCode: {request.responseCode}");
};
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 Why are REST API custom analysis Events Invalid Events
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.