Search Unity

dynamic event parameter without specifying target object

Discussion in 'Unity Analytics' started by undefined666, Aug 1, 2019.

  1. undefined666

    undefined666

    Joined:
    Apr 3, 2018
    Posts:
    42
    I have following singleton class to work with unity analytics:

    Code (CSharp):
    1. public class AnalyticsManager : MonoBehaviour
    2. {
    3.     [SerializeField]
    4.     private AnalyticsEventTracker BlitzStartedTracker;
    5.     [SerializeField]
    6.     private AnalyticsEventTracker BlitzRestartedTracker;
    7.     [SerializeField]
    8.     private AnalyticsEventTracker BlitzFinishedTracker;
    9.     private static AnalyticsManager instance;
    10.     public static AnalyticsManager Instance {
    11.         get {
    12.             return instance;
    13.         }
    14.     }
    15.     private void Awake() {
    16.         DontDestroyOnLoad(gameObject);
    17.         if (instance == null)
    18.             instance = this;
    19.         else
    20.             Destroy(gameObject);
    21.     }
    22.     public void TriggerBlitzStarted() {
    23.         BlitzStartedTracker.TriggerEvent();
    24.     }
    25.     public void TriggerBlitzRestarted() {
    26.         BlitzRestartedTracker.TriggerEvent();
    27.     }
    28.     public void TriggerBlitzFinished() {
    29.         BlitzFinishedTracker.TriggerEvent();
    30.     }
    31. }
    The game object this script attached to also holds 3 AnalyticsEventTracker components for each event.I'd like to pass parameter with my event but AnalyticsEventTracker requires to specify target object where it takes param value.
    Is there way set event parameter without target object?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,918
    You don't need to use the Analytics Tracker component any longer, the functionality is built into the Editor. What version of Unity are you using?
     
  3. undefined666

    undefined666

    Joined:
    Apr 3, 2018
    Posts:
    42
    I'm still on 2018.3.12f1 as 2019 version shows significant performance drop on webgl target.
    2019.1.1f1 (64-bit) the last version I was testing on.Also there is no way to downgrade project back to 2018 after upgrading it to 2019
     
    Last edited: Aug 1, 2019
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,918
    Yes it is built into the editor in your version. The namespace is available with

    using UnityEngine.Analytics;
     
  5. undefined666

    undefined666

    Joined:
    Apr 3, 2018
    Posts:
    42
    Indeed Analytics.CustomEvent seems exactly what I need.Thanks!