I’m looking at setting up the Unity Analytics service in a project. I’ve linked the project to the service and have included the code snippet for the Analytics service in the manifest.json file:
“com.unity.services.analytics”: “3.0.0-pre.4”
I’ve added the “using Unity.Services.Analytics;” at the top of my class, and have also included the below code:
// Start is called before the first frame update
async void Start()
{
await UnityServices.InitializeAsync();
}
However, I seem to be getting the following error:
error CS0103: The name ‘UnityServices’ does not exist in the current context
had the same problem 5 minutes ago, documentation is quite complicated to follow as it keeps promoting that gaming services beta plugin in every page, and some guides seem to indicate they are for the new and some for the old analytics?
i went back to legacy analytics plugin from package manager for now… but interested to know whats the solution for that beta…
Hi Kilfeather and mgear,
Thanks for posting your feedback and concerns.
Correction to my previous post: The Authentication package is not required when using Analytics. All that is required is the Import to Core : using Unity.Services.Core;
Once you have imported the package you must include the following import/using statement
using Unity.Services.Analytics;
using Unity.Services.Core;
Here is the full script that can be attached to a game object in your scene as an example.
If you have created a custom event, Simply replace the parameter and event with your own
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Services.Analytics;
using Unity.Services.Core;
public class UGS_Analytics : MonoBehaviour
{
async void Start()
{
await UnityServices.InitializeAsync();
HandleCustomEvent();
}
private void HandleCustomEvent()
{
//Handle Custom event
Dictionary<string, object> parameters = new Dictionary<string, object>()
{
{ "myCustomParam", "Hello World"}
};
// The event will get queued up and sent every minute
Events.CustomData("myCustomEvent", parameters);
// You can call Events.Flush() to send the event immediately
Events.Flush();
}
}
the big note on the first line made me think that its required to signup for that beta, to use those events,
then went to signup on dashboard, followed to installation guide: https://docs.unity.com/analytics/SDKInstallation.html
selected analytics, made the snippet, it generated only that “com.unity.services.analytics” line.
We’re having a similar problem with missing namespace. We have Analytics Library 3.6.12 and the built-in Unity Analytics. The Unity.Services.Core namespace seems OK but the Analytics one still errors.
We’re on Unity 2021.3.1f1.
(We don’t see the version 4.1.0 and the package name is ‘Analytics library’, not ‘Analytics’.
I trust you restarted Unity, etc. Please try with a new project. You may need to regenerate your project files on this project. Does the code run in Unity? That is, is this only an Intellisense issue in your code editor? Perhaps I misunderstood, your first sentence says you solved the issue.
Hello Everyone, I can’t seem to find unity analytics 4.1. for some reason the only package I can download is Analytics Library 3.6.12. Also, in the service tab I can only see Legacy Analytics, how can I set up services so I canturn on Analytics?
Please refer to this previous post above, you need to add it manually. Some versions of Unity did not receive the corresponding Package Manager back port https://discussions.unity.com/t/874700/13
“Had the same with 2021.3.0f1, I had to manually add the package by name (+ sign in the top left corner) and add com.unity.services.analytics”