Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question When Flushing events?

Discussion in 'Unity Analytics' started by Max_power1965, Sep 2, 2022.

  1. Max_power1965

    Max_power1965

    Joined:
    Oct 31, 2013
    Posts:
    129
    Hello I have a 2 questions:
    1. Does Unity automatically flush the events if the user closes the app with some events in the queue?
    2. Actually, I call AnalyticsService.Instance.Flush(); every time I fire an event? Is there something wrong with this approach?
     
  2. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    Yes events are flushed automatically upon exit.

    You can see more information in the documentation about sending events here: Track Events

    Calling AnalyticsService.Instance.Flush(); every time you fire an event will result in the event being sent immediately.
     
  3. Max_power1965

    Max_power1965

    Joined:
    Oct 31, 2013
    Posts:
    129
    Thanks since I'm here a couple of things:
    1. The first link in the documentation link that you sent me, it's broken ( https://resources.unity.com/player-engagement-center/intro-to-analytics-for-games)
    2. I wasn't able to find anything in the documentation about how the events are manages in the SDK, but as far as I understood, the events are automatically cached and when the app gets closed, they will be automatically flushed. if this is the case, then why would I need to use "AnalyticsService.Instance.Flush()" in the first place?
    2a. Does this works also in the Unity Editor, I mean, every time I hit the "stop" button the events will be automatically send to the server?
    3. in case I want to send an event with zero parameters, should I pass an empty dictionary to the
    AnalyticsService.Instance.CustomData(eventName, param) method

    Thanks
     
  4. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    I'm not entirely sure how you got to that link? That's not what I linked, please try again here: Track Events

    The documentation which I linked explains in more detail, but yes, standard events get sent when the app is quit.

    Yes

    I'm not entirely sure what you mean? Why would you want to send a custom event with 0 parameters?
    Take a look at best practices on the same link, I originally linked: Track Events
     
    Last edited: Sep 5, 2022
  5. Max_power1965

    Max_power1965

    Joined:
    Oct 31, 2013
    Posts:
    129
    1. I've attached the image that contains the broken link in the documentation in case you might want to fix it.
    3. Assuming I've create en event called "player_did_click_double_coin_btn" to register when the user did click the button to double the coins, now this event has no custom parameter like level number, number or coins etc.

    So to launch the event I do this:
    Code (CSharp):
    1.                 string eventName = "player_did_click_double_coin_btn";
    2.  
    3.                 Dictionary<string, object> body = new Dictionary<string, object>()
    4.                 {
    5.                 };
    6.                   AnalyticsService.Instance.CustomData(eventName, body);
    Where the body of the custom data is an empty dictionary. Looking at the documentation, I've only found examples where events have custom parameters associated. So, is it correct what I'm doing?
    Thanks
     

    Attached Files:

  6. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    Oh okay, thank you, that has now been noted and reported as a bug. thank you for raising this.


    Yes that is correct.