Skip to Content
AI Powered Docs! 🤖 These docs are translated with AI, so keep an eye out for minor quirks. We're always improving!

Getting Started with Metrix SDK for Unity

This guide will walk you through the process of setting up and implementing the Metrix SDK in your Unity project. By integrating this SDK, you can easily collect user and behavioral data from your game or application and leverage Metrix’s powerful analytics and marketing capabilities.

Sample Project: For a complete and working example of Metrix SDK implementation in Unity, you can explore our sample project on GitHub.


1. Adding the Metrix Plugin to Your Unity Project

To begin, you need to import the Metrix SDK plugin into your Unity project:

  1. Download the Plugin: Get the latest version of the Metrix Unity plugin from this link.
  2. Import into Project: After downloading, either double-click the MetrixSDK_UnityPlugin_vX.X.X.unitypackage file or drag it into the Project window in Unity to import the plugin into your project.

2. Dependency Management

The Metrix plugin offers two main methods for managing its dependencies: using External Dependency Manager for Unity (EDM4U) (the automatic and recommended method) or manually adding dependencies to your project’s Gradle file (an alternative method).

This tool (formerly known as “Unity Jar Resolver”) automatically downloads and adds the necessary libraries to your project.

  • Install EDM4U: If you don’t have this tool in your project, download the latest version from this link and import it into your project as well.

2.2. Alternative Method: Manually Adding Dependencies to Gradle (Android Only)

If you prefer to manage dependencies manually or aren’t using EDM4U, you can directly add Metrix dependencies to your Android project’s build.gradle file. This method applies only to Android builds.

  1. Configure build.gradle: Ensure that the maven { url 'https://jitpack.io' } repository is added to your project-level build.gradle file within the allprojects { repositories { ... } } section.

    allprojects { repositories { google() mavenCentral() maven { url 'https://jitpack.io' } // Add this line } }
  2. Add Dependencies: Add the following dependencies to your module-level build.gradle file (typically app/build.gradle) within the dependencies { ... } section:

    dependencies { implementation 'ir.metrix.analytics:metrix-unity:2.6.7' implementation 'ir.metrix.attribution:metrix-unity:2.6.7' implementation 'ir.metrix.notification:metrix-unity:2.6.7' }

3. Initializing the Metrix Library in Your Application

The initial setup steps vary slightly depending on your application’s target platform.

3.1. Setup for Android Applications

  1. Resolve Dependencies:
  • If you’re using EDM4U:
    • In Unity, go to: Assets -> External Dependency Manager -> Android Resolver -> Resolve to resolve Android dependencies once.
  • If you’ve added dependencies manually:
    • You don’t need to run Android Resolver. Unity and Gradle will manage dependencies automatically during the project build.
  1. Configure AndroidManifest.xml: Place your Metrix APP_ID and API_KEY in your application’s AndroidManifest.xml file. These keys are essential for identifying your app within Metrix.
  • File Location: The AndroidManifest.xml file is typically located in Assets/Plugins/Android.

  • Enable Custom Manifest: If you don’t see this file, you might need to enable “Custom Main Manifest” in Unity’s Player settings: Go to Edit -> Project Settings... -> Player -> Android Setting (Tab) -> Publishing Settings -> Enable Custom Main Manifest.

  • Add Keys: Add the following lines within the <application> tag in your AndroidManifest.xml file, replacing YOUR_APP_ID and YOUR_API_KEY with your actual keys:

    <manifest> ... <application> ... <meta-data android:name="ir.metrix.APPLICATION_ID" android:value="YOUR_APP_ID" /> <meta-data android:name="ir.metrix.API_KEY" android:value="YOUR_API_KEY" /> </application> </manifest>
  • YOUR_APP_ID: Your Application ID, obtained from the Metrix dashboard.

  • YOUR_API_KEY: Your API Key, obtained from the Metrix dashboard.

  1. Verify Permission for Advertising ID: Ensure that the com.google.android.gms.permission.AD_ID permission is present in your project’s final (merged) manifest. This permission is crucial for collecting the device’s Advertising ID and for correct Attribution functionality:

    <manifest> <uses-permission android:name="com.google.android.gms.permission.AD_ID"/> ... </manifest>

4. Enhancing Library Security with SDK Signature (Android Only)

You can enhance communication and data transfer security and further ensure the integrity of your application’s statistics by enabling the SDK Signature feature in the Metrix dashboard. This feature allows Metrix to verify the authenticity of data sent from your application.

After enabling SDK Signature in your Metrix dashboard, retrieve the corresponding signature ID from the Encoded column. Then, place this signature in your C# Unity code as follows (either before or immediately after calling Metrix.Initialize):

Metrix.setSignature("YOUR_SIGNATURE_FROM_METRIX_DASHBOARD");

Note: This feature is currently available only for the Android platform.