AXitAnalytics is a customizable analytics framework designed to seamlessly integrate with Unity projects. Its goal is to provide developers with an extensible base to track user interactions and game performance across various platforms such as Firebase and ByteBrew. By abstracting the core logic, it allows developers to switch or add providers without modifying their game code extensively.
- Open Unity and go to Package Manager via Windows > Package Manager.
- Click on the Plus (+) icon > Add Package from git URL.
- Paste the following link in the URL field:
https://github.com/ngocphat03/AXitAnalytics.git - Click Add to install the package into your project.
FIREBASE_ANALYTICS- Add this symbol if you are integrating Firebase Analytics.
- Follow the Firebase Unity setup guide to install the Firebase SDK and configure it properly.
VCONTAINER- Use this symbol if you are utilizing the VContainer DI framework.
- For installation and setup, refer to the official VContainer documentation.
ZENJECT- Define this symbol if your project uses Zenject for dependency injection.
- You can find more details and setup instructions on the Zenject GitHub page.
NOTE:
For more details on adding scripting define symbols in Unity, check Unity's official
Custom Scripting Symbols documentation
The AnalyticServiceMonoInstaller can be configured to work standalone or with dependency injection (DI) frameworks like VContainer or Zenject. Follow the steps below for different setups.
- Create a GameObject:
- In the Unity Editor, go to the Hierarchy window.
- Right-click and select Create Empty to create a new GameObject.
- Attach the Script:
- Drag the
AnalyticServiceMonoInstaller.csscript from the Project window and drop it onto the GameObject.
- Drag the
- Configure Persistence (Optional):
- Select the GameObject in the Hierarchy.
- In the Inspector, find the
isPersistentAcrossScenesoption:- Enabled (default): The GameObject will persist across scene changes.
- Disabled: Uncheck the box if you don't need this behavior.
🚧 Feature is coming soon.
Support for VContainer is under development. Stay tuned for updates.
🚧Feature is coming soon.
Integration with Zenject will be available in an upcoming release.
- Standalone Mode: Use
AnalyticServiceMonoInstalleras a standard MonoBehaviour. - VContainer or Zenject: Replace with appropriate DI installers to enable dependency injection.
Follow these steps to create and track custom events using AXitAnalytics, whether you're using a standalone setup or integrating with a dependency injection (DI) framework.
1. Creating a Custom Event
Define a class that implements the IEvent interface to represent your event.
using System.Collections.Generic;
using AXitUnityTemplate.Analytics.Runtime.Interface;
public class StartGameEvent : IEvent
{
public string Name => "StartGame";
public Dictionary<string, object> Data { get; }
public StartGameEvent(int level)
{
this.Data = new Dictionary<string, object>
{
{ "level", level },
{ "scene", "1.MainScene" },
};
}
}- Tracking Events
Standalone (Without Dependency Injection)
If you are not using DI frameworks like Zenject or VContainer, use the Singleton pattern to access the AnalyticsService.
using AXitUnityTemplate.Analytics.Runtime;
public class LevelController : MonoBehaviour
{
private void Start()
{
AnalyticsService.Instance.TrackEvent(new StartGameEvent(1));
}
}With Dependency Injection
If your project uses DI frameworks, inject AnalyticsService into your classes.
using AXitUnityTemplate.Analytics.Runtime;
public class LevelController
{
private readonly AnalyticsService analyticsService;
public LevelController(AnalyticsService analyticsService)
{
this.analyticsService = analyticsService;
}
public void TrackStartGame()
{
this.analyticsService.TrackEvent(new StartGameEvent(1));
}
}AXitAnalytics supports multiple platforms, including Android, iOS, and WebGL. Below are the specific instructions for setting up analytics on each platform.
No special configuration is required for Android and iOS platforms. Simply follow the standard integration steps, and everything should work out of the box.
If you plan to use Firebase Analytics on WebGL, you need to manually configure Firebase in the index.html file generated by Unity.
-
Modify the
index.htmlFile:After building your project for WebGL, locate the
index.htmlfile in the build output folder. -
Add the Firebase Scripts:
Paste the following code inside the
<head>tag of theindex.htmlfile:<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script> <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-analytics.js"></script> <script> const firebaseConfig = { apiKey: "YOUR_API_KEY", authDomain: "YOUR_PROJECT_ID.firebaseapp.com", databaseURL: "https://YOUR_PROJECT_ID.firebaseio.com", projectId: "YOUR_PROJECT_ID", storageBucket: "YOUR_PROJECT_ID.appspot.com", messagingSenderId: "YOUR_SENDER_ID", appId: "YOUR_APP_ID", measurementId: "YOUR_MEASUREMENT_ID" }; firebase.initializeApp(firebaseConfig); firebase.analytics(); </script>
- Replace the
firebaseConfigobject with your project’s configuration details.- You can find these details in the Firebase Console:
- Go to Project Settings > General tab > Scroll to the Your apps section.
- Copy the configuration for your Web app.
- You can find these details in the Firebase Console:
- Make sure the Firebase SDK versions are compatible with your Unity WebGL build.
This project is licensed under the MIT License, allowing you to freely use, modify, and distribute it. See the LICENSE file in the repository for details.