Skip to main content

Analytics and Attribution

Introduction


When we talk about analytics we mean a unified and comprehensive solution for collecting, processing, and analyzing data related to user interactions within a game. The attribution feature in our SDK allows you to accurately track the source of user acquisitions and attribute them to specific marketing campaigns, channels, or ad networks. This feature allows developers to gain valuable insights into user behavior, engagement, and the overall performance of their games.

Plankton's analytics and attribution feature supports providers such as Firebase, AppMetrica, AppsFlyer, and Tenjin

Before you begin


Prerequisites

  • Complete the Plankton setup
  • For Android
    • Set Target API Level to 33 or higher
    • Set Minimum Api Level to 19 or higher
  • For iOS
    • Set Target Minimum iOS Version to 15.0 or higher
note

You can change Minimum and Target versions in Unity from Edit > Project Settings > Player > Other Settings

Set up your accounts

Create and set up an account for each provider you want to use.

Firebase(Google Analytics)

  1. Sign into Firebase using your Google account.
  2. Create a Firebase Project and make sure that Google Analytics is enabled in it.
  3. Register your game with Firebase separately for Android and for iOS. Don't create app for Unity.
  4. Download the Firebase Android configuration file (google-services.json). This file is needed later in this guide.

Yandex AppMetrica

  1. Follow the steps in AppMetrica getting started guide and finish setting up your game in AppMetrica
  2. Retrieve the unique API key of your game from the AppMetrica's Settings page. This key is needed later in this guide.

AppsFlyer

  1. Visit AppsFlyer marketers guide to setup your AppsFlyer account and add your game.
  2. Retrieve the unique Dev Key of your game from its settings page in AppsFlyer dashboard.

Tenjin

  1. Follow the Tenjin getting started guide for marketers and finish setting up your game in Tenjin.
  2. Get the unique SDK Key from your app's page in Tenjin dashboard. This key is needed later in this guide.

Confiure Plankton settings


  1. Open plankton settings by going to Edit > Project Settings > Plankton.
  2. Select the checkbox of the features that you want to use.
  3. Fill the required field
    • It is API Key for AppMetrica, Dev Key for AppsFlyer and SDK Key for Tenjin.
    • For Firebase (Analytics and Remote Config) you should click "Open firebase json" and open your Firebase configuration file.(It is google-services.json in Android and GoogleService-Info.plist in iOS.)
    • For Firebase, you can also enable Push Notification just by selecting its checkbox.
    • For GameAnalytics you just select the checkbox. The configuration should be provided through code.

note

If you are using AppsFlyer on iOS, there are two extra fields that need to be filled.

  • Apple App ID: Find it in your app's page in AppStore Connect, in App Information > General Information> Apple ID
  • Advertising attribution report endpoint URL: The URL which SKAN postback copies are sent to. According to AppsFlyer's official docs, set it to https://appsflyer-skadnetwork.com/.

Implementation


Let's dive into codes. Always import the Plankton package in your scripts.

using Plankton;

Initialize

At first initialize the GeneralAnalytics class like below:

GeneralAnalytics.Initialize();
info

After calling initialize, AppsFlyer and Tenjin will start their attribution process and gather user's install data.

Set user property

User properties (also known as profile attributes) are attributes you define to describe segments of your user base, such as gender, age, type of subscription, number of levels completed, and so on.

This is how you can set a user property:

var providers = Provider.Firebase | Provider.Yandex;
GeneralAnalytics.SetUserProperty(providers, "property_key", "property_value");

If you want to set a user property in multiple providers at the same time, you can add other providers with the binary literal |.

Notice

SetUserProperty is not available for AppsFlyer and Tenjin.

Send event

Events provide insight on what is happening in your app, such as user actions, system events, or errors. They allow you to measure a specific interaction or occurrence in your game. For example, you can use an event to measure when someone opens a page, clicks a link, or completes a purchase, or to measure system behavior, such as when an app crashes or an impression is served.

Here's a sample of sending an event with three parameters:

var eventProviders = Provider.Firebase | Provider.Appsflyer | Provider.Yandex;
var parameters = new Dictionary<string, string>() {
{ "param_1", "value_1"},
{ "param_2", "value_2"},
{ "param_3", "value_3"},
};
GeneralAnalytics.LogEvent(eventProviders, "event_name", parameters);

If you want to send an event to multiple providers at the same time, you can add other providers with the binary literal |.

If you simply want to send an event without any parameters, pass an empty Dictionary as parameters argument.

tip

Analytics providers like Firebase usually log some events automatically. You can get more information about each provider's default events in their websites.

Notice

LogEvent is not available for Tenjin.

Track revenue

You can log every revenue you make from showing ads or selling in-app products with Plankton's TrackRevenue method. It is actually a kind of event that is dedicated to logging revenue.

var providers = Provider.Firebase | Provider.Appsflyer | Provider.Yandex;
GeneralAnalytics.TrackRevenue(providers, "test_revenue", 2.99, "USD");

If you want to log revenue event in multiple providers at the same time, you can add other providers with the binary literal |.

info

If you use Plankton for displaying ads in your game, it will automatically log ad's revenue with an event called "plankton_revenue"

Firebase Remote Configs

Firebase Remote Config is a cloud service that lets you change the behavior and appearance of your app without requiring users to update the app. When using Remote Config, you create in-app default values that control the behavior and appearance of your app. Then, you can later use the Firebase console or the Remote Config backend APIs to override in-app default values for all app users or for segments of your user base.

You can set key-value parameters in the Remote Configs section of your Firebase Analytics dashboard. For getting the values in your game, first you need to fetch the values from remote config backend. This is how you should fetch the remote config:

GeneralAnalytics.RemoteConfig.Fetch(json => Debug.Log($"Fetch Successfull! configs:{json}"), () => Debug.Log("Fetch Failed!"));

Now that you have successfully fetched the remote config, you can get parameter values by calling RemoteConfig.Get method:

var configValue = GeneralAnalytics.RemoteConfig.Get("config_key", "default_value");

The second argument of this method is the default value in case the key which you are looking for does not exist in the configs.

Notice

Remote Config feature is only supported by Firebase.

API Refrences


Defined Types

In this section, we will discuss the enumerated types, variables, and classes associated with this feature:

Enums

GeneralAnalytics.Provider
ValuesDescriptionUsage
Firebase You can use Firebase Analytics as an analytics SDK in your game. You have to set up an account to be able to provide the needed credentials to use it.GeneralAnalytics.Provider.Firebase
Yandex You can use AppMetrica as an analytics SDK in your game. You have to set up an account to be able to provide the needed credentials to use it.GeneralAnalytics.Provider.Yandex
AppsflyerYou can use AppsFlyer as a marketing attribution and an analytics SDK in your game. You have to set up an account to be able to provide the needed credentials to use it.GeneralAnalytics.Provider.Appsflyer
TenjinYou can use Tenjin as a marketing attribution tool. Tenjin's attribution technology enables marketers to gain insight and context into why users engage with their apps.GeneralAnalytics.Provider.Tenjin

Method Summaries

MethodArgumentsReturn TypeDescription
Initialize(no arguments)voidYou need to initialize GeneralAnalytics before using its features.
SetUserPropertyProvider providers, string key, string valuevoidSets a user property to a given value. Up to 25 user property names are supported. Once set, user property values persist throughout the app lifecycle and across sessions. This method is supported by Firebase and Yandex.
TrackRevenueProvider providers, string eventName, double amount, string currencyvoidYou can use this method to track your revenue.
LogEventProvider providers,string eventName, params object[] argsvoidYou can use this method to send events in your game.
LogEventProvider providers, string eventName, Dictionary<string, string> argsvoidYou can use this method to send events in your game.
RemoteConfig.FetchSystem.Action<string> onSucceed, System.Action onFailedvoidAsynchronously fetches and then activates the fetched configs from Firebase.
RemoteConfig.Getstring key, string defaultValuestringGets remote config string value for the given key.
RemoteConfig.Getstring key, int defaultValueintGets remote config int value for the given key.
RemoteConfig.Getstring key, float defaultValuefloatGets remote config float value for the given key.