Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Facebook analytics integration for Unity game project

Discussion in 'Unity Analytics' started by simpleonegame, Oct 21, 2020.

Thread Status:
Not open for further replies.
  1. simpleonegame

    simpleonegame

    Joined:
    Dec 17, 2019
    Posts:
    13
    I'm not an experienced programmer, just an artist trying to make my second game bit more professionally, I was using Unity analytics but my publisher wants me to use Facebook analytics and I couldn't figure this one thing for last 2 good weeks.. some one help me please

    My Objective: Make a "Breakdown" in Facebook analytics with level numbers, i.e. I want to know how many people played a specific level. I found out how to display the "Count", "Count percent" etc. But what I did not find is, how to display the "LevelNumber"/"LevelName" like the image(Unity.png) attached. In the image we can see there are level numbers(marked in red) listed vertically.
    Unity.png

    I tried writing this code to do so:

    My Code 1:
    public void LogCompletedEvent(string levelName, double levelNumber)
    {
    var parameters = new Dictionary<string, object>();
    parameters["LevelName"] = levelName;
    FB.LogAppEvent("LevelCompleted", (float)levelNumber, parameters);
    }


    Result: I don't see level numbers in the "Breakdowns" dashboard (Activity>Breakdowns), instead I see one word which is "All Others". I'm passing a string for "Level numbers" as levelName.
    Facebook_Analytics_Error_AllOthers.JPG

    second thing I tried was to use a standard Event for Casual games, it can be found here on this page and it's called "AchievedLevel": https://developers.facebook.com/docs/app-events/best-practices/gaming-casual/#achievedlevel-event

    My Code 2:
    public void LogAchievedLevelEvent(string level)
    {
    var parameters = new Dictionary<string, object>();
    parameters[AppEventParameterName.Level] = level;
    FB.LogAppEvent(AppEventName.AchievedLevel, parameters);
    }


    As I said earlier, above code is a standard event provided by Facebook, but whenever I directly copy and paste it, it throws an error (cannot convert from 'System.Collections.Generic.Dictionary<string, object>' to 'float?'), no idea why Facebook is giving me a code that throws error like this.

    Any help will be greatly appreciated and thank you very much in advance :)
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We would not be able to support FB Analytics, you would need to contact them.
     
  3. ilyaskos3

    ilyaskos3

    Joined:
    Apr 25, 2019
    Posts:
    3
    Try this
    Code (CSharp):
    1. public void LogAchievedLevelEvent(string level)
    2. {
    3. var parameters = new Dictionary<string, object>();
    4. parameters[AppEventParameterName.Level] = level;
    5. FB.LogAppEvent(AppEventName.AchievedLevel, parameters : parameters);
    6. }
     
Thread Status:
Not open for further replies.