Skip to content

Unity Analytics

C. Plug edited this page Jul 27, 2022 · 6 revisions

⚠️ [NOTE] ⚠️

This page describes the legacy, deprecated Unity Analytics that no longer accepts integration of new projects.
UniSwitcher was equipped with the ability to send the event for each completed screen transition by using the "ScreenVisit" event in the deprecated Unity Analytics event set. However, with the new Unity Gaming Service Analytics, such event name is no longer the standard.
Although UniSwitcher currently does not support the new Analytics, I'm investigating it. Unfortunately, there is no ETA for the official support for now.


This plugin supports Unity Analytics. When UniSwitcher detects UA is enabled, it will send the 'ScreenVisit' event whenever PerformSceneTransition is called.
If you want to track scene switch events, it is strongly recommended to add UniSwitcher.Domain.IReportable to your BaseScene implementation.

But why?

Unity Analytics has a rate limit on the number of events sent per set time.
Since UniSwitcher reports every scene change (its destination) using AnalyticsEvent.ScreenVisit by default, too many scene changes in a short period can easily cause the game to hit the rate limit. Such change can occur if you implement, e.g., a dialog scene that can occur multiple times.
By implementing IReportable, you can suppress the scene transition event sent to Unity Analytics.

Implementing IReportable

The interface IReportable requires implementing the DoNotReport method.
This method indicates Scenes that should not be reported of their transitions, e.g., scenes that contain dialogs.

public class Scene: BaseScene, IReportable
{
    // Your implementation here

    /// <summary>
    /// If this returns true, DO NOT SEND ANALYTICS REPORT.
    /// </summary>
    /// <returns></returns>
    public bool DoNotReport()
    {
        var self = this;
        return NonReportingScenes().Any(scene => self == scene);
    }

    // Suppose that this is your pause dialog scene.
    public static Scene PauseDialog => new Scene("pause_dialog.unity");

    /// <summary>
    /// Scenes you DON'T want to send analytics reports about
    /// because, e.g., it can be loaded in quick succession.
    /// NOTE: This is just one way to implement this behavior;
    ///       if you have a better idea, you may use it instead.
    /// </summary>
    /// <returns></returns>
    private static IEnumerable<Scene> NonReportingScenes()
    {
        // List all scenes you want to suppress using 'yield return.'
        yield return PauseDialog;
    }
}

Clone this wiki locally