docs.unity3d.com
    Show / Hide Table of Contents

    Interface IAnalyticsService

    Namespace: Unity.Services.Analytics
    Syntax
    public interface IAnalyticsService

    Properties

    PrivacyUrl

    This is the URL for the Unity Analytics privacy policy. This policy page should be presented to the user in a platform-appropriate way along with the ability to opt out of data collection.

    Declaration
    string PrivacyUrl { get; }
    Property Value
    Type Description
    String

    Methods

    AcquisitionSource(AcquisitionSourceParameters)

    Record an acquisitionSource event.

    Declaration
    void AcquisitionSource(AcquisitionSourceParameters acquisitionSourceParameters)
    Parameters
    Type Name Description
    AcquisitionSourceParameters acquisitionSourceParameters

    (Required) Helper object to handle parameters.

    AdImpression(AdImpressionParameters)

    Declaration
    void AdImpression(AdImpressionParameters parameters)
    Parameters
    Type Name Description
    AdImpressionParameters parameters

    CheckForRequiredConsents()

    Returns identifiers of required consents we need to gather from the user in order to be allowed to sent analytics events. This method must be called every time the game starts - without checking the geolocation, no event will be sent (even if the consent was already given). If the required consent was already given, an empty list is returned. If the user already opted out from the current legislation, an empty list is returned. It involves the GeoIP call. ConsentCheckException is thrown if the GeoIP call was unsuccessful.

    Declaration
    Task<List<string>> CheckForRequiredConsents()
    Returns
    Type Description
    Task<List<String>>

    A list of consent identifiers that are required for sending analytics events.

    Exceptions
    Type Condition
    ConsentCheckException

    Thrown if the GeoIP call was unsuccessful.

    ConvertCurrencyToMinorUnits(String, Double)

    Converts an amount of currency to the minor units required for the objects passed to the Transaction method. This method uses data from ISO 4217. Note that this method expects you to pass in currency in the major units for conversion - if you already have data in the minor units you don't need to call this method. For example - 1.99 USD would be converted to 199, 123 JPY would be returned unchanged.

    Declaration
    long ConvertCurrencyToMinorUnits(string currencyCode, double value)
    Parameters
    Type Name Description
    String currencyCode

    The ISO4217 currency code for the input currency. For example, USD for dollars, or JPY for Japanese Yen

    Double value

    The major unit value of currency, for example 1.99 for 1 dollar 99 cents.

    Returns
    Type Description
    Int64

    The minor unit value of the input currency, for example for an input of 1.99 USD 199 would be returned.

    CustomData(String, IDictionary<String, Object>)

    Record a custom event. A schema for this event must exist on the dashboard or it will be ignored.

    Declaration
    void CustomData(string eventName, IDictionary<string, object> eventParams)
    Parameters
    Type Name Description
    String eventName
    IDictionary<String, Object> eventParams

    Flush()

    Forces an immediately upload of all recorded events to the server, if there is an internet connection.

    Declaration
    void Flush()
    Exceptions
    Type Condition
    ConsentCheckException

    Thrown if the required consent flow cannot be determined..

    OptOut()

    Opts the user out of sending analytics from all legislations. To deny consent for a specific opt-in legislation, like PIPL, use ProvideConsent(string key, bool consent) method) All existing cached events and any subsequent events will be discarded immediately. A final 'forget me' signal will be uploaded which will trigger purge of analytics data for this user from the back-end. If this 'forget me' event cannot be uploaded immediately (e.g. due to network outage), it will be reattempted regularly until successful upload is confirmed. Consent status is stored in PlayerPrefs so that the opted-out status is maintained over app restart. This action cannot be undone.

    Declaration
    void OptOut()
    Exceptions
    Type Condition
    ConsentCheckException

    Thrown if the required consent flow cannot be determined..

    ProvideOptInConsent(String, Boolean)

    Sets the consent status for the specified opt-in-based legislation (PIPL etc). The required legislation identifier can be found by calling CheckForRequiredConsents method. If this method is tried to be used for the incorrect legislation (PIPL outside China etc), the ConsentCheckException is thrown.

    Declaration
    void ProvideOptInConsent(string identifier, bool consent)
    Parameters
    Type Name Description
    String identifier

    The legislation identifier for which the consent status should be changed.

    Boolean consent

    The consent status which should be set for the specified legislation.

    Exceptions
    Type Condition
    ConsentCheckException

    Thrown if the incorrect legislation was being provided or the required consent flow cannot be determined.

    RecordInternalEvent(Event)

    Allows other sources to write events with common analytics parameters to the Analytics service. This is primarily for use by other packages - as this method adds common parameters that may not be expected in the general case, for custom events you should use the CustomData method instead.

    Declaration
    void RecordInternalEvent(Event eventToRecord)
    Parameters
    Type Name Description
    Event eventToRecord

    Internal event to record

    SetAnalyticsEnabled(Boolean)

    Allows you to disable the Analytics service. When the service gets disabled all currently cached data both in RAM and on disk will be deleted and any new events will be voided. By default the service is enabled so you do not need to call this method on start. Will return instantly when disabling, must be awaited when re-enabling. To disable the Analytics Service before the game starts

    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    static void DisableAnalytics()
    {
        AnalyticsService.Instance.SetAnalyticsEnabled(false);
    }

    Declaration
    Task SetAnalyticsEnabled(bool enabled)
    Parameters
    Type Name Description
    Boolean enabled
    Returns
    Type Description
    Task

    Transaction(TransactionParameters)

    Record a Transaction event.

    Declaration
    void Transaction(TransactionParameters transactionParameters)
    Parameters
    Type Name Description
    TransactionParameters transactionParameters

    (Required) Helper object to handle parameters.

    TransactionFailed(TransactionFailedParameters)

    Record a TransactionFailed event.

    Declaration
    void TransactionFailed(TransactionFailedParameters parameters)
    Parameters
    Type Name Description
    TransactionFailedParameters parameters

    (Required) Helper object to handle parameters.

    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023