Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

very beginner code for analytics

Discussion in 'Unity Analytics' started by dougbello, Oct 14, 2015.

  1. dougbello


    Apr 9, 2015
    Hello guys,

    I'm really new at unity and C# I'm finishing my game with playmaker but I would love to have some analytics feedback.

    I already implement unity analytics to my game and its working on its basic function. (using latest 5.2.1f1)

    But I need a custom event just to know when a player reaches the level and how many crystals he has at this moment.

    I'm thinking in a code like this:

    using UnityEngine;
    using System.Collections;
    using UnityEngine.Analytics;
    using System.Collections.Generic;

    public class analytics_try : MonoBehaviour {

    public int levelReach;
    private int totalCrystals;

    void OnTriggerEnter(Collider other) {

    Analytics.CustomEvent("level", new Dictionary<string, object> {

    { "level", levelReach },
    { "crystals", totalCrystals },




    I know its a sh*** wrong code, but I'm hoping someone can help me here.

    Thanks a lot.
  2. mpinol


    Unity Technologies

    Jul 29, 2015
    Hi @dougbello,

    I would remove the comma after 'totalCystals },' and make sure that you assign values to levelReach and totalCrystals before sending the event and you are all set!

    For a good way to view this data I would suggest using a Funnel. You can create each step of the Funnel where the parameter 'levelReach' corresponds to the level value and then in the Funnel Analyzer page you can select 'Parameters Overview' from the Drilldown Type menu to see the average number of totalCrystals each user collected on a particular level. You can read more about funnels here,
  3. dougbello


    Apr 9, 2015
    Thank you @mpinol !

    Even with my ZERO C# knowledge it is working!!!!

    Thanks again.
    mpinol likes this.