Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-native-play-install-referrer

uerceg28.7kMIT1.1.9TypeScript support: included

Play Install Referrer Library wrapper for React Native

react-native, mobile, android, google, install-referrer, play-install-referrer

readme

Play Install Referrer Library wrapper for React Native

Supported platforms:
Current version: 1.1.9
Troubles? Report an issue

react-native-play-install-referrer is a simple wrapper around Google's Play Install Referrer Library which offers basic functionality of obtaining Android referrer information from React Native 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 react-native-play-install-referrer plugin version is 2.2.

Add plugin to your app

react-native-play-install-referrer plugin is hosted on npm repo and can be added from there.

Yarn:

yarn add react-native-play-install-referrer

npm:

npm install --save react-native-play-install-referrer

Usage

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

import { PlayInstallReferrer } from 'react-native-play-install-referrer';

PlayInstallReferrer.getInstallReferrerInfo((installReferrerInfo, error) => {
  if (!error) {
    console.log("Install referrer = " + installReferrerInfo.installReferrer);
    console.log("Referrer click timestamp seconds = " + installReferrerInfo.referrerClickTimestampSeconds);
    console.log("Install begin timestamp seconds = " + installReferrerInfo.installBeginTimestampSeconds);
    console.log("Referrer click timestamp server seconds = " + installReferrerInfo.referrerClickTimestampServerSeconds);
    console.log("Install begin timestamp server seconds = " + installReferrerInfo.installBeginTimestampServerSeconds);
    console.log("Install version = " + installReferrerInfo.installVersion);
    console.log("Google Play instant = " + installReferrerInfo.googlePlayInstant);
  } else {
    console.log("Failed to get install referrer info!");
    console.log("Response code: " + error.responseCode);
    console.log("Message: " + error.message);
  }
});

If successfully obtained, map with content of install referrer information will be delivered into callback method as first parameter. From that map, you can get following install referrer details:

  • Install referrer string value (installReferrer key).
  • Timestamp of when user clicked on URL which redirected him/her to Play Store to download your app (referrerClickTimestampSeconds key).
  • Timestamp of when app installation on device begun (installBeginTimestampSeconds key).
  • Server timestamp of when user clicked on URL which redirected him/her to Play Store to download your app (referrerClickTimestampServerSeconds key).
  • Server timestamp of when app installation on device begun (installBeginTimestampServerSeconds key).
  • Original app version which was installed (installVersion key).
  • Information if your app's instant version (if you have one) was launched in past 7 days (googlePlayInstant key).

You should first check if second parameter in the callback - error is null or not. If not, for some reason reading of install referrer details failed. In case no error is reported, install referrer information should be delivered into the first map parameter of the callback method.

In case error is reported, you can get following information about the error:

  • Response code: Error response code 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). Note: Error code field is not always present in error map - only if error created when one of the error codes from native Install Referrer Library is received; otherwise this field will be undefined.
  • Message: Additional string message which describes error more in detail. Note: Message field should always be present in error map.

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 react-native-play-install-referrer plugin as an Gradle dependency and it will automatically make sure that manifest file ends up with above mentioned permission added to it upon building your app.

Example app

You can find example app using react-native-play-install-referrer plugin inside example folder of this repository. In case you want to run the app (with re-adding plugin), you can run this command inside app folder:

yarn remove react-native-play-install-referrer && yarn add ../ && npx react-native run-android

Todos

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

changelog

Version 1.1.9 [14th May 2025]

Fixed

Changed

  • Updated compile and target SDK API to 35.
  • Made dependabot happy (hopefully).

Version 1.1.8 [19th January 2022]

Added

  • Added example app in TypeScript.

Changed

  • Updated TypeScript definition for callback. (thanks to @apfritts)
  • Ignored this module on non-Android platforms. (thanks to @apfritts)

Version 1.1.7 [20th October 2021]

Changed

  • Updated native Play Install Referrer library to v2.2.

Fixed

  • Fixed addListener and removeListeners warnings (same issue with suggested fix which got copy pasted in this plugin as well). (thanks to @mikehardy)

Version 1.1.6 [29th December 2020]

Added

  • Added Example app chapter to README.

Changed

  • Unified plugin and example app package names (under the hood changes, no affect on plugin functionality).

Version 1.1.5 [15th September 2020]

Fixed

Changed


Version 1.1.4 [7th September 2020]

Changed


Version 1.1.3 [7th September 2020]

Changed


Version 1.1.2 [7th September 2020]

Changed


Version 1.1.1 [12th July 2020]

Changed


Version 1.1.0 [12th July 2020]

Added

  • Added reading of 3 new fields introduced in Play Install Referrer library v2.0 - referrerClickTimestampServerSeconds, installBeginTimestampServerSeconds and installVersion.

Changed

  • Changed my GitHub username from @uerceg to @ugi.
  • Updated Play Install Referrer library to v2.1.
  • Updated example app to show newly read fields as well.

Note: Project is moved from https://github.com/uerceg/play-install-referrer-react-native.


Version 1.0.0 [25th May 2020]

Added

  • Initial release of react-native-play-install-referrer plugin.