Skip to content

uerceg/play-install-referrer-unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Play Install Referrer Library wrapper for Unity

Supported platforms:
Current version: 3.0.0
Unity IDE support: 2017.4.39f1 and later
Latest release: Download
Troubles? Report an issue

play-install-referrer is a simple wrapper around Google's Play Install Referrer Library which offers basic functionality of obtaining Android referrer information from Unity app.

More information about Play Install Referrer API can be found in official Google documentation.

Version of native Play Install Referrer Library which is being used inside of latest play-install-referrer plugin version is 2.1.

Usage

In order to obtain install referrer details, call GetInstallReferrerInfo static method of PlayInstallReferrer class:

using Ugi.PlayInstallReferrerPlugin;

PlayInstallReferrer.GetInstallReferrerInfo((installReferrerDetails) =>
    {
        Debug.Log("Install referrer details received!");

        // check for error
        if (installReferrerDetails.Error != null)
        {
            Debug.LogError("Error occurred!");
            if (installReferrerDetails.Error.Exception != null)
            {
                Debug.LogError("Exception message: " + installReferrerDetails.Error.Exception.Message);
            }
            Debug.LogError("Response code: " + installReferrerDetails.Error.ResponseCode.ToString());
            return;
        }

        // print install referrer details
        if (installReferrerDetails.InstallReferrer != null)
        {
            Debug.Log("Install referrer: " + installReferrerDetails.InstallReferrer);
        }
        if (installReferrerDetails.ReferrerClickTimestampSeconds != null)
        {
            Debug.Log("Referrer click timestamp: " + installReferrerDetails.ReferrerClickTimestampSeconds);
        }
        if (installReferrerDetails.InstallBeginTimestampSeconds != null)
        {
            Debug.Log("Install begin timestamp: " + installReferrerDetails.InstallBeginTimestampSeconds);
        }
        if (installReferrerDetails.ReferrerClickTimestampServerSeconds != null)
        {
            Debug.Log("Referrer click timestamp server: " + installReferrerDetails.ReferrerClickTimestampServerSeconds);
        }
        if (installReferrerDetails.InstallBeginTimestampServerSeconds != null)
        {
            Debug.Log("Install begin timestamp server: " + installReferrerDetails.InstallBeginTimestampServerSeconds);
        }
        if (installReferrerDetails.InstallVersion != null)
        {
            Debug.Log("Install version: " + installReferrerDetails.InstallVersion);
        }
        if (installReferrerDetails.GooglePlayInstant != null)
        {
            Debug.Log("Google Play instant: " + installReferrerDetails.GooglePlayInstant);
        }
    });

Instance of PlayInstallReferrerDetails object will be delivered into callback method. From that instance, you can get following install referrer details:

You should first check if Error property is null or not. If not, for some reason reading of install referrer details failed and those properties will be null. In case no error is reported, install referrer detail properties should reflect the values obtained from native Install Referrer Library response.

Under the hood

Important thing to notice is that in order to work properly, Play Install Referrer Library requires following permission to be added to your app's AndroidManifest.xml:

<uses-permission android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE"/>

Play Install Referrer Library is added to play-install-referrer plugin as an AAR library and it will automatically make sure that manifest file ends up with above mentioned permission added to it upon building your app.

Todos

List of tasks to be done in this repository can be found in here.

API reference

PlayInstallReferrer class

GetInstallReferrerInfo

public static void GetInstallReferrerInfo(Action<PlayInstallReferrerDetails> callback)

Static method for getting install referrer details.

Parameters Description
callback Action<PlayInstallReferrerDetails>: Callback to which install referrer information will be delivered.

PlayInstallReferrerDetails class

InstallReferrer

public string InstallReferrer { get; }

Public property containing information about install referrer string value.

ReferrerClickTimestampSeconds

public long? ReferrerClickTimestampSeconds { get; }

Public property containing information about timestamp of when user clicked on URL which redirected him/her to Play Store.

InstallBeginTimestampSeconds

public long? InstallBeginTimestampSeconds { get; }

Public property containing information about timestamp of when app installation on device begun.

ReferrerClickTimestampServerSeconds

public long? ReferrerClickTimestampServerSeconds { get; }

Public property containing information about server timestamp of when user clicked on URL which redirected him/her to Play Store.

InstallBeginTimestampServerSeconds

public long? InstallBeginTimestampServerSeconds { get; }

Public property containing information about server timestamp of when app installation on device begun.

InstallVersion

public string InstallVersion { get; }

Public property containing information about original app version which was installed.

GooglePlayInstant

public bool? GooglePlayInstant { get; }

Public property containing information if app's instant version was launched in past 7 days.

Error

public PlayInstallReferrerError Error { get; }

Public property containing information about error which might have occured during attempt to read install referrer details.

PlayInstallReferrerError class

ResponseCode

public int ResponseCode { get; }

Public property containing information about one of the error response codes which native Install Referrer Library might return. Full list of potential response codes can be found in here (OK will never be reported in this property, since it's a success status code).

Exception

public Exception Exception { get; }

Public property containing information about potential exception which might have occurred during attempt to read install referrer details.

About

Play Install Referrer Library ported to Unity

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages