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.
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:
- Install referrer string value (InstallReferrer property).
- Timestamp of when user clicked on URL which redirected him/her to Play Store to download your app (ReferrerClickTimestampSeconds property).
- Timestamp of when app installation on device begun (InstallBeginTimestampSeconds property).
- Server timestamp of when user clicked on URL which redirected him/her to Play Store to download your app (ReferrerClickTimestampServerSeconds property).
- Server timestamp of when app installation on device begun (InstallBeginTimestampServerSeconds property).
- Original app version which was installed (InstallVersion property).
- Information if your app's instant version (if you have one) was launched in past 7 days (GooglePlayInstant property).
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.
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.
List of tasks to be done in this repository can be found in here.
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. |
public string InstallReferrer { get; }
Public property containing information about install referrer string value.
public long? ReferrerClickTimestampSeconds { get; }
Public property containing information about timestamp of when user clicked on URL which redirected him/her to Play Store.
public long? InstallBeginTimestampSeconds { get; }
Public property containing information about timestamp of when app installation on device begun.
public long? ReferrerClickTimestampServerSeconds { get; }
Public property containing information about server timestamp of when user clicked on URL which redirected him/her to Play Store.
public long? InstallBeginTimestampServerSeconds { get; }
Public property containing information about server timestamp of when app installation on device begun.
public string InstallVersion { get; }
Public property containing information about original app version which was installed.
public bool? GooglePlayInstant { get; }
Public property containing information if app's instant version was launched in past 7 days.
public PlayInstallReferrerError Error { get; }
Public property containing information about error which might have occured during attempt to read install referrer details.
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).
public Exception Exception { get; }
Public property containing information about potential exception which might have occurred during attempt to read install referrer details.